ubinos
edlist.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Sung Ho Park
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef UBICLIB_EDLIST_H_
8 #define UBICLIB_EDLIST_H_
9 
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14 
23 #include <ubinos_config.h>
24 #include <ubinos/type.h>
25 
27 typedef struct _edlist_t
28 {
29  unsigned int count;
30  void * head;
31  void * tail;
32  void * cur;
33  void * data;
35 
43 typedef edlist_t * edlist_pt;
44 
46 typedef struct _edlist_elmt_t
47 {
48  struct
49  {
50  struct _edlist_elmt_t * prev;
51  struct _edlist_elmt_t * next;
52  edlist_t * list;
53  } link;
55  void * data;
57 
66 
72 #define edlist_init(edlist) \
73 { \
74  (edlist)->count = 0; \
75  (edlist)->head = NULL; \
76  (edlist)->tail = NULL; \
77  (edlist)->cur = NULL; \
78  (edlist)->data = NULL; \
79 }
80 
86 #define edlist_link_init(link) \
87 { \
88  (link)->prev = NULL; \
89  (link)->next = NULL; \
90  (link)->list = NULL; \
91 }
92 
107 #define edlist_insertprev(elmttype, linkname, edlist, ref, elmt) \
108 { \
109  (elmt)->linkname.next = ((elmttype) ref); \
110  \
111  if (NULL == ((elmttype) ref)) { \
112  (elmt)->linkname.prev = (edlist)->tail; \
113  (edlist)->tail = (elmt); \
114  } \
115  else { \
116  (elmt)->linkname.prev = ((elmttype) ref)->linkname.prev; \
117  ((elmttype) ref)->linkname.prev = (elmt); \
118  } \
119  \
120  if (NULL == (elmt)->linkname.prev) { \
121  (edlist)->head = (elmt); \
122  } \
123  else { \
124  (elmt)->linkname.prev->linkname.next = (elmt); \
125  } \
126  \
127  (edlist)->count++; \
128  \
129  (elmt)->linkname.list = (edlist); \
130 }
131 
146 #define edlist_insertnext(elmttype, linkname, edlist, ref, elmt) \
147 { \
148  (elmt)->linkname.prev = ((elmttype) ref); \
149  \
150  if (NULL == ((elmttype) ref)) { \
151  (elmt)->linkname.next = (edlist)->head; \
152  (edlist)->head = (elmt); \
153  } \
154  else { \
155  (elmt)->linkname.next = ((elmttype) ref)->linkname.next; \
156  ((elmttype) ref)->linkname.next = (elmt); \
157  } \
158  \
159  if (NULL == (elmt)->linkname.next) { \
160  (edlist)->tail = (elmt); \
161  } \
162  else { \
163  (elmt)->linkname.next->linkname.prev = (elmt); \
164  } \
165  \
166  (edlist)->count++; \
167  \
168  (elmt)->linkname.list = (edlist); \
169 }
170 
180 #define edlist_remove(elmttype, linkname, elmt) \
181 { \
182  if (NULL != ((elmt)->linkname.list)) { \
183  if ((elmt) == ((elmt)->linkname.list)->cur) { \
184  ((elmt)->linkname.list)->cur = (elmt)->linkname.prev; \
185  } \
186  \
187  if (NULL == (elmt)->linkname.prev) { \
188  ((elmt)->linkname.list)->head = (elmt)->linkname.next; \
189  } \
190  else { \
191  (elmt)->linkname.prev->linkname.next = (elmt)->linkname.next; \
192  } \
193  \
194  if (NULL == (elmt)->linkname.next) { \
195  ((elmt)->linkname.list)->tail = (elmt)->linkname.prev; \
196  } \
197  else { \
198  (elmt)->linkname.next->linkname.prev = (elmt)->linkname.prev; \
199  } \
200  \
201  ((elmt)->linkname.list)->count--; \
202  \
203  (elmt)->linkname.prev = NULL; \
204  (elmt)->linkname.next = NULL; \
205  (elmt)->linkname.list = NULL; \
206  } \
207 }
208 
220 void * _edlist_setcur(edlist_pt edlist, void * cur);
221 
237 #define edlist_setcur(elmttype, linkname, edlist, cur) ((elmttype) _edlist_setcur(edlist, cur))
238 
248 void * _edlist_getcur(edlist_pt edlist);
249 
263 #define edlist_getcur(elmttype, linkname, edlist) ((elmttype) _edlist_getcur(edlist))
264 
279 #define edlist_getcurnext(elmttype, linkname, edlist) \
280  ( (elmttype) \
281  ((NULL == (edlist)->cur || NULL == ((elmttype) (edlist)->cur)->linkname.next) ? \
282  _edlist_setcur((edlist), (edlist)->head) : \
283  _edlist_setcur((edlist), ((elmttype) (edlist)->cur)->linkname.next) ) )
284 
294 #define edlist_head(elmttype, linkname, edlist) ((elmttype) (edlist)->head)
295 
305 #define edlist_tail(elmttype, linkname, edlist) ((elmttype) (edlist)->tail)
306 
316 #define edlist_next(elmttype, linkname, elmt) ((elmt)->linkname.next)
317 
327 #define edlist_prev(elmttype, linkname, elmt) ((elmt)->linkname.prev)
328 
338 #define edlist_list(elmttype, linkname, elmt) ((elmt)->linkname.list)
339 
340 #ifdef __cplusplus
341 }
342 #endif
343 
344 #endif /* UBICLIB_EDLIST_H_ */
struct _edlist_t edlist_t
void * _edlist_getcur(edlist_pt edlist)
void * _edlist_setcur(edlist_pt edlist, void *cur)
struct _edlist_elmt_t edlist_elmt_t
edlist_t * edlist_pt
Definition: edlist.h:43
edlist_elmt_t * edlist_elmt_pt
Definition: edlist.h:65
Definition: edlist.h:47
struct _edlist_elmt_t::@0 link
void * data
Definition: edlist.h:55
Definition: edlist.h:28
void * tail
Definition: edlist.h:31
void * cur
Definition: edlist.h:32
void * head
Definition: edlist.h:30
void * data
Definition: edlist.h:33
unsigned int count
Definition: edlist.h:29
ubinos basic data type