1 #pragma once 2 3 #include <stdbool.h> 4 #include <stdlib.h> 5 6 struct list_node_t; 7 typedef struct list_node_t list_node_t; 8 9 struct list_t; 10 typedef struct list_t list_t; 11 12 typedef void (*list_free_cb)(void *data); 13 typedef bool (*list_iter_cb)(void *data); 14 15 // Lifecycle. 16 list_t *list_new(list_free_cb callback); 17 void list_free(list_t *list); 18 19 // Accessors. 20 bool list_is_empty(const list_t *list); 21 size_t list_length(const list_t *list); 22 void *list_front(const list_t *list); 23 void *list_back(const list_t *list); 24 25 // Mutators. 26 bool list_insert_after(list_t *list, list_node_t *prev_node, void *data); 27 bool list_prepend(list_t *list, void *data); 28 bool list_append(list_t *list, void *data); 29 bool list_remove(list_t *list, void *data); 30 void list_clear(list_t *list); 31 32 // Iteration. 33 void list_foreach(const list_t *list, list_iter_cb callback); 34 35 list_node_t *list_begin(const list_t *list); 36 list_node_t *list_end(const list_t *list); 37 list_node_t *list_next(const list_node_t *node); 38 void *list_node(const list_node_t *node); 39