![]() |
Lucciefr
Lua code caving, injection and exploration framework
|
Generic list management macros. More...
Go to the source code of this file.
Macros | |
#define | LIST_ITERATE(element, head) for (element = head; element; element = element->next) |
Iterate over the list, starting at head and moving 'forward'. More... | |
#define | LIST_LAST(element, head) |
Find the last element in the list. More... | |
#define | LIST_ITERATE_REVERSED(element, head) |
Iterate over the list in 'reverse' order, starting at end and moving 'backwards'. More... | |
#define | LIST_MATCH(element, head, condition) |
Find the first match to a specific condition, returns either an element pointer or NULL . More... | |
#define | LIST_FIND(element, head, value) LIST_MATCH(element, head, element == value) |
Find a specific element pointer (the first one matching "value") within the list. | |
#define | LIST_COUNT(counter, head) |
Count the elements in the list. More... | |
#define | LIST_APPEND(element, head) |
Append a new element to the list (i.e. add at the end). More... | |
#define | LIST_DELETE(element, head) |
Delete an element from the list. More... | |
Generic list management macros.
These (preprocessor) macros will directly work with pointers to data structures (mystruct*
), and operate on them as a double-linked list.
The only requirement is that your structure provides two (void*)
pointers prev
and next
, which indicate the previous and next elements in the list. The list itself is referred to (and kept track of) by a pointer to the first element (head
).
NULL
pointers or breaking the pointer chain (e.g. by appending the same element twice, or deleting elements not contained within the list). If you need to safeguard against this, do so in your own code! #define LIST_APPEND | ( | element, | |
head | |||
) |
Append a new element to the list (i.e. add at the end).
#define LIST_COUNT | ( | counter, | |
head | |||
) |
Count the elements in the list.
#define LIST_DELETE | ( | element, | |
head | |||
) |
Delete an element from the list.
#define LIST_ITERATE | ( | element, | |
head | |||
) | for (element = head; element; element = element->next) |
Iterate over the list, starting at head and moving 'forward'.
#define LIST_ITERATE_REVERSED | ( | element, | |
head | |||
) |
Iterate over the list in 'reverse' order, starting at end and moving 'backwards'.
for
loop prevents that, and syntactic reasons won't allow macro expansion/assignment of element
via the initializer expression in a single statement.) Be careful to avoid situations where that might lead to problems: #define LIST_LAST | ( | element, | |
head | |||
) |
Find the last element in the list.
#define LIST_MATCH | ( | element, | |
head, | |||
condition | |||
) |
Find the first match to a specific condition, returns either an element pointer or NULL
.
This is simply done by testing condition
while (partially) iterating the list.