Defines the SMFList_T data type and functions for a linked lists that can be iterated over in both directions. More...
#include <cmime.h>
Go to the source code of this file.
Macros | |
#define | smf_list_size(list) ((list)->size) |
#define | smf_list_head(list) ((list)->head) |
#define | smf_list_tail(list) ((list)->tail) |
#define | smf_list_is_head(elem) ((elem)->prev == NULL ? 1 : 0) |
#define | smf_list_is_tail(elem) ((elem)->next == NULL ? 1 : 0) |
#define | smf_list_data(elem) ((elem)->data) |
#define | smf_list_next(elem) ((elem)->next) |
#define | smf_list_prev(elem) ((elem)->prev) |
Typedefs | |
typedef CMimeListElem_T | SMFListElem_T |
An element of a SMFList_T list. | |
typedef CMimeList_T | SMFList_T |
Double linked list implementation. | |
Functions | |
int | smf_list_new (SMFList_T **list, void(*destroy)(void *data)) |
Creates a new SMFList_T list. | |
int | smf_list_free (SMFList_T *list) |
Free a SMFList_T list. | |
int | smf_list_remove (SMFList_T *list, SMFListElem_T *elem, void **data) |
Remove an element from list. | |
int | smf_list_append (SMFList_T *list, void *data) |
Append data to the end of a list. | |
int | smf_list_prepend (SMFList_T *list, void *data) |
Prepend data to a list. | |
void * | smf_list_pop_tail (SMFList_T *list) |
Remove tail element from list and return data pointer. | |
void * | smf_list_pop_head (SMFList_T *list) |
Remove head element from list an return data pointer. | |
int | smf_list_insert_next (SMFList_T *list, SMFListElem_T *elem, void *data) |
Insert new element next to elem. | |
int | smf_list_insert_prev (SMFList_T *list, SMFListElem_T *elem, void *data) |
Insert new element previous to elem. | |
void | smf_list_map (SMFList_T *list, void(*func)(SMFListElem_T *elem, void *args), void *args) |
Iterates over list and calls function for every element with the current element. | |
int | smf_list_map_new (SMFList_T *list, SMFList_T **new, void *(*func)(SMFListElem_T *elem, void *args), void *args) |
Iterates over list and calls function func with every element, return value of func will be saved in new list **new. | |
Defines the SMFList_T data type and functions for a linked lists that can be iterated over in both directions.
Each element in the list contains a piece of data, together with pointers which link to the previous and next elements in the list. Using these pointers it is possible to move through the list in both directions.
To create a new SMFList_T, use smf_list_new()
To insert an element into a SMFList_T, use smf_list_append()
To remove an element, use smf_list_remove()
To destroy a SMFList_T use smf_list_free()
#define smf_list_data | ( | elem | ) | ((elem)->data) |
#define smf_list_head | ( | list | ) | ((list)->head) |
#define smf_list_is_head | ( | elem | ) | ((elem)->prev == NULL ? 1 : 0) |
#define smf_list_is_tail | ( | elem | ) | ((elem)->next == NULL ? 1 : 0) |
#define smf_list_next | ( | elem | ) | ((elem)->next) |
#define smf_list_prev | ( | elem | ) | ((elem)->prev) |
#define smf_list_size | ( | list | ) | ((list)->size) |
#define smf_list_tail | ( | list | ) | ((list)->tail) |
int smf_list_append | ( | SMFList_T * | list, |
void * | data | ||
) |
Append data to the end of a list.
list | SMFList_T list to which new data should be appended |
data | new data which should be appended |
int smf_list_free | ( | SMFList_T * | list | ) |
Free a SMFList_T list.
list | list to free |
int smf_list_insert_next | ( | SMFList_T * | list, |
SMFListElem_T * | elem, | ||
void * | data | ||
) |
Insert new element next to elem.
list | a SMFList_T list |
elem | a SMFListElem_T element |
data | data to insert next to element |
int smf_list_insert_prev | ( | SMFList_T * | list, |
SMFListElem_T * | elem, | ||
void * | data | ||
) |
Insert new element previous to elem.
list | a SMFList_T list |
elem | a SMFListElem_T element |
data | data to insert previous to element |
void smf_list_map | ( | SMFList_T * | list, |
void(*)(SMFListElem_T *elem, void *args) | func, | ||
void * | args | ||
) |
Iterates over list and calls function for every element with the current element.
list | a SMFList_T list |
func | function to call for each element |
args | optional arguments for function pointer |
int smf_list_map_new | ( | SMFList_T * | list, |
SMFList_T ** | new, | ||
void *(*)(SMFListElem_T *elem, void *args) | func, | ||
void * | args | ||
) |
Iterates over list and calls function func with every element, return value of func will be saved in new list **new.
list | a SMFList_T list |
new | out param to return the new list |
func | function to call for each element |
args | optional arguments for function pointer returns 0 on sucess or -1 in case of error |
int smf_list_new | ( | SMFList_T ** | list, |
void(*)(void *data) | destroy | ||
) |
Creates a new SMFList_T list.
list | out param to return the new list |
destroy | list destroy function |
void* smf_list_pop_head | ( | SMFList_T * | list | ) |
Remove head element from list an return data pointer.
list | a SMFList_T list |
void* smf_list_pop_tail | ( | SMFList_T * | list | ) |
Remove tail element from list and return data pointer.
list | a SMFList_T list |
int smf_list_prepend | ( | SMFList_T * | list, |
void * | data | ||
) |
Prepend data to a list.
list | a SMFList_T list to which new data should be prepended |
data | new data which should be appended |
int smf_list_remove | ( | SMFList_T * | list, |
SMFListElem_T * | elem, | ||
void ** | data | ||
) |
Remove an element from list.
list | a SMFList_T list |
elem | the SMFListElem_T element which should be removed |
data | out param to return element data |