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

Arrays which store name/value pair items, and can grow unlimited. More...

Modules

 Dynamic arrays of pointers related API
 Arrays which store name/value pair items.
 

Macros

#define ci_dyn_array_get_item(array, pos)   (pos < (array)->count ? (array)->items[pos] : NULL)
 Return the ci_array_item_t item on position 'pos'.
 
#define ci_dyn_array_value(array, pos)   ((pos < (array)->count && (array)->items[pos] != NULL) ? (array)->items[pos]->value : NULL)
 Return the value of item on position 'pos'.
 
#define ci_dyn_array_name(array, pos)   ((pos < (array)->count && (array)->items[pos] != NULL) ? (array)->items[pos]->name : NULL)
 Return the name of item on position 'pos'.
 
#define ci_dyn_array_size(array)   ((array)->count)
 Return the size of array 'array'.
 

Typedefs

typedef struct ci_dyn_array ci_dyn_array_t
 The ci_dyn_array_t objects can store a list of name/value pairs. More...
 

Functions

ci_dyn_array_tci_dyn_array_new (size_t mem_size)
 Allocate the required memory and initialize an ci_dyn_array_t object. More...
 
ci_dyn_array_tci_dyn_array_new2 (size_t items, size_t item_size)
 Create and initialize an ci_dyn_array_t object for the given number of items. More...
 
void ci_dyn_array_destroy (ci_dyn_array_t *array)
 Destroy an ci_dyn_array_t object. More...
 
const ci_array_item_t * ci_dyn_array_add (ci_dyn_array_t *array, const char *name, const void *value, size_t size)
 Add an name/value pair item to a dynamic array. More...
 
const void * ci_dyn_array_search (ci_dyn_array_t *array, const char *name)
 Search in an dynamic array for an item with the given name. More...
 
void ci_dyn_array_iterate (const ci_dyn_array_t *array, void *data, int(*fn)(void *data, const char *name, const void *))
 Run the given function for each dynamic array item. More...
 

Detailed Description

Arrays which store name/value pair items, and can grow unlimited.

Typedef Documentation

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

The memory RAM space of dynamic array items can not be released before the ci_dyn_array destroyed.

Function Documentation

const ci_array_item_t* ci_dyn_array_add ( ci_dyn_array_t array,
const char *  name,
const void *  value,
size_t  size 
)

Add an name/value pair item to a dynamic array.

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

Destroy an ci_dyn_array_t object.

Parameters
arraya pointer to ci_dyn_array_t object to be destroyed
void ci_dyn_array_iterate ( const ci_dyn_array_t array,
void *  data,
int(*)(void *data, const char *name, const void *)  fn 
)

Run the given function for each dynamic array item.

Parameters
arraya pointer to the ci_dyn_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_dyn_array_t* ci_dyn_array_new ( size_t  mem_size)

Allocate the required memory and initialize an ci_dyn_array_t object.

Parameters
mem_sizethe initial size to use for dyn_array
Returns
the allocated object on success, or NULL on failure
ci_dyn_array_t* ci_dyn_array_new2 ( size_t  items,
size_t  item_size 
)

Create and initialize an ci_dyn_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 void* ci_dyn_array_search ( ci_dyn_array_t array,
const char *  name 
)

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

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