libcmime  
A lightweight C mime library
cmime_list.h
Go to the documentation of this file.
1 /* libcmime - A C mime library
2  * Copyright (C) 2013 SpaceNet AG and Axel Steiner <ast@treibsand.com>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
29 #ifndef _CMIME_LIST_H
30 #define _CMIME_LIST_H
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <stdlib.h>
37 #include <string.h>
38 #include <stdlib.h>
39 #include <assert.h>
40 
45 typedef struct _CMimeListElem {
46  void *data;
47  struct _CMimeListElem *prev;
48  struct _CMimeListElem *next;
50 
55 typedef struct _CMimeList {
56  int size;
57  void (*destroy)(void *data);
60 } CMimeList_T;
61 
69 int cmime_list_new(CMimeList_T **list, void (*destroy)(void *data));
70 
77 int cmime_list_free(CMimeList_T *list);
78 
87 int cmime_list_remove(CMimeList_T *list, CMimeListElem_T *elem, void **data);
88 
96 int cmime_list_append(CMimeList_T *list, void *data);
97 
105 int cmime_list_prepend(CMimeList_T *list, void *data);
106 
113 void *cmime_list_pop_tail(CMimeList_T *list);
114 
121 void *cmime_list_pop_head(CMimeList_T *list);
122 
131 int cmime_list_insert_next(CMimeList_T *list, CMimeListElem_T *elem, void *data);
132 
141 int cmime_list_insert_prev(CMimeList_T *list, CMimeListElem_T *elem, void *data);
142 
150 void cmime_list_map(CMimeList_T *list, void(*func)(CMimeListElem_T *elem,void *args), void *args);
151 
160 int cmime_list_map_new(CMimeList_T *list, CMimeList_T **new_list, void *(*func)(CMimeListElem_T *elem, void *args), void *args);
161 
166 #define cmime_list_size(list) ((list)->size)
167 
172 #define cmime_list_head(list) ((list)->head)
173 
178 #define cmime_list_tail(list) ((list)->tail)
179 
184 #define cmime_list_is_head(elem) ((elem)->prev == NULL ? 1 : 0)
185 
190 #define cmime_list_is_tail(elem) ((elem)->next == NULL ? 1 : 0)
191 
196 #define cmime_list_data(elem) ((elem)->data)
197 
202 #define cmime_list_next(elem) ((elem)->next)
203 
208 #define cmime_list_prev(elem) ((elem)->prev)
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 
214 #endif /* _CMIME_LIST_H */
int cmime_list_prepend(CMimeList_T *list, void *data)
Prepend data to a list.
Definition: cmime_list.c:217
int cmime_list_map_new(CMimeList_T *list, CMimeList_T **new_list, 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 ...
Definition: cmime_list.c:236
int size
Definition: cmime_list.h:56
struct _CMimeListElem * prev
Definition: cmime_list.h:47
int cmime_list_free(CMimeList_T *list)
Free a CMimeList_T list.
Definition: cmime_list.c:45
An element of a CMimeList_T list.
Definition: cmime_list.h:45
int cmime_list_insert_prev(CMimeList_T *list, CMimeListElem_T *elem, void *data)
Insert new element previous to elem.
Definition: cmime_list.c:170
CMimeListElem_T * head
Definition: cmime_list.h:58
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. ...
Definition: cmime_list.c:224
int cmime_list_insert_next(CMimeList_T *list, CMimeListElem_T *elem, void *data)
Insert new element next to elem.
Definition: cmime_list.c:129
Double linked list implementation.
Definition: cmime_list.h:55
void * cmime_list_pop_head(CMimeList_T *list)
Remove head element from list an return data pointer.
Definition: cmime_list.c:113
CMimeListElem_T * tail
Definition: cmime_list.h:59
void * cmime_list_pop_tail(CMimeList_T *list)
Remove tail element from list and return data pointer.
Definition: cmime_list.c:98
int cmime_list_remove(CMimeList_T *list, CMimeListElem_T *elem, void **data)
Remove an element from list.
Definition: cmime_list.c:62
struct _CMimeListElem * next
Definition: cmime_list.h:48
int cmime_list_new(CMimeList_T **list, void(*destroy)(void *data))
Creates a new CMimeList_T list.
Definition: cmime_list.c:29
int cmime_list_append(CMimeList_T *list, void *data)
Append data to the end of a list.
Definition: cmime_list.c:210
void * data
Definition: cmime_list.h:46