libcmime  
A lightweight C mime library
Data Structures | Macros | Functions
cmime_list.h File Reference

Defines functions and structs for double linked list. More...

#include <stdlib.h>
#include <string.h>
#include <assert.h>
Include dependency graph for cmime_list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CMimeListElem_T
 An element of a CMimeList_T list. More...
 
struct  CMimeList_T
 Double linked list implementation. More...
 

Macros

#define cmime_list_size(list)   ((list)->size)
 
#define cmime_list_head(list)   ((list)->head)
 
#define cmime_list_tail(list)   ((list)->tail)
 
#define cmime_list_is_head(elem)   ((elem)->prev == NULL ? 1 : 0)
 
#define cmime_list_is_tail(elem)   ((elem)->next == NULL ? 1 : 0)
 
#define cmime_list_data(elem)   ((elem)->data)
 
#define cmime_list_next(elem)   ((elem)->next)
 
#define cmime_list_prev(elem)   ((elem)->prev)
 

Functions

int cmime_list_new (CMimeList_T **list, void(*destroy)(void *data))
 Creates a new CMimeList_T list. More...
 
int cmime_list_free (CMimeList_T *list)
 Free a CMimeList_T list. More...
 
int cmime_list_remove (CMimeList_T *list, CMimeListElem_T *elem, void **data)
 Remove an element from list. More...
 
int cmime_list_append (CMimeList_T *list, void *data)
 Append data to the end of a list. More...
 
int cmime_list_prepend (CMimeList_T *list, void *data)
 Prepend data to a list. More...
 
void * cmime_list_pop_tail (CMimeList_T *list)
 Remove tail element from list and return data pointer. More...
 
void * cmime_list_pop_head (CMimeList_T *list)
 Remove head element from list an return data pointer. More...
 
int cmime_list_insert_next (CMimeList_T *list, CMimeListElem_T *elem, void *data)
 Insert new element next to elem. More...
 
int cmime_list_insert_prev (CMimeList_T *list, CMimeListElem_T *elem, void *data)
 Insert new element previous to elem. More...
 
void cmime_list_map (CMimeList_T *list, void(*func)(CMimeListElem_T *elem, void *args), void *args)
 Iterates over list and calls function for every element with the current element. More...
 
int cmime_list_map_new (CMimeList_T *list, CMimeList_T **new, void *(*func)(CMimeListElem_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. More...
 

Detailed Description

Defines functions and structs for double linked list.

Macro Definition Documentation

#define cmime_list_data (   elem)    ((elem)->data)
Returns
data pointer of element
Examples:
parse_mime_message.c, and save_attachment_to_file.c.
#define cmime_list_head (   list)    ((list)->head)
Returns
head element of CMimeList_T list
Examples:
parse_mime_message.c, and save_attachment_to_file.c.
#define cmime_list_is_head (   elem)    ((elem)->prev == NULL ? 1 : 0)
Returns
1 if element is list head, 0 if not
#define cmime_list_is_tail (   elem)    ((elem)->next == NULL ? 1 : 0)
Returns
1 if element is list tail, 0 if not
#define cmime_list_next (   elem)    ((elem)->next)
Returns
next element
#define cmime_list_prev (   elem)    ((elem)->prev)
Returns
previous element
#define cmime_list_size (   list)    ((list)->size)
Returns
size of CMimeList_T list
#define cmime_list_tail (   list)    ((list)->tail)
Returns
tail element of CMimeList_T list

Function Documentation

int cmime_list_append ( CMimeList_T list,
void *  data 
)

Append data to the end of a list.

Parameters
listCMimeList_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 cmime_list_free ( CMimeList_T list)

Free a CMimeList_T list.

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

Insert new element next to elem.

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

Insert new element previous to elem.

Parameters
lista CMimeList_T list
elema CMimeListElem_T element
datadata to insert previous to element
Returns
0 on sucess or -1 in case of error
void cmime_list_map ( CMimeList_T list,
void(*)(CMimeListElem_T *elem, void *args)  func,
void *  args 
)

Iterates over list and calls function for every element with the current element.

Parameters
lista CMimeList_T list
funcfunction to call for each element
argsoptional arguments for function pointer
int cmime_list_map_new ( CMimeList_T list,
CMimeList_T **  new,
void *(*)(CMimeListElem_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 CMimeList_T list
newout param to return the new list
funcfunction to call for each element
argsoptional arguments for function pointer
int cmime_list_new ( CMimeList_T **  list,
void(*)(void *data)  destroy 
)

Creates a new CMimeList_T list.

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

Remove head element from list an return data pointer.

Parameters
lista CMimeList_T list
Returns
data pointer of removed list element
void* cmime_list_pop_tail ( CMimeList_T list)

Remove tail element from list and return data pointer.

Parameters
lista CMimeList_T list
Returns
data pointer of removed list element
int cmime_list_prepend ( CMimeList_T list,
void *  data 
)

Prepend data to a list.

Parameters
lista CMimeList_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 cmime_list_remove ( CMimeList_T list,
CMimeListElem_T elem,
void **  data 
)

Remove an element from list.

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