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

The Product represents a single product with a unique numerical identifier, human-readable name, and integral non-negative quantity. More...

#include <Product.h>

Collaboration diagram for Product:

Public Member Functions

struct Productproduct_create (unsigned int id, const char *name, unsigned int quantity)
 Create a new Product with the given initial properties.
 
void product_delete (struct Product **this)
 Delete the given dynamically initialised Product and reset its pointer.
 
int product_report_serialise (const struct Product *this, FILE *buffer)
 Serialise the given Product in the report format to the given buffer.
 
int product_file_serialise (const struct Product *this, FILE *buffer)
 Serialise the given Product in the stock file format to the given buffer.
 
bool product_modify_quantity (struct Product *this, int modifier)
 Attempt to modify the quantity of the given Product.
 
int product_ptr_compare (const void *product_lhs, const void *product_rhs)
 Compare the Product items pointed to by the given LHS and RHS according to stock levels.
 

Data Fields

unsigned int id
 Numerical identifier of the Product.
 
unsigned int quantity
 Non-negative number of Product items in stock.
 
char name [MAX_NAME_LENGTH+1]
 NULL-terminated human-readable name of the Product.
 

Detailed Description

The Product represents a single product with a unique numerical identifier, human-readable name, and integral non-negative quantity.

Definition at line 21 of file Product.c.

Member Function Documentation

◆ product_create()

struct Product * product_create ( unsigned int  id,
const char *  name,
unsigned int  quantity 
)

Create a new Product with the given initial properties.

Parameters
idThe numerical identifier of the Product.
nameA human-readable name of the Product.
quantityThe initial quantity of the Product in stock.
Returns
The dynamically allocated Product with the initial properties set.

Definition at line 28 of file Product.c.

◆ product_delete()

void product_delete ( struct Product **  this)

Delete the given dynamically initialised Product and reset its pointer.

Parameters
thisThe Product to delete.

Definition at line 53 of file Product.c.

◆ product_file_serialise()

int product_file_serialise ( const struct Product this,
FILE *  buffer 
)

Serialise the given Product in the stock file format to the given buffer.

Parameters
thisThe Product to serialise.
bufferThe destination file buffer for the serialised Product information.
Returns
The number of bytes written, or negative if an error occurred. In the latter case, errno is set.

Definition at line 64 of file Product.c.

◆ product_modify_quantity()

bool product_modify_quantity ( struct Product this,
int  modifier 
)

Attempt to modify the quantity of the given Product.

Parameters
thisThe Product to modify.
modifierThe amount by which the quantity of the given Product should be incremented or decremented.
Returns
Was the modification successful? Modification will fail if and only if the quantity would go negative.

Definition at line 69 of file Product.c.

◆ product_ptr_compare()

int product_ptr_compare ( const void *  product_lhs,
const void *  product_rhs 
)

Compare the Product items pointed to by the given LHS and RHS according to stock levels.

Parameters
product_lhsThe LHS Product operand
product_rhsThe RHS Product operand
Returns
  • -1 if the stock level of the LHS operand is strictly less than the stock level of the RHS operand;
  • 0 if the stock level of the LHS operand is equal to the stock level of the RHS operand; or
  • 1 if the stock level of the LHS operand is strictly greater than the stock level of the RHS operand.

Definition at line 78 of file Product.c.

◆ product_report_serialise()

int product_report_serialise ( const struct Product this,
FILE *  buffer 
)

Serialise the given Product in the report format to the given buffer.

Parameters
thisThe Product to serialise.
bufferThe destination file buffer for the serialised Product information.
Returns
The number of bytes written, or negative if an error occurred. In the latter case, errno is set.

Definition at line 59 of file Product.c.

Field Documentation

◆ id

unsigned int Product::id

Numerical identifier of the Product.

Definition at line 23 of file Product.c.

◆ name

char Product::name[MAX_NAME_LENGTH+1]

NULL-terminated human-readable name of the Product.

Definition at line 25 of file Product.c.

◆ quantity

unsigned int Product::quantity

Non-negative number of Product items in stock.

Definition at line 24 of file Product.c.


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