c-icap-doc  0.1
Modules | Macros | Typedefs | Functions

Arrays which store name/value pair items. More...

Modules

 Arrays of strings related API
 Arrays which store name/value pair items.
 
 Arrays of pointers
 Arrays of name/pointers to objects pairs.
 

Macros

#define ci_array_value(array, pos)   (pos < (array)->count ? (array)->items[pos].value : NULL)
 Return the value of item on position 'pos'.
 
#define ci_array_name(array, pos)   (pos < (array)->count ? (array)->items[pos].name : NULL)
 Return the name of item on position 'pos'.
 
#define ci_array_size(array)   ((array)->count)
 Return the size of array 'array'.
 

Typedefs

typedef struct ci_array ci_array_t
 The ci_array_t objects can store a list of name/value pairs. More...
 

Functions

ci_array_tci_array_new (size_t max_mem_size)
 Allocate the required memory and initialize an ci_array_t object. More...
 
ci_array_tci_array_new2 (size_t items, size_t item_size)
 Create and initialize an ci_array_t object for the given number of items. More...
 
void ci_array_destroy (ci_array_t *array)
 Destroy an ci_array_t object. More...
 
const ci_array_item_t * ci_array_add (ci_array_t *array, const char *name, const void *value, size_t size)
 Add an name/value pair item to the array. More...
 
const ci_array_item_t * ci_array_pop (ci_array_t *array)
 Delete the last element of the array. More...
 
const void * ci_array_search (ci_array_t *array, const char *name)
 Search in an array for an item with the given name. More...
 
void ci_array_iterate (const ci_array_t *array, void *data, int(*fn)(void *data, const char *name, const void *))
 Run the given function for each array item. More...
 
const ci_array_item_t * ci_array_get_item (ci_array_t *array, int pos)
 Get an item of the array. More...
 

Detailed Description

Arrays which store name/value pair items.

Typedef Documentation

The ci_array_t objects can store a list of name/value pairs.

Currently can grow up to a fixed size.

Function Documentation

const ci_array_item_t* ci_array_add ( ci_array_t array,
const char *  name,
const void *  value,
size_t  size 
)

Add an name/value pair item to the array.

Parameters
arraya pointer to the ci_array_t object
namethe name part of the name/value pair item to add
valuethe value part of the name/value pair item to add
sizethe size of the value part of the new item.
Returns
a pointer to the new array item on success, NULL otherwise
void ci_array_destroy ( ci_array_t array)

Destroy an ci_array_t object.

Parameters
arraya pointer to ci_array_t object to be destroyed
const ci_array_item_t* ci_array_get_item ( ci_array_t array,
int  pos 
)

Get an item of the array.

Parameters
arraya pointer to the ci_array_t object
posThe position of the item in array
Returns
a pointer to the array item on success, NULL otherwise
void ci_array_iterate ( const ci_array_t array,
void *  data,
int(*)(void *data, const char *name, const void *)  fn 
)

Run the given function for each array item.

Parameters
arraya pointer to the ci_array_t object
dataa pointer to data which will be passed on fn function
fna pointer to the function which will be run for each array item. The iteration will stop if the fn function return non zero value
ci_array_t* ci_array_new ( size_t  max_mem_size)

Allocate the required memory and initialize an ci_array_t object.

Parameters
max_mem_sizethe maximum memory to use
Returns
the allocated object on success, or NULL on failure
ci_array_t* ci_array_new2 ( size_t  items,
size_t  item_size 
)

Create and initialize an ci_array_t object for the given number of items.

Parameters
itemsthe maximum aray items
item_sizethe items size
Returns
the allocated object on success, or NULL on failure
const ci_array_item_t* ci_array_pop ( ci_array_t array)

Delete the last element of the array.

Parameters
arraya pointer to the ci_array_t object
Returns
a pointer to the popped array item on success, NULL otherwise
const void* ci_array_search ( ci_array_t array,
const char *  name 
)

Search in an array for an item with the given name.

Parameters
arraya pointer to the ci_array_t object
namethe item to be search for.
Returns
pointer to the value pair of the array item if found, NULL otherwise