Go to the source code of this file.
OCS linked list API
Definition in file ocs_list.h.
Data Structures | |
| struct | ocs_list_t |
| list/link structure More... | |
Macros | |
| #define | OCS_LIST_DEBUG |
| #define | ocs_list_magic_decl uint32_t magic; |
| #define | OCS_LIST_LIST_MAGIC 0xcafe0000 |
| #define | OCS_LIST_LINK_MAGIC 0xcafe0001 |
| #define | ocs_list_set_list_magic list->magic = OCS_LIST_LIST_MAGIC |
| #define | ocs_list_set_link_magic list->magic = OCS_LIST_LINK_MAGIC |
| #define | ocs_list_assert(cond,...) |
| #define | item2link(list, item) ((ocs_list_t*) (((uint8_t*)(item)) + (list)->offset)) |
| #define | link2item(list, link) ((void*) (((uint8_t*)(link)) - (list)->offset)) |
| #define | ocs_list_init(head, type, link) _ocs_list_init(head, offsetof(type, link)) |
| #define | ocs_list_remove_head(list) ocs_list_remove(list, ocs_list_get_head(list)) |
| Remove and return an item from the head of the list. More... | |
| #define | ocs_list_foreach(list, item) for (item = ocs_list_get_head((list)); item; item = ocs_list_next((list), item) ) |
| Iterate a linked list. More... | |
| #define | ocs_list_foreach_safe(list, item, nxt) |
| Iterate a linked list safely. More... | |
Typedefs | |
| typedef ocs_list_t | ocs_list_link_t |
Functions | |
| void | _ocs_list_assertmsg (const char *label, const char *filename, int linenum) |
| static void | _ocs_list_init (ocs_list_t *list, uint32_t offset) |
| Initialize a list. More... | |
| static int32_t | ocs_list_empty (ocs_list_t *list) |
| Test if a list is empty. More... | |
| static int32_t | ocs_list_is_singular (ocs_list_t *list) |
| Test if a list has single entry. More... | |
| static int | ocs_list_valid (ocs_list_t *list) |
| Test if a list is valid (ready for use) More... | |
| static void | _ocs_list_insert_link (ocs_list_t *a, ocs_list_t *b, ocs_list_t *c) |
| Insert link between two other links. More... | |
| static void | ocs_list_init_link (ocs_list_t *list, ocs_list_t *link) |
| Initialize a list link for debug purposes. More... | |
| static void | ocs_list_add_head (ocs_list_t *list, void *item) |
| Add an item to the head of the list. More... | |
| static void | ocs_list_add_tail (ocs_list_t *list, void *item) |
| Add an item to the tail of the list. More... | |
| static void * | ocs_list_get_head (ocs_list_t *list) |
| Return the first item in the list. More... | |
| static void * | ocs_list_get_tail (ocs_list_t *list) |
| Return the first item in the list. More... | |
| static void * | ocs_list_tail (ocs_list_t *list) |
| Return the last item in the list. More... | |
| static void * | ocs_list_next (ocs_list_t *list, void *item) |
| Get the next item on the list. More... | |
| static void * | ocs_list_remove (ocs_list_t *list, void *item) |
| Remove an item from the list. More... | |
| static int32_t | ocs_list_on_list (ocs_list_link_t *link) |
| Test if object is on a list. More... | |
| #define item2link | ( | list, | |
| item | |||
| ) | ((ocs_list_t*) (((uint8_t*)(item)) + (list)->offset)) |
Definition at line 87 of file ocs_list.h.
| #define link2item | ( | list, | |
| link | |||
| ) | ((void*) (((uint8_t*)(link)) - (list)->offset)) |
Definition at line 90 of file ocs_list.h.
| #define ocs_list_assert | ( | cond, | |
| ... | |||
| ) |
Definition at line 55 of file ocs_list.h.
| #define OCS_LIST_DEBUG |
Definition at line 43 of file ocs_list.h.
| #define ocs_list_foreach | ( | list, | |
| item | |||
| ) | for (item = ocs_list_get_head((list)); item; item = ocs_list_next((list), item) ) |
Iterate a linked list.
Iterate a linked list.
| list | Pointer to list |
| item | Pointer to iterated item |
note, item is NULL after full list is traversed.
Definition at line 428 of file ocs_list.h.
| #define ocs_list_foreach_safe | ( | list, | |
| item, | |||
| nxt | |||
| ) |
Iterate a linked list safely.
Iterate a linked list safely, meaning that the iterated item may be safely removed from the list.
| list | Pointer to list |
| item | Pointer to iterated item |
| nxt | Pointer to saveed iterated item |
note, item is NULL after full list is traversed.
Definition at line 446 of file ocs_list.h.
| #define ocs_list_init | ( | head, | |
| type, | |||
| link | |||
| ) | _ocs_list_init(head, offsetof(type, link)) |
Definition at line 113 of file ocs_list.h.
| #define OCS_LIST_LINK_MAGIC 0xcafe0001 |
Definition at line 51 of file ocs_list.h.
| #define OCS_LIST_LIST_MAGIC 0xcafe0000 |
Definition at line 50 of file ocs_list.h.
| #define ocs_list_magic_decl uint32_t magic; |
Definition at line 49 of file ocs_list.h.
| #define ocs_list_set_link_magic list->magic = OCS_LIST_LINK_MAGIC |
Definition at line 53 of file ocs_list.h.
| #define ocs_list_set_list_magic list->magic = OCS_LIST_LIST_MAGIC |
Definition at line 52 of file ocs_list.h.
| typedef ocs_list_t ocs_list_link_t |
Definition at line 84 of file ocs_list.h.
| void _ocs_list_assertmsg | ( | const char * | label, |
| const char * | filename, | ||
| int | linenum | ||
| ) |
Definition at line 35 of file ocs_list.c.
|
inlinestatic |
Initialize a list.
A list object is initialized. Helper define is used to call _ocs_list_init() with offsetof(type, link)
| list | Pointer to list |
| offset | Offset in bytes in item to the link element |
Definition at line 104 of file ocs_list.h.
|
inlinestatic |
Insert link between two other links.
Inserts a link in between two other links
| a | Pointer to first link |
| b | Pointer to next link |
| c | Pointer to link to insert between a and b |
Definition at line 172 of file ocs_list.h.
|
inlinestatic |
Initialize a list link for debug purposes.
For debugging a linked list link element has a magic number that is initialized, and the offset value initialzied and used for subsequent assertions.
| list | Pointer to list head |
| link | Pointer to link to be initialized |
Definition at line 210 of file ocs_list.h.
|
inlinestatic |
Test if object is on a list.
Returns True if object is on a list
| link | Pointer to list link |
Definition at line 460 of file ocs_list.h.