libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
|
Go to the source code of this file.
Functions | |
void | list_create (list_t *, size_t, size_t) |
void | list_destroy (list_t *) |
void | list_insert_after (list_t *, void *, void *) |
void | list_insert_before (list_t *, void *, void *) |
void | list_insert_head (list_t *, void *) |
void | list_insert_tail (list_t *, void *) |
void | list_remove (list_t *, void *) |
void * | list_remove_head (list_t *) |
void * | list_remove_tail (list_t *) |
void | list_move_tail (list_t *, list_t *) |
void * | list_head (const list_t *) |
void * | list_tail (const list_t *) |
void * | list_next (const list_t *, const void *) |
void * | list_prev (const list_t *, const void *) |
void * | list_get_i (const list_t *, size_t) |
int | list_is_empty (const list_t *) |
void | list_link_init (list_node_t *) |
void | list_link_replace (list_node_t *, list_node_t *) |
int | list_link_active (const list_node_t *) |
size_t | list_count (const list_t *) |
This is a general-purpose doubly-linked list system. It is designed to be easy to integrate into pre-existing data structures and has many functions to manipulate and examine the linked list.
Definition in file list.h.
size_t list_count | ( | const list_t * | list | ) |
void list_create | ( | list_t * | list, |
size_t | size, | ||
size_t | offset | ||
) |
Initializes a new linked list. This must be called before a list_t is used. When you are done with the linked list, you must deinitialize it using list_destroy().
Data structures to be held in the linked list must have a list_node_t field added to them. This is where the linked list will keep its lists node references. If you want to hold an object in more than one linked list, you will need a separate list_node_t for each linked list. A single list_node_t cannot be shared at the same time between multiple lists.
list | The linked list to be initialized. |
size | The size in bytes of the objects to be referenced in the linked list. This is mostly meant for error-checking for the placement of the list node. |
offset | Offset within the data structures that will be contained in the list_t to where the list_node_t field is. You should use the standard offsetof() for this purpose. |
void list_destroy | ( | list_t * | list | ) |
Destroys a list_t structure which was previously initialized using list_create(). The list MUST be empty before this is done, otherwise an assertion failure is tripped.
void * list_get_i | ( | const list_t * | list, |
size_t | i | ||
) |
Performs an iterative search through the list to retrieve a particular element in the list in order.
i | The index of the item in the list (counting from 0). This must be less than the total number of items in the list as returned by list_count(). |
void * list_head | ( | const list_t * | list | ) |
void list_insert_after | ( | list_t * | list, |
void * | object, | ||
void * | nobject | ||
) |
Inserts a new object immediately after another object into a linked list.
list | The list into which the insert will be performed. |
object | The preceding object, after which the new object will be inserted. |
nobject | The new object being inserted. It will be inserted immediately following object . |
void list_insert_before | ( | list_t * | list, |
void * | object, | ||
void * | nobject | ||
) |
Inserts a new object immediately in front of another object into a linked list.
list | The list into which the insert will be performed. |
object | The following object, in front of which the new object will be inserted. |
nobject | The new object being inserted. It will be inserted immediately in front of object . |
void list_insert_head | ( | list_t * | list, |
void * | object | ||
) |
void list_insert_tail | ( | list_t * | list, |
void * | object | ||
) |
int list_is_empty | ( | const list_t * | list | ) |
int list_link_active | ( | const list_node_t * | link | ) |
void list_link_init | ( | list_node_t * | link | ) |
Initializes a list_node_t so that subsequent calls to list_link_active() can determine the activity status of that node correctly. This is equivalent to just setting the contents of the node to NULL, so you can achieve the same effect of this function by simply allocating the structure containing the list_node_t using an allocation function which zeros out the memory contents during allocation (such as calloc()).
void list_link_replace | ( | list_node_t * | lold, |
list_node_t * | lnew | ||
) |
Replaces an object in a linked list with another object, without the need to have a reference to the original list_t.
lold | A pointer to the list_node_t of the old object, which is to be replaced by the new object. This object MUST be in a list (list_link_active() returns true). |
lnew | A pointer to the list_node_t of the new object, which is to replace the old object. This object must NOT be in a list (list_link_active() returns false). |
Transfers the contents of one list to another, by appending them. This is faster than moving items one by one, as it simply manipulates the list references for the first and last item. Thus this is a constant-time algorithm.
dst | Destination list to which to append all items in src . |
src | Source list, from which to append all items to the end of dst . Afterwards, the src list will be empty. |
void * list_next | ( | const list_t * | list, |
const void * | object | ||
) |
Iterates through the list forward (towards the tail) by 1 object.
list | The list being iterated. |
object | The object from which the next object will be returned. This must not be NULL. |
object
in the second argument. If there are no more objects following object
, returns NULL instead. Iterating through a list forwards:
for()
loop correctly so as to avoid using a removed reference for the iteration. Grab the next item reference early, before potentially removing the current item: void * list_prev | ( | const list_t * | list, |
const void * | object | ||
) |
Iterates through the list backward (towards the head) by 1 object.
list | The list being iterated. |
object | The object from which the previous object will be returned. This must not be NULL. |
object
in the second argument. If there are no more objects preceding object
, returns NULL instead. Iterating through a list backwards:
for()
loop correctly so as to avoid using a removed reference for the iteration. Grab the next item reference early, before potentially removing the current item: void list_remove | ( | list_t * | list, |
void * | object | ||
) |
void * list_remove_head | ( | list_t * | list | ) |
Removes an object from the head (start) of the list.
This function is commonly used to empty out a list by removing all members, like this:
void * list_remove_tail | ( | list_t * | list | ) |
Removes an object from the tail (end) of the list.
This function is commonly used to empty out a list by removing all members, like this: