39 static const unsigned int line_length = 4 + 3 +
MAX_NAME_LENGTH + 3 + 11;
40 for (
unsigned int counter = 0; counter < line_length; ++counter)
50 struct Pool *pool = malloc(
sizeof(
struct Pool));
69 const unsigned int product_count = (*this)->
index;
70 for (
unsigned int product_idx = 0; product_idx < product_count; ++product_idx)
73 free((*this)->products);
90 struct Product **new_products = realloc(this->products,
sizeof(
struct Product *) * new_capacity);
91 if (new_products == NULL)
94 this->products = new_products;
95 this->capacity = new_capacity;
98 this->products[this->index++] = product;
104 const unsigned int count = this->index;
109 memcpy(sorted, this->products,
sizeof(
struct Product *) * count);
112 print_dashed_header(buffer);
114 print_dashed_header(buffer);
117 for (
unsigned int product_idx = 0; product_idx < count; ++product_idx)
122 print_dashed_header(buffer);
130 const unsigned int product_count = this->index;
133 for (
unsigned int product_idx = 0; product_idx < product_count; ++product_idx)
142 return index < this->index ? this->products[index] : NULL;
int pool_serialise_report(const struct Pool *const this, FILE *const buffer)
bool pool_insert_element(struct Pool *const this, struct Product *const product)
struct Product * pool_get_product_by_index(const struct Pool *const this, const unsigned int index)
void pool_delete(struct Pool **const this)
struct Pool * pool_create(const unsigned int initial_capacity, const float growth_factor)
int pool_serialise_stock_file(const struct Pool *const this, FILE *const buffer)
Pool class specification.
int product_report_serialise(const struct Product *const this, FILE *const buffer)
int product_file_serialise(const struct Product *const this, FILE *const buffer)
void product_delete(struct Product **this)
int product_ptr_compare(const void *const product_lhs, const void *const product_rhs)
Product class specification.
#define MAX_NAME_LENGTH
Maximum number of bytes for a Product name, excluding the NULL-terminator.
An ordered expandable collection of dynamically allocated Product records.
unsigned int capacity
Maximum capacity of the Pool.
static void print_dashed_header(FILE *const buffer)
Print the common header separator consisting of repeated hyphens.
struct Product ** products
Pool elements.
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.
The Product represents a single product with a unique numerical identifier, human-readable name,...