Stock Control System
Loading...
Searching...
No Matches
Pool Struct Reference

An ordered expandable collection of dynamically allocated Product records. More...

#include <Pool.h>

Collaboration diagram for Pool:

Public Member Functions

struct Poolpool_create (const unsigned int initial_capacity, const float growth_factor)
 Create a new empty Pool with the given initial capacity and growth factor.
 
void pool_delete (struct Pool **this)
 Destroy the Pool and all held Product objects.
 
bool pool_insert_element (struct Pool *this, struct Product *product)
 Insert the given Product into the Pool, expanding the Pool by its growth factor if necessary.
 
int pool_serialise_report (const struct Pool *this, FILE *buffer)
 Serialise the contents of the Pool, with an additional header, to the given stream, in the report format.
 
int pool_serialise_stock_file (const struct Pool *this, FILE *buffer)
 Serialise the contents of the Pool, with an additional header, to the given stream, in the stock file format.
 
struct Productpool_get_product_by_index (const struct Pool *this, unsigned int index)
 Retrieve the Product at the stated index in the pool.
 

Data Fields

unsigned int capacity
 Maximum capacity of the Pool.
 
unsigned int index
 Index of next available item in the Pool for products.
 
float growth_factor
 Factor by which the Pool capacity should be expanded.
 
struct Product ** products
 Pool elements.
 

Static Private Member Functions

static void print_dashed_header (FILE *const buffer)
 Print the common header separator consisting of repeated hyphens.
 

Detailed Description

An ordered expandable collection of dynamically allocated Product records.

Definition at line 24 of file Pool.c.

Member Function Documentation

◆ pool_create()

struct Pool * pool_create ( const unsigned int  initial_capacity,
const float  growth_factor 
)

Create a new empty Pool with the given initial capacity and growth factor.

Parameters
initial_capacityThe initial number of Product instances that the Pool may accommodate.
growth_factorThe multiplicative factor by which the Pool capacity should grow when expanded.
Returns
The dynamically allocated Pool.

Definition at line 46 of file Pool.c.

◆ pool_delete()

void pool_delete ( struct Pool **  this)

Destroy the Pool and all held Product objects.

Parameters
thisThe Pool to delete.
See also
product_delete for Product destructor.

Definition at line 67 of file Pool.c.

◆ pool_get_product_by_index()

struct Product * pool_get_product_by_index ( const struct Pool this,
unsigned int  index 
)

Retrieve the Product at the stated index in the pool.

Parameters
thisThe Pool containing the Product at the given index.
indexThe index of the Product within the Pool.
Returns
The Product at the requested index, or NULL if there was no suitable Product.

Definition at line 140 of file Pool.c.

◆ pool_insert_element()

bool pool_insert_element ( struct Pool this,
struct Product product 
)

Insert the given Product into the Pool, expanding the Pool by its growth factor if necessary.

Parameters
thisThe Pool into which the Product should be inserted.
productThe Product to insert.
Returns
Was the Product successfully inserted into the Pool?

Definition at line 78 of file Pool.c.

◆ pool_serialise_report()

int pool_serialise_report ( const struct Pool this,
FILE *  buffer 
)

Serialise the contents of the Pool, with an additional header, to the given stream, in the report format.

Parameters
thisThe Pool to serialise.
bufferThe destination buffer to which the serialised Pool data should be written.
Returns
The number of bytes written, negative if and only if an error occurred. In the latter case, errno is set.

Definition at line 102 of file Pool.c.

◆ pool_serialise_stock_file()

int pool_serialise_stock_file ( const struct Pool this,
FILE *  buffer 
)

Serialise the contents of the Pool, with an additional header, to the given stream, in the stock file format.

Parameters
thisThe Pool to serialise.
bufferThe destination buffer to which the serialised Pool data should be written.
Returns
The number of bytes written, negative if and only if an error occurred. In the latter case, errno is set.

Definition at line 128 of file Pool.c.

◆ print_dashed_header()

static void print_dashed_header ( FILE *const  buffer)
staticprivate

Print the common header separator consisting of repeated hyphens.

Parameters
bufferThe buffer to which the separator bytes should be written.

Definition at line 37 of file Pool.c.

Field Documentation

◆ capacity

unsigned int Pool::capacity

Maximum capacity of the Pool.

Definition at line 26 of file Pool.c.

◆ growth_factor

float Pool::growth_factor

Factor by which the Pool capacity should be expanded.

Definition at line 28 of file Pool.c.

◆ index

unsigned int Pool::index

Index of next available item in the Pool for products.

Definition at line 27 of file Pool.c.

◆ products

struct Product** Pool::products

Pool elements.

Definition at line 29 of file Pool.c.


The documentation for this struct was generated from the following files: