ubinos
edlist.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Sung Ho Park
3  Contact: ubinos.org@gmail.com
4 
5  This file is part of the itf_ubinos component of the Ubinos.
6 
7  GNU General Public License Usage
8  This file may be used under the terms of the GNU
9  General Public License version 3.0 as published by the Free Software
10  Foundation and appearing in the file license_gpl3.txt included in the
11  packaging of this file. Please review the following information to
12  ensure the GNU General Public License version 3.0 requirements will be
13  met: http://www.gnu.org/copyleft/gpl.html.
14 
15  GNU Lesser General Public License Usage
16  Alternatively, this file may be used under the terms of the GNU Lesser
17  General Public License version 2.1 as published by the Free Software
18  Foundation and appearing in the file license_lgpl.txt included in the
19  packaging of this file. Please review the following information to
20  ensure the GNU Lesser General Public License version 2.1 requirements
21  will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 
23  Commercial Usage
24  Alternatively, licensees holding valid commercial licenses may
25  use this file in accordance with the commercial license agreement
26  provided with the software or, alternatively, in accordance with the
27  terms contained in a written agreement between you and rightful owner.
28  */
29 
30 #ifndef UBICLIB_EDLIST_H_
31 #define UBICLIB_EDLIST_H_
32 
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
46 #include <ubinos_config.h>
47 #include <ubinos/type.h>
48 
50 typedef struct _edlist_t
51 {
52  unsigned int count;
53  void * head;
54  void * tail;
55  void * cur;
56  void * data;
57 } edlist_t;
58 
66 typedef edlist_t * edlist_pt;
67 
69 typedef struct _edlist_elmt_t
70 {
71  struct
72  {
73  struct _edlist_elmt_t * prev;
74  struct _edlist_elmt_t * next;
75  edlist_t * list;
76  } link;
78  void * data;
80 
89 
95 #define edlist_init(edlist) \
96 { \
97  (edlist)->count = 0; \
98  (edlist)->head = NULL; \
99  (edlist)->tail = NULL; \
100  (edlist)->cur = NULL; \
101  (edlist)->data = NULL; \
102 }
103 
109 #define edlist_link_init(link) \
110 { \
111  (link)->prev = NULL; \
112  (link)->next = NULL; \
113  (link)->list = NULL; \
114 }
115 
130 #define edlist_insertprev(elmttype, linkname, edlist, ref, elmt) \
131 { \
132  (elmt)->linkname.next = ((elmttype) ref); \
133  \
134  if (NULL == ((elmttype) ref)) { \
135  (elmt)->linkname.prev = (edlist)->tail; \
136  (edlist)->tail = (elmt); \
137  } \
138  else { \
139  (elmt)->linkname.prev = ((elmttype) ref)->linkname.prev; \
140  ((elmttype) ref)->linkname.prev = (elmt); \
141  } \
142  \
143  if (NULL == (elmt)->linkname.prev) { \
144  (edlist)->head = (elmt); \
145  } \
146  else { \
147  (elmt)->linkname.prev->linkname.next = (elmt); \
148  } \
149  \
150  (edlist)->count++; \
151  \
152  (elmt)->linkname.list = (edlist); \
153 }
154 
169 #define edlist_insertnext(elmttype, linkname, edlist, ref, elmt) \
170 { \
171  (elmt)->linkname.prev = ((elmttype) ref); \
172  \
173  if (NULL == ((elmttype) ref)) { \
174  (elmt)->linkname.next = (edlist)->head; \
175  (edlist)->head = (elmt); \
176  } \
177  else { \
178  (elmt)->linkname.next = ((elmttype) ref)->linkname.next; \
179  ((elmttype) ref)->linkname.next = (elmt); \
180  } \
181  \
182  if (NULL == (elmt)->linkname.next) { \
183  (edlist)->tail = (elmt); \
184  } \
185  else { \
186  (elmt)->linkname.next->linkname.prev = (elmt); \
187  } \
188  \
189  (edlist)->count++; \
190  \
191  (elmt)->linkname.list = (edlist); \
192 }
193 
203 #define edlist_remove(elmttype, linkname, elmt) \
204 { \
205  if (NULL != ((elmt)->linkname.list)) { \
206  if ((elmt) == ((elmt)->linkname.list)->cur) { \
207  ((elmt)->linkname.list)->cur = (elmt)->linkname.prev; \
208  } \
209  \
210  if (NULL == (elmt)->linkname.prev) { \
211  ((elmt)->linkname.list)->head = (elmt)->linkname.next; \
212  } \
213  else { \
214  (elmt)->linkname.prev->linkname.next = (elmt)->linkname.next; \
215  } \
216  \
217  if (NULL == (elmt)->linkname.next) { \
218  ((elmt)->linkname.list)->tail = (elmt)->linkname.prev; \
219  } \
220  else { \
221  (elmt)->linkname.next->linkname.prev = (elmt)->linkname.prev; \
222  } \
223  \
224  ((elmt)->linkname.list)->count--; \
225  \
226  (elmt)->linkname.prev = NULL; \
227  (elmt)->linkname.next = NULL; \
228  (elmt)->linkname.list = NULL; \
229  } \
230 }
231 
243 void * _edlist_setcur(edlist_pt edlist, void * cur);
244 
260 #define edlist_setcur(elmttype, linkname, edlist, cur) ((elmttype) _edlist_setcur(edlist, cur))
261 
271 void * _edlist_getcur(edlist_pt edlist);
272 
286 #define edlist_getcur(elmttype, linkname, edlist) ((elmttype) _edlist_getcur(edlist))
287 
302 #define edlist_getcurnext(elmttype, linkname, edlist) \
303  ( (elmttype) \
304  ((NULL == (edlist)->cur || NULL == ((elmttype) (edlist)->cur)->linkname.next) ? \
305  _edlist_setcur((edlist), (edlist)->head) : \
306  _edlist_setcur((edlist), ((elmttype) (edlist)->cur)->linkname.next) ) )
307 
317 #define edlist_head(elmttype, linkname, edlist) ((elmttype) (edlist)->head)
318 
328 #define edlist_tail(elmttype, linkname, edlist) ((elmttype) (edlist)->tail)
329 
339 #define edlist_next(elmttype, linkname, elmt) ((elmt)->linkname.next)
340 
350 #define edlist_prev(elmttype, linkname, elmt) ((elmt)->linkname.prev)
351 
361 #define edlist_list(elmttype, linkname, elmt) ((elmt)->linkname.list)
362 
363 #ifdef __cplusplus
364 }
365 #endif
366 
367 #endif /* UBICLIB_EDLIST_H_ */
_edlist_t::tail
void * tail
Definition: edlist.h:54
_edlist_t::count
unsigned int count
Definition: edlist.h:52
_edlist_t::head
void * head
Definition: edlist.h:53
type.h
ubinos basic data type
_edlist_t::cur
void * cur
Definition: edlist.h:55
_edlist_elmt_t::link
struct _edlist_elmt_t::@0 link
edlist_elmt_pt
edlist_elmt_t * edlist_elmt_pt
Definition: edlist.h:88
_edlist_getcur
void * _edlist_getcur(edlist_pt edlist)
_edlist_t::data
void * data
Definition: edlist.h:56
edlist_pt
edlist_t * edlist_pt
Definition: edlist.h:66
_edlist_t
Definition: edlist.h:50
edlist_elmt_t
struct _edlist_elmt_t edlist_elmt_t
edlist_t
struct _edlist_t edlist_t
_edlist_setcur
void * _edlist_setcur(edlist_pt edlist, void *cur)
_edlist_elmt_t
Definition: edlist.h:69
_edlist_elmt_t::data
void * data
Definition: edlist.h:78