54#define UNLIMITED_LIST_ITEMS 0
56#define MAX_LIST_ITEMS SIZE_MAX
59#define link_node(__NODE_1, __NODE_2) \
61 __NODE_2->prev = __NODE_1; \
62 __NODE_1->next = __NODE_2; \
66#define list_foreach(__ITEM_, __LIST_) \
68 n_log(LOG_ERR, "Error in list_foreach, %s is NULL", #__LIST_); \
70 for (LIST_NODE* __ITEM_ = __LIST_->start; __ITEM_; __ITEM_ = __ITEM_->next)
73#define list_pop(__LIST_, __TYPE_) (__TYPE_*)list_pop_f(__LIST_)
75#define list_shift(__LIST_, __TYPE_) (__TYPE_*)list_shift_f(__LIST_, __FILE__, __LINE__)
77#define remove_list_node(__LIST_, __NODE_, __TYPE_) (__TYPE_*)remove_list_node_f(__LIST_, __NODE_)
91int list_push(
LIST* list,
void* ptr,
void (*destructor)(
void* ptr));
93int list_push_sorted(
LIST* list,
void* ptr,
int (*comparator)(
const void* a,
const void* b),
void (*destructor)(
void* ptr));
97int list_unshift_sorted(
LIST* list,
void* ptr,
int (*comparator)(
const void* a,
const void* b),
void (*destructor)(
void* ptr));
LIST_NODE * end
pointer to the end of the list
void * ptr
void pointer to store
size_t nb_max_items
maximum number of item in the list.
struct LIST_NODE * prev
pointer to the previous node
LIST_NODE * start
pointer to the start of the list
size_t nb_items
number of item currently in the list
void(* destroy_func)(void *ptr)
pointer to destructor function if any, else NULL
struct LIST_NODE * next
pointer to the next node
void * list_pop_f(LIST *list)
Get a pointer from the end of the list.
void * list_shift_f(LIST *list, char *file, size_t line)
Get a pointer from the start of the list.
int list_empty(LIST *list)
Empty a LIST list of pointers.
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
int list_node_unshift(LIST *list, LIST_NODE *node)
Add a pointer at the start of the list.
int list_unshift(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer at the start of the list.
LIST_NODE * list_node_shift(LIST *list)
Get a LIST_NODE pointer from the start of the list.
LIST_NODE * new_list_node(void *ptr, void(*destructor)(void *ptr))
Allocate a new node to link in a list.
int list_destroy(LIST **list)
Empty and Free a list container.
int list_unshift_sorted(LIST *list, void *ptr, int(*comparator)(const void *a, const void *b), void(*destructor)(void *ptr))
Add a pointer sorted in the list , starting by the start of the list.
LIST_NODE * list_node_pop(LIST *list)
Get a LIST_NODE pointer from the end of the list.
void * remove_list_node_f(LIST *list, LIST_NODE *node)
Internal function called each time we need to get a node out of a list.
LIST_NODE * list_search(LIST *list, void *ptr)
search ptr in list
LIST * new_generic_list(size_t max_items)
Initialiaze a generic list container to max_items pointers.
int list_push_sorted(LIST *list, void *ptr, int(*comparator)(const void *a, const void *b), void(*destructor)(void *ptr))
Add a pointer sorted in the list , starting by the end of the list.
int list_empty_with_f(LIST *list, void(*free_fnct)(void *ptr))
Empty a LIST list of pointers.
LIST_NODE * list_search_with_f(LIST *list, int(*checkfunk)(void *ptr))
search ptr in list
int list_node_push(LIST *list, LIST_NODE *node)
Add a filled node to the end of the list.
Structure of a generic LIST container.
Structure of a generic list node.