]> git.sur5r.net Git - ngadmin/blob - lib/src/list.h
Lib: updated Doxygen file.
[ngadmin] / lib / src / list.h
1
2 #ifndef DEF_LIST
3 #define DEF_LIST
4
5
6 #include <stdlib.h>
7 #include <stdbool.h>
8 #include <string.h>
9
10 #ifdef MT_SAFE_LIST
11 #include <pthread.h>
12 #endif
13
14
15
16 typedef struct ListNode ListNode;
17
18 struct ListNode {
19  void* data;
20  ListNode *prev, *next;
21 };
22
23
24 typedef struct {
25  ListNode *first, *last;
26  unsigned int count;
27  #ifdef MT_SAFE_LIST
28  pthread_cond_t cond;
29  pthread_mutex_t mutex;
30  #endif
31 } List;
32
33
34
35
36 // Creates an empty list
37 List* createEmptyList (void);
38
39 // Destroys a list, and eventually frees the elements
40 // NOT MT SAFE
41 void destroyList (List *l, void (*freefunc)(void*));
42
43 // Adds an element at front of the list
44 void pushFrontList (List *l, void* data);
45
46 // Adds an element at back of the list
47 void pushBackList (List *l, void* data);
48
49 // Pops an element from the front of the list and returns its value
50 void* popFrontList (List *l);
51
52 // Pops an element from the back of the list and returns its value
53 void* popBackList (List *l);
54
55 // Clears all the items of the list, and eventually frees them
56 void clearList (List *l, void (*freefunc)(void*));
57
58 // Find and destroy a particular element of the list, and eventually frees it
59 bool findAndDestroy (List *l, void* data, void (*freefunc)(void*));
60
61 // Browse all the items of the list through the callback function
62 void browseList (List *l, void (*browsefunc)(void*));
63
64 // 
65 void* convertToArray (List *l, size_t sz);
66
67
68
69
70 #endif
71