72#define UNLIMITED_LIST_ITEMS 0
74#define MAX_LIST_ITEMS SIZE_MAX
77#define link_node(__NODE_1, __NODE_2) \
79 if (!(__NODE_1) || !(__NODE_2)) { \
80 n_log(LOG_ERR, "link_node: NULL argument (%s=%p, %s=%p)", #__NODE_1, (void*)(__NODE_1), #__NODE_2, (void*)(__NODE_2)); \
82 (__NODE_2)->prev = (__NODE_1); \
83 (__NODE_1)->next = (__NODE_2); \
88#define list_foreach(__ITEM_, __LIST_) \
89 for (LIST_NODE* __ITEM_ = (__LIST_) ? (__LIST_)->start : NULL, *__next_##__ITEM_ = __ITEM_ ? __ITEM_->next : NULL; __ITEM_; __ITEM_ = __next_##__ITEM_, \
90 __next_##__ITEM_ = __ITEM_ ? __ITEM_->next : NULL)
93#define list_pop(__LIST_, __TYPE_) (__TYPE_*)list_pop_f(__LIST_)
95#define list_shift(__LIST_, __TYPE_) (__TYPE_*)list_shift_f(__LIST_, __FILE__, __LINE__)
97#define remove_list_node(__LIST_, __NODE_, __TYPE_) (__TYPE_*)remove_list_node_f(__LIST_, __NODE_)
115int list_push(
LIST* list,
void* ptr,
void (*destructor)(
void* ptr));
117int list_push_sorted(
LIST* list,
void* ptr,
int (*comparator)(
const void* a,
const void* b),
void (*destructor)(
void* ptr));
121int 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 items 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 last ptr from list
void * list_shift_f(LIST *list, char *file, size_t line)
get first ptr from list
int list_empty(LIST *list)
empty the list
LIST_NODE * list_search(LIST *list, const void *ptr)
search ptr in list
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
add a pointer at the end of the list
int list_node_unshift(LIST *list, LIST_NODE *node)
unshift a node at the beginning of the list
int list_unshift(LIST *list, void *ptr, void(*destructor)(void *ptr))
put a pointer at the beginning of list
LIST_NODE * list_node_shift(LIST *list)
shift a node from the beginning of the list
LIST_NODE * new_list_node(void *ptr, void(*destructor)(void *ptr))
create a new node
int list_destroy(LIST **list)
free the list
int list_unshift_sorted(LIST *list, void *ptr, int(*comparator)(const void *a, const void *b), void(*destructor)(void *ptr))
put a pointer sorted via comparator from the start to the end
LIST_NODE * list_node_pop(LIST *list)
pop a node from the end of the list
void * remove_list_node_f(LIST *list, LIST_NODE *node)
remove a node
LIST * new_generic_list(size_t max_items)
initialize a list
int list_push_sorted(LIST *list, void *ptr, int(*comparator)(const void *a, const void *b), void(*destructor)(void *ptr))
add a pointer sorted via comparator from the end of the list
int list_empty_with_f(LIST *list, void(*free_fnct)(void *ptr))
empty the list with a custom free function
LIST_NODE * list_search_with_f(LIST *list, int(*checkfunk)(void *ptr))
search for data in list
int list_node_push(LIST *list, LIST_NODE *node)
push a node at the end of the list
Structure of a generic LIST container.
Structure of a generic list node.