GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_data_storage.h File Reference

Typed recursive storage for key value pairs. More...

Go to the source code of this file.

Data Structures

struct  gp_data_rational
 Rational number. More...
 
struct  gp_data_node
 A data node. More...
 

Typedefs

typedef struct gp_data_node gp_data_node
 A data node.
 

Enumerations

enum  gp_data_type {
  GP_DATA_INT , GP_DATA_STRING , GP_DATA_DOUBLE , GP_DATA_RATIONAL ,
  GP_DATA_DICT
}
 Data type. More...
 

Functions

gp_storage * gp_storage_create (void)
 Creates an empty data storage.
 
void gp_storage_destroy (gp_storage *self)
 Destroys a data storage and frees all its data.
 
gp_data_nodegp_storage_root (gp_storage *self)
 Returns storage root node.
 
void gp_storage_clear (gp_storage *self)
 Clears all data in storage.
 
void gp_data_print (const gp_data_node *node)
 Prints a data node into a stdout.
 
static void gp_storage_print (gp_storage *self)
 Prints a content of a storage into the stdout.
 
const char * gp_data_type_name (enum gp_data_type type)
 Returns a data type name.
 
gp_data_nodegp_storage_add_int (gp_storage *self, gp_data_node *node, const char *id, long i)
 Adds a long integer to a storage.
 
gp_data_nodegp_storage_add_string (gp_storage *self, gp_data_node *node, const char *id, const char *str)
 Adds a string to a storage.
 
gp_data_nodegp_storage_add_double (gp_storage *self, gp_data_node *node, const char *id, double d)
 Adds a double floating point to a storage.
 
gp_data_nodegp_storage_add_rational (gp_storage *self, gp_data_node *node, const char *id, long num, long den)
 Adds a rational number to a storage.
 
gp_data_nodegp_storage_add_dict (gp_storage *self, gp_data_node *node, const char *id)
 Adds a dictionary to a storage.
 

Detailed Description

Typed recursive storage for key value pairs.

Definition in file gp_data_storage.h.

Enumeration Type Documentation

◆ gp_data_type

Data type.

Enumerator
GP_DATA_INT 

A long integer.

GP_DATA_STRING 

A string.

GP_DATA_DOUBLE 

A double.

GP_DATA_RATIONAL 

A rational number.

GP_DATA_DICT 

A dictionary aka hash.

Definition at line 17 of file gp_data_storage.h.

Function Documentation

◆ gp_data_print()

void gp_data_print ( const gp_data_node * node)

Prints a data node into a stdout.

Parameters
nodeA data node.

Referenced by gp_storage_print().

◆ gp_data_type_name()

const char * gp_data_type_name ( enum gp_data_type type)

Returns a data type name.

Parameters
typeA data type.
Returns
Returns a data type name.

◆ gp_storage_add_dict()

gp_data_node * gp_storage_add_dict ( gp_storage * self,
gp_data_node * node,
const char * id )

Adds a dictionary to a storage.

Parameters
storageA storage to add the data to.
nodeA dict node to add the data to, if NULL data are added to root node.
idA name for the newly added node.
Returns
A pointer to a newly added node or NULL in a case of a failure.

◆ gp_storage_add_double()

gp_data_node * gp_storage_add_double ( gp_storage * self,
gp_data_node * node,
const char * id,
double d )

Adds a double floating point to a storage.

Parameters
storageA storage to add the data to.
nodeA dict node to add the data to, if NULL data are added to root node.
idA name for the newly added node.
dA value for the newly added node.
Returns
A pointer to a newly added node or NULL in a case of a failure.

◆ gp_storage_add_int()

gp_data_node * gp_storage_add_int ( gp_storage * self,
gp_data_node * node,
const char * id,
long i )

Adds a long integer to a storage.

Parameters
storageA storage to add the data to.
nodeA dict node to add the data to, if NULL data are added to root node.
idA name for the newly added node.
iA value for the newly added node.
Returns
A pointer to a newly added node or NULL in a case of a failure.

◆ gp_storage_add_rational()

gp_data_node * gp_storage_add_rational ( gp_storage * self,
gp_data_node * node,
const char * id,
long num,
long den )

Adds a rational number to a storage.

Parameters
storageA storage to add the data to.
nodeA dict node to add the data to, if NULL data are added to root node.
idA name for the newly added node.
numA numerator value for the newly added node.
denA denominator value for the newly added node.
Returns
A pointer to a newly added node or NULL in a case of a failure.

◆ gp_storage_add_string()

gp_data_node * gp_storage_add_string ( gp_storage * self,
gp_data_node * node,
const char * id,
const char * str )

Adds a string to a storage.

Parameters
storageA storage to add the data to.
nodeA dict node to add the data to, if NULL data are added to root node.
idA name for the newly added node.
strA value for the newly added node.
Returns
A pointer to a newly added node or NULL in a case of a failure.

◆ gp_storage_clear()

void gp_storage_clear ( gp_storage * self)

Clears all data in storage.

After this call the data storage is empty as it was just created with gp_storage_create().

Parameters
selfA data storage.

◆ gp_storage_create()

gp_storage * gp_storage_create ( void )

Creates an empty data storage.

Returns
A newly created data storage or NULL in a case of a failure.

◆ gp_storage_destroy()

void gp_storage_destroy ( gp_storage * self)

Destroys a data storage and frees all its data.

Parameters
selfA data storage to be freed.

◆ gp_storage_print()

static void gp_storage_print ( gp_storage * self)
inlinestatic

Prints a content of a storage into the stdout.

Parameters
selfA data storage.

Definition at line 116 of file gp_data_storage.h.

References gp_data_print(), and gp_storage_root().

◆ gp_storage_root()

gp_data_node * gp_storage_root ( gp_storage * self)

Returns storage root node.

The root node in data storage is always a dictionary.

Parameters
selfA data storage.
Returns
Data storage root.

Referenced by gp_storage_print().