Data Structures | |
| struct | _GGZListEntry |
| A single entry in a GGZList. More... | |
| struct | _GGZList |
| Simple doubly-linked list. More... | |
Defines | |
| #define | GGZ_LIST_REPLACE_DUPS 0x00 |
| Overwrite duplicate values on insert. | |
| #define | GGZ_LIST_ALLOW_DUPS 0x01 |
| Allow duplicate data entries to exist in the list. | |
Typedefs | |
| typedef int(*) | ggzEntryCompare (const void *a, const void *b) |
| A function type for doing data comparison on two items in a GGZList. | |
| typedef void *(*) | ggzEntryCreate (void *data) |
| A function type for creating a copy of a data item for insertion into a GGZList. | |
| typedef void(*) | ggzEntryDestroy (void *data) |
| A function type to destroy an entry in a GGZList. | |
| typedef _GGZListEntry | GGZListEntry |
| A single entry in a GGZList. | |
| typedef _GGZList | GGZList |
| Simple doubly-linked list. | |
Functions | |
| GGZList * | ggz_list_create (ggzEntryCompare compare_func, ggzEntryCreate create_func, ggzEntryDestroy destroy_func, int options) |
| Create a new GGZList. | |
| int | ggz_list_insert (GGZList *list, void *data) |
| Insert data into a list. | |
| GGZListEntry * | ggz_list_head (GGZList *list) |
| Get the first node of a list. | |
| GGZListEntry * | ggz_list_tail (GGZList *list) |
| Get the last node of a list. | |
| GGZListEntry * | ggz_list_next (GGZListEntry *entry) |
| Get the next node of a list. | |
| GGZListEntry * | ggz_list_prev (GGZListEntry *entry) |
| Get the previous node of a list. | |
| void * | ggz_list_get_data (GGZListEntry *entry) |
| Retrieve the data stored in a list entry. | |
| GGZListEntry * | ggz_list_search (GGZList *list, void *data) |
| Search for a specified data item in the list. | |
| GGZListEntry * | ggz_list_search_alt (GGZList *list, void *data, ggzEntryCompare compare_func) |
| Search for a specified data item in the list using a provided comparison function. | |
| void | ggz_list_delete_entry (GGZList *list, GGZListEntry *entry) |
| Removes an entry from a list, calling a destructor if registered. | |
| void | ggz_list_free (GGZList *list) |
| Free all resources associated with a list. | |
| int | ggz_list_count (GGZList *list) |
| Get the length of the list. | |
| int | ggz_list_compare_str (void *a, void *b) |
| Compare two character strings. | |
| void * | ggz_list_create_str (void *data) |
| Copy a character string. | |
| void | ggz_list_destroy_str (void *data) |
| Free a character string. | |
| typedef int(*) ggzEntryCompare(const void *a, const void *b) |
| typedef void*(*) ggzEntryCreate(void *data) |
A function type for creating a copy of a data item for insertion into a GGZList.
A function of this type may be called on an element when it is first inserted into a GGZList.
| data | A pointer to the data given to the list for insertion |
| typedef void(*) ggzEntryDestroy(void *data) |
| typedef struct _GGZListEntry GGZListEntry |
A single entry in a GGZList.
Do not access these members directly, but use the ggz_list_get_data(), ggz_list_next() and ggz_list_prev() accessor functions instead.
Simple doubly-linked list.
Do not access these members directly. Instead use accessor functions.
| GGZList* ggz_list_create | ( | ggzEntryCompare | compare_func, | |
| ggzEntryCreate | create_func, | |||
| ggzEntryDestroy | destroy_func, | |||
| int | options | |||
| ) |
Create a new GGZList.
When creating a a new list, you have some control over its behavior. The first parameter, compare_func allows you to specify a comparison for sorting the list elements. If you specify NULL for compare_func, the list will be unordered. The second parameter, create_func allows you to specify how new copies of data will be created during insertion. GGZList objects stores pointers to your data in GGZListEntry nodes. If you specify NULL for create_func, the list will store the actual pointer to your data when you call ggz_list_insert(). If you specify a create_func, it will be called to create a new copy of the object for storage in the list. You are then safely deallocate the original copy of the data. The third parameter, destroy_func allows you to specify a deallocation function for data entries when they are removed from the list.
| compare_func | Function to use for comparing data items | |
| create_func | Function to use for allocating and copying data items | |
| destroy_func | Function to use for dellocating data items | |
| options | One of GGZ_LIST_REPLACE_DUPS or GGZ_LIST_ALLOW_DUPS specifying how the list should handle duplicate data entries |
| int ggz_list_insert | ( | GGZList * | list, | |
| void * | data | |||
| ) |
Insert data into a list.
| list | Pointer to a GGZList | |
| data | Pointer to data to be inserted |
| GGZListEntry* ggz_list_head | ( | GGZList * | list | ) |
Get the first node of a list.
| list | Pointer to a GGZList |
| GGZListEntry* ggz_list_tail | ( | GGZList * | list | ) |
Get the last node of a list.
| list | Pointer to a GGZList |
| GGZListEntry* ggz_list_next | ( | GGZListEntry * | entry | ) |
Get the next node of a list.
| entry | Pointer to a GGZListEntry in a GGZList |
| GGZListEntry* ggz_list_prev | ( | GGZListEntry * | entry | ) |
Get the previous node of a list.
| entry | Pointer to a GGZListEntry in a GGZList |
| void* ggz_list_get_data | ( | GGZListEntry * | entry | ) |
Retrieve the data stored in a list entry.
| entry | Pointer to a GGZListEntry |
| GGZListEntry* ggz_list_search | ( | GGZList * | list, | |
| void * | data | |||
| ) |
Search for a specified data item in the list.
ggz_list_search() searches a list for a particular data item using the ggzEntryCompare function provided as compare_func to ggz_list_create(). If you wish to search using an alternative comparison function, see ggz_list_search_alt().
| list | Pointer to a GGZList | |
| data | Pointer to data to search for |
| GGZListEntry* ggz_list_search_alt | ( | GGZList * | list, | |
| void * | data, | |||
| ggzEntryCompare | compare_func | |||
| ) |
Search for a specified data item in the list using a provided comparison function.
ggz_list_search_alt() searches a list for a particular data item using the passed ggzEntryCompare function.
| list | Pointer to a GGZList | |
| data | Pointer to data to search for | |
| compare_func | Comparison function |
| void ggz_list_delete_entry | ( | GGZList * | list, | |
| GGZListEntry * | entry | |||
| ) |
Removes an entry from a list, calling a destructor if registered.
ggz_list_delete_entry() removes the specifed entry from the list. If a ggzEntryDestroy function was passed as destroy_func to ggz_list_create(), it will be called on the data item after it has been removed.
| list | Pointer to a GGZList | |
| entry | Pointer to the GGZListEntry to remove |
| void ggz_list_free | ( | GGZList * | list | ) |
Free all resources associated with a list.
ggz_list_free() will free all resources allocated by the list. If a ggzEntryDestroy function was passed as destroy_func to ggz_list_create(), it will be called on all data items in the list as well.
| list | Pointer to a GGZList |
| int ggz_list_count | ( | GGZList * | list | ) |
Get the length of the list.
| list | Pointer to a GGZList |
| int ggz_list_compare_str | ( | void * | a, | |
| void * | b | |||
| ) |
Compare two character strings.
This function is intended to be passed as the compare_func of ggz_list_create() when creating a list that stores character strings.
| a | A string to compare | |
| b | A second string to compare |
| void* ggz_list_create_str | ( | void * | data | ) |
Copy a character string.
This function is intended to be passed as the create_func of ggz_list_create() when creating a list that stores character strings.
| data | A string to copy |
| void ggz_list_destroy_str | ( | void * | data | ) |
Free a character string.
This function is intended to be passed as the destroy_func of ggz_list_create() when creating a list that stores character strings.
| data | The string to deallocate |
1.5.1