c-icap-doc  0.1
Macros | Typedefs | Functions


Lists for storing items, and can grow unlimited. More...

Macros

#define ci_list_first(list)   (list && (list)->items && (((list)->cursor = (list)->items->next) != NULL || 1) ? (list)->items->item : NULL)
 
Gets the first item of the list and updates the list cursor to the next item. More...
 
#define ci_list_next(list)   (((list)->tmp = (list)->cursor) != NULL && (((list)->cursor = (list)->cursor->next) != NULL || 1) ? (list)->tmp->item : NULL)
 
Return the next item of the list and updates the list cursor to the next item. More...
 
#define ci_list_head(list)   (list && list->items != NULL ? list->items->item : NULL)
 
Return the head of the list
 
#define ci_list_tail(list)   (list && list->last != NULL ? list->last->item : NULL)
 
Return last item of the list.
 

Typedefs

typedef struct ci_list ci_list_t
 
The ci_list_t objects can store a list of objects, with a predefined size. More...
 

Functions

ci_list_tci_list_create (size_t init_size, size_t obj_size)
 
Allocate the required memory and initialize a ci_list_t object More...
 
void ci_list_destroy (ci_list_t *list)
 
Destroy an ci_list_t object More...
 
void ci_list_iterate (ci_list_t *list, void *data, int(*fn)(void *data, const void *obj))
 
Run the given function for each list item More...
 
const void * ci_list_push (ci_list_t *list, const void *obj)
 
Add an item to the head of list. More...
 
const void * ci_list_push_back (ci_list_t *list, const void *data)
 
Add an item to the tail of list. More...
 
void * ci_list_pop (ci_list_t *list, void *obj)
 
Remove the first item of the list. More...
 
void * ci_list_pop_back (ci_list_t *list, void *obj)
 
Remove the last item of the list. More...
 
int ci_list_remove (ci_list_t *list, const void *obj)
 
Remove the first found item equal to the obj. More...
 
const void * ci_list_search (ci_list_t *list, const void *data)
 
Return the first found item equal to the obj. More...
 
const void * ci_list_search2 (ci_list_t *list, const void *data, int(*cmp_func)(const void *obj, const void *user_data, size_t user_data_size))
 
Return the first found item equal to the obj, using the cmp_func as comparison function. More...
 
void ci_list_sort (ci_list_t *list)
 
Sorts the list using as compare function the default. More...
 
void ci_list_sort2 (ci_list_t *list, int(*cmp_func)(const void *obj1, const void *obj2, size_t obj_size))
 
Sorts the list using as compare function the cmp_func. More...
 

Detailed Description


Lists for storing items, and can grow unlimited.

Macro Definition Documentation

◆ ci_list_first

#define ci_list_first (   list)    (list && (list)->items && (((list)->cursor = (list)->items->next) != NULL || 1) ? (list)->items->item : NULL)


Gets the first item of the list and updates the list cursor to the next item.

WARNING: do not mix this macro with ci_list_iterate. Use the ci_list_head and ci_list_tail macros instead

Parameters
lista pointer to the ci_list_t object
Returns
The first item if exist, NULL otherwise

◆ ci_list_next

#define ci_list_next (   list)    (((list)->tmp = (list)->cursor) != NULL && (((list)->cursor = (list)->cursor->next) != NULL || 1) ? (list)->tmp->item : NULL)


Return the next item of the list and updates the list cursor to the next item.

WARNING: It does not check for valid list object. WARNING: do not mix this macro with ci_list_iterate!

Parameters
lista pointer to the ci_list_t object
Returns
The next item if exist, NULL otherwise

Typedef Documentation

◆ ci_list_t


The ci_list_t objects can store a list of objects, with a predefined size.

The list items can be removed. The memory RAM space of list can not be decreased before the ci_list destroyed. However the memory of removed items reused.

Function Documentation

◆ ci_list_create()

ci_list_t* ci_list_create ( size_t  init_size,
size_t  obj_size 
)


Allocate the required memory and initialize a ci_list_t object

Parameters
init_sizethe initial memory size to use
obj_sizethe size of stored objects. If it is 0 then stores pointers to objects.
Returns
the allocated object on success, or NULL on failure

◆ ci_list_destroy()

void ci_list_destroy ( ci_list_t list)


Destroy an ci_list_t object

Parameters
lista pointer to ci_list_t object to be destroyed

◆ ci_list_iterate()

void ci_list_iterate ( ci_list_t list,
void *  data,
int(*)(void *data, const void *obj)  fn 
)


Run the given function for each list item

Parameters
lista pointer to the ci_list_t object
dataa pointer to data which will be passed to the fn function
fna pointer to the function which will be run for each vector item. The iteration will stop if the fn function return non zero value.

◆ ci_list_pop()

void* ci_list_pop ( ci_list_t list,
void *  obj 
)


Remove the first item of the list.

Parameters
lista pointer to the ci_list_t object
objpointer to an object to store removed item
Returns
a pointer to the obj on success, NULL otherwise

◆ ci_list_pop_back()

void* ci_list_pop_back ( ci_list_t list,
void *  obj 
)


Remove the last item of the list.

Parameters
lista pointer to the ci_list_t object
objpointer to an object to store removed item
Returns
a pointer to the obj on success, NULL otherwise

◆ ci_list_push()

const void* ci_list_push ( ci_list_t list,
const void *  obj 
)


Add an item to the head of list.

Parameters
lista pointer to the ci_list_t object
objpointer to the object to add in vector
Returns
a pointer to the new item on success, NULL otherwise

◆ ci_list_push_back()

const void* ci_list_push_back ( ci_list_t list,
const void *  data 
)


Add an item to the tail of list.

Parameters
lista pointer to the ci_list_t object
objpointer to the object to add in vector
Returns
a pointer to the new item on success, NULL otherwise

◆ ci_list_remove()

int ci_list_remove ( ci_list_t list,
const void *  obj 
)


Remove the first found item equal to the obj.

Parameters
lista pointer to the ci_list_t object
objpointer to an object to remove
Returns
not 0 on success, 0 otherwise

◆ ci_list_search()

const void* ci_list_search ( ci_list_t list,
const void *  data 
)


Return the first found item equal to the obj.

Parameters
lista pointer to the ci_list_t object
objpointer to an object to remove
Returns
the found item on success, NULL otherwise

◆ ci_list_search2()

const void* ci_list_search2 ( ci_list_t list,
const void *  data,
int(*)(const void *obj, const void *user_data, size_t user_data_size)  cmp_func 
)


Return the first found item equal to the obj, using the cmp_func as comparison function.

Parameters
lista pointer to the ci_list_t object
objpointer to an object to remove
cmp_functhe comparison function to use
Returns
the found item on success, NULL otherwise

◆ ci_list_sort()

void ci_list_sort ( ci_list_t list)


Sorts the list using as compare function the default.

Parameters
lista pointer to the ci_list_t object

◆ ci_list_sort2()

void ci_list_sort2 ( ci_list_t list,
int(*)(const void *obj1, const void *obj2, size_t obj_size)  cmp_func 
)


Sorts the list using as compare function the cmp_func.

Parameters
lista pointer to the ci_list_t object
cmp_functhe compare function to use