smf_list.h File Reference

Defines the SMFList_T data type and functions for a linked lists that can be iterated over in both directions. More...

#include <cmime.h>
Include dependency graph for smf_list.h:
This graph shows which files directly or indirectly include this file:

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.
 

Detailed Description

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()

Macro Definition Documentation

#define smf_list_data (   elem)    ((elem)->data)
Returns
data pointer of element
#define smf_list_head (   list)    ((list)->head)
Returns
head element of SMFList_T list
#define smf_list_is_head (   elem)    ((elem)->prev == NULL ? 1 : 0)
Returns
1 if element is list head, 0 if not
#define smf_list_is_tail (   elem)    ((elem)->next == NULL ? 1 : 0)
Returns
1 if element is list tail, 0 if not
#define smf_list_next (   elem)    ((elem)->next)
Returns
next element
#define smf_list_prev (   elem)    ((elem)->prev)
Returns
previous element
#define smf_list_size (   list)    ((list)->size)
Returns
size of SMFList_T list
#define smf_list_tail (   list)    ((list)->tail)
Returns
tail element of SMFList_T list

Function Documentation

int smf_list_append ( SMFList_T list,
void *  data 
)

Append data to the end of a list.

Parameters
listSMFList_T list to which new data should be appended
datanew data which should be appended
Returns
0 on success or -1 in case of error
int smf_list_free ( SMFList_T list)

Free a SMFList_T list.

Parameters
listlist to free
Returns
0 on success or -1 in case of error
int smf_list_insert_next ( SMFList_T list,
SMFListElem_T elem,
void *  data 
)

Insert new element next to elem.

Parameters
lista SMFList_T list
elema SMFListElem_T element
datadata to insert next to element
Returns
0 on sucess or -1 in case of error
int smf_list_insert_prev ( SMFList_T list,
SMFListElem_T elem,
void *  data 
)

Insert new element previous to elem.

Parameters
lista SMFList_T list
elema SMFListElem_T element
datadata to insert previous to element
Returns
0 on sucess or -1 in case of error
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.

Parameters
lista SMFList_T list
funcfunction to call for each element
argsoptional 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.

Parameters
lista SMFList_T list
newout param to return the new list
funcfunction to call for each element
argsoptional 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.

Parameters
listout param to return the new list
destroylist destroy function
Returns
0 on success or -1 in case of error
void* smf_list_pop_head ( SMFList_T list)

Remove head element from list an return data pointer.

Parameters
lista SMFList_T list
Returns
data pointer of removed list element
void* smf_list_pop_tail ( SMFList_T list)

Remove tail element from list and return data pointer.

Parameters
lista SMFList_T list
Returns
data pointer of removed list element
int smf_list_prepend ( SMFList_T list,
void *  data 
)

Prepend data to a list.

Parameters
lista SMFList_T list to which new data should be prepended
datanew data which should be appended
Returns
0 on success or -1 in case of error
int smf_list_remove ( SMFList_T list,
SMFListElem_T elem,
void **  data 
)

Remove an element from list.

Parameters
lista SMFList_T list
elemthe SMFListElem_T element which should be removed
dataout param to return element data
Returns
0 on success or -1 in case of error