diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/eina/src/include/eina_clist.h | 160 |
1 files changed, 41 insertions, 119 deletions
diff --git a/libraries/eina/src/include/eina_clist.h b/libraries/eina/src/include/eina_clist.h index 68f15df..096a4b7 100644 --- a/libraries/eina/src/include/eina_clist.h +++ b/libraries/eina/src/include/eina_clist.h | |||
@@ -23,7 +23,22 @@ | |||
23 | #define __EINA_CLIST_H__ | 23 | #define __EINA_CLIST_H__ |
24 | 24 | ||
25 | /** | 25 | /** |
26 | * @addtogroup Eina_CList_Group Compact inline list | 26 | * @addtogroup Eina_Data_Types_Group Data Types |
27 | * | ||
28 | * @{ | ||
29 | */ | ||
30 | |||
31 | /** | ||
32 | * @addtogroup Eina_Containers_Group Containers | ||
33 | * | ||
34 | * @{ | ||
35 | */ | ||
36 | |||
37 | /** | ||
38 | * @defgroup Eina_CList_Group Compact List | ||
39 | * | ||
40 | * @{ | ||
41 | * | ||
27 | * @brief Eina_Clist is a compact (inline) list implementation | 42 | * @brief Eina_Clist is a compact (inline) list implementation |
28 | * | 43 | * |
29 | * Elements of this list are members of the structs stored in the list | 44 | * Elements of this list are members of the structs stored in the list |
@@ -42,9 +57,8 @@ | |||
42 | * @note There's no NULL at the end of the list, the last item points to the head. | 57 | * @note There's no NULL at the end of the list, the last item points to the head. |
43 | * | 58 | * |
44 | * @note List heads must be initialized with EINA_CLIST_INIT or by calling eina_clist_element_init | 59 | * @note List heads must be initialized with EINA_CLIST_INIT or by calling eina_clist_element_init |
45 | */ | 60 | * |
46 | 61 | * Define a list like so: | |
47 | /* Define a list like so: | ||
48 | * | 62 | * |
49 | * @code | 63 | * @code |
50 | * struct gadget | 64 | * struct gadget |
@@ -88,24 +102,6 @@ | |||
88 | */ | 102 | */ |
89 | 103 | ||
90 | /** | 104 | /** |
91 | * @addtogroup Eina_Data_Types_Group Data Types | ||
92 | * | ||
93 | * @{ | ||
94 | */ | ||
95 | |||
96 | /** | ||
97 | * @addtogroup Eina_Containers_Group Containers | ||
98 | * | ||
99 | * @{ | ||
100 | */ | ||
101 | |||
102 | /** | ||
103 | * @defgroup Eina_CList_Group Compact list | ||
104 | * | ||
105 | * @{ | ||
106 | */ | ||
107 | |||
108 | /** | ||
109 | * @typedef Eina_Clist | 105 | * @typedef Eina_Clist |
110 | * This is the list head and the list entry. | 106 | * This is the list head and the list entry. |
111 | * @since 1.1.0 | 107 | * @since 1.1.0 |
@@ -135,13 +131,7 @@ struct _Eina_Clist | |||
135 | * @note There's no need to initialize an element before adding it to the list. | 131 | * @note There's no need to initialize an element before adding it to the list. |
136 | * @since 1.1.0 | 132 | * @since 1.1.0 |
137 | */ | 133 | */ |
138 | static inline void eina_clist_add_after(Eina_Clist *elem, Eina_Clist *to_add) | 134 | static inline void eina_clist_add_after(Eina_Clist *elem, Eina_Clist *to_add); |
139 | { | ||
140 | to_add->next = elem->next; | ||
141 | to_add->prev = elem; | ||
142 | elem->next->prev = to_add; | ||
143 | elem->next = to_add; | ||
144 | } | ||
145 | 135 | ||
146 | /** | 136 | /** |
147 | * Add an element before the specified one. | 137 | * Add an element before the specified one. |
@@ -154,13 +144,7 @@ static inline void eina_clist_add_after(Eina_Clist *elem, Eina_Clist *to_add) | |||
154 | * @note There's no need to initialize an element before adding it to the list. | 144 | * @note There's no need to initialize an element before adding it to the list. |
155 | * @since 1.1.0 | 145 | * @since 1.1.0 |
156 | */ | 146 | */ |
157 | static inline void eina_clist_add_before(Eina_Clist *elem, Eina_Clist *to_add) | 147 | static inline void eina_clist_add_before(Eina_Clist *elem, Eina_Clist *to_add); |
158 | { | ||
159 | to_add->next = elem; | ||
160 | to_add->prev = elem->prev; | ||
161 | elem->prev->next = to_add; | ||
162 | elem->prev = to_add; | ||
163 | } | ||
164 | 148 | ||
165 | /** | 149 | /** |
166 | * Add element at the head of the list. | 150 | * Add element at the head of the list. |
@@ -173,10 +157,7 @@ static inline void eina_clist_add_before(Eina_Clist *elem, Eina_Clist *to_add) | |||
173 | * @note There's no need to initialize an element before adding it to the list. | 157 | * @note There's no need to initialize an element before adding it to the list. |
174 | * @since 1.1.0 | 158 | * @since 1.1.0 |
175 | */ | 159 | */ |
176 | static inline void eina_clist_add_head(Eina_Clist *list, Eina_Clist *elem) | 160 | static inline void eina_clist_add_head(Eina_Clist *list, Eina_Clist *elem); |
177 | { | ||
178 | eina_clist_add_after(list, elem); | ||
179 | } | ||
180 | 161 | ||
181 | /** | 162 | /** |
182 | * Add element at the tail of the list. | 163 | * Add element at the tail of the list. |
@@ -189,10 +170,7 @@ static inline void eina_clist_add_head(Eina_Clist *list, Eina_Clist *elem) | |||
189 | * @note There's no need to initialize an element before adding it to the list. | 170 | * @note There's no need to initialize an element before adding it to the list. |
190 | * @since 1.1.0 | 171 | * @since 1.1.0 |
191 | */ | 172 | */ |
192 | static inline void eina_clist_add_tail(Eina_Clist *list, Eina_Clist *elem) | 173 | static inline void eina_clist_add_tail(Eina_Clist *list, Eina_Clist *elem); |
193 | { | ||
194 | eina_clist_add_before(list, elem); | ||
195 | } | ||
196 | 174 | ||
197 | /** | 175 | /** |
198 | * Init an (unlinked) element. | 176 | * Init an (unlinked) element. |
@@ -207,11 +185,7 @@ static inline void eina_clist_add_tail(Eina_Clist *list, Eina_Clist *elem) | |||
207 | * @note It is not necessary to call this before adding an element to this list. | 185 | * @note It is not necessary to call this before adding an element to this list. |
208 | * @since 1.1.0 | 186 | * @since 1.1.0 |
209 | */ | 187 | */ |
210 | static inline void eina_clist_element_init(Eina_Clist *elem) | 188 | static inline void eina_clist_element_init(Eina_Clist *elem); |
211 | { | ||
212 | elem->next = NULL; | ||
213 | elem->prev = NULL; | ||
214 | } | ||
215 | 189 | ||
216 | /** | 190 | /** |
217 | * Check if an element is in a list or not. | 191 | * Check if an element is in a list or not. |
@@ -222,10 +196,7 @@ static inline void eina_clist_element_init(Eina_Clist *elem) | |||
222 | * it has been added to a list or remove from a list. | 196 | * it has been added to a list or remove from a list. |
223 | * @since 1.1.0 | 197 | * @since 1.1.0 |
224 | */ | 198 | */ |
225 | static inline int eina_clist_element_is_linked(Eina_Clist *elem) | 199 | static inline int eina_clist_element_is_linked(Eina_Clist *elem); |
226 | { | ||
227 | return (elem->next != NULL && elem->prev != NULL); | ||
228 | } | ||
229 | 200 | ||
230 | /** | 201 | /** |
231 | * Remove an element from its list. | 202 | * Remove an element from its list. |
@@ -235,12 +206,7 @@ static inline int eina_clist_element_is_linked(Eina_Clist *elem) | |||
235 | * @post The element is marked as not being in any list | 206 | * @post The element is marked as not being in any list |
236 | * @since 1.1.0 | 207 | * @since 1.1.0 |
237 | */ | 208 | */ |
238 | static inline void eina_clist_remove(Eina_Clist *elem) | 209 | static inline void eina_clist_remove(Eina_Clist *elem); |
239 | { | ||
240 | elem->next->prev = elem->prev; | ||
241 | elem->prev->next = elem->next; | ||
242 | eina_clist_element_init(elem); | ||
243 | } | ||
244 | 210 | ||
245 | /** | 211 | /** |
246 | * Get the next element. | 212 | * Get the next element. |
@@ -248,15 +214,10 @@ static inline void eina_clist_remove(Eina_Clist *elem) | |||
248 | * @param list The list | 214 | * @param list The list |
249 | * @param elem An element | 215 | * @param elem An element |
250 | * @pre @a elem is in @a list | 216 | * @pre @a elem is in @a list |
251 | * @return The element after @elem in @list or NULL if @a elem is last in @a list | 217 | * @return The element after @a elem in @a list or @c NULL if @a elem is last in @a list |
252 | * @since 1.1.0 | 218 | * @since 1.1.0 |
253 | */ | 219 | */ |
254 | static inline Eina_Clist *eina_clist_next(const Eina_Clist *list, const Eina_Clist *elem) | 220 | static inline Eina_Clist *eina_clist_next(const Eina_Clist *list, const Eina_Clist *elem); |
255 | { | ||
256 | Eina_Clist *ret = elem->next; | ||
257 | if (elem->next == list) ret = NULL; | ||
258 | return ret; | ||
259 | } | ||
260 | 221 | ||
261 | /** | 222 | /** |
262 | * Get the previous element. | 223 | * Get the previous element. |
@@ -267,12 +228,7 @@ static inline Eina_Clist *eina_clist_next(const Eina_Clist *list, const Eina_Cli | |||
267 | * @return The element before @a elem or NULL if @a elem is the first in the list | 228 | * @return The element before @a elem or NULL if @a elem is the first in the list |
268 | * @since 1.1.0 | 229 | * @since 1.1.0 |
269 | */ | 230 | */ |
270 | static inline Eina_Clist *eina_clist_prev(const Eina_Clist *list, const Eina_Clist *elem) | 231 | static inline Eina_Clist *eina_clist_prev(const Eina_Clist *list, const Eina_Clist *elem); |
271 | { | ||
272 | Eina_Clist *ret = elem->prev; | ||
273 | if (elem->prev == list) ret = NULL; | ||
274 | return ret; | ||
275 | } | ||
276 | 232 | ||
277 | /** | 233 | /** |
278 | * Get the first element. | 234 | * Get the first element. |
@@ -281,22 +237,16 @@ static inline Eina_Clist *eina_clist_prev(const Eina_Clist *list, const Eina_Cli | |||
281 | * @returns The first element in @a list or NULL if @a list is empty | 237 | * @returns The first element in @a list or NULL if @a list is empty |
282 | * @since 1.1.0 | 238 | * @since 1.1.0 |
283 | */ | 239 | */ |
284 | static inline Eina_Clist *eina_clist_head(const Eina_Clist *list) | 240 | static inline Eina_Clist *eina_clist_head(const Eina_Clist *list); |
285 | { | ||
286 | return eina_clist_next(list, list); | ||
287 | } | ||
288 | 241 | ||
289 | /** | 242 | /** |
290 | * Get the last element. | 243 | * Get the last element. |
291 | * | 244 | * |
292 | * @param list The list | 245 | * @param list The list |
293 | * @returns The last element in @a list or NULL if @list is empty | 246 | * @returns The last element in @a list or NULL if @a list is empty |
294 | * @since 1.1.0 | 247 | * @since 1.1.0 |
295 | */ | 248 | */ |
296 | static inline Eina_Clist *eina_clist_tail(const Eina_Clist *list) | 249 | static inline Eina_Clist *eina_clist_tail(const Eina_Clist *list); |
297 | { | ||
298 | return eina_clist_prev(list, list); | ||
299 | } | ||
300 | 250 | ||
301 | /** | 251 | /** |
302 | * Check if a list is empty. | 252 | * Check if a list is empty. |
@@ -305,10 +255,7 @@ static inline Eina_Clist *eina_clist_tail(const Eina_Clist *list) | |||
305 | * @returns non-zero if @a list is empty, zero if it is not | 255 | * @returns non-zero if @a list is empty, zero if it is not |
306 | * @since 1.1.0 | 256 | * @since 1.1.0 |
307 | */ | 257 | */ |
308 | static inline int eina_clist_empty(const Eina_Clist *list) | 258 | static inline int eina_clist_empty(const Eina_Clist *list); |
309 | { | ||
310 | return list->next == list; | ||
311 | } | ||
312 | 259 | ||
313 | /** | 260 | /** |
314 | * Initialize a list | 261 | * Initialize a list |
@@ -322,10 +269,7 @@ static inline int eina_clist_empty(const Eina_Clist *list) | |||
322 | * initialize the list by zero'ing out the list head. | 269 | * initialize the list by zero'ing out the list head. |
323 | * @since 1.1.0 | 270 | * @since 1.1.0 |
324 | */ | 271 | */ |
325 | static inline void eina_clist_init(Eina_Clist *list) | 272 | static inline void eina_clist_init(Eina_Clist *list); |
326 | { | ||
327 | list->next = list->prev = list; | ||
328 | } | ||
329 | 273 | ||
330 | /** | 274 | /** |
331 | * Count the elements of a list | 275 | * Count the elements of a list |
@@ -334,13 +278,7 @@ static inline void eina_clist_init(Eina_Clist *list) | |||
334 | * @returns The number of items in the list | 278 | * @returns The number of items in the list |
335 | * @since 1.1.0 | 279 | * @since 1.1.0 |
336 | */ | 280 | */ |
337 | static inline unsigned int eina_clist_count(const Eina_Clist *list) | 281 | static inline unsigned int eina_clist_count(const Eina_Clist *list); |
338 | { | ||
339 | unsigned count = 0; | ||
340 | const Eina_Clist *ptr; | ||
341 | for (ptr = list->next; ptr != list; ptr = ptr->next) count++; | ||
342 | return count; | ||
343 | } | ||
344 | 282 | ||
345 | /** | 283 | /** |
346 | * Move all elements from src to the tail of dst | 284 | * Move all elements from src to the tail of dst |
@@ -351,16 +289,7 @@ static inline unsigned int eina_clist_count(const Eina_Clist *list) | |||
351 | * @post @a src is initialized but empty after this operation | 289 | * @post @a src is initialized but empty after this operation |
352 | * @since 1.1.0 | 290 | * @since 1.1.0 |
353 | */ | 291 | */ |
354 | static inline void eina_clist_move_tail(Eina_Clist *dst, Eina_Clist *src) | 292 | static inline void eina_clist_move_tail(Eina_Clist *dst, Eina_Clist *src); |
355 | { | ||
356 | if (eina_clist_empty(src)) return; | ||
357 | |||
358 | dst->prev->next = src->next; | ||
359 | src->next->prev = dst->prev; | ||
360 | dst->prev = src->prev; | ||
361 | src->prev->next = dst; | ||
362 | eina_clist_init(src); | ||
363 | } | ||
364 | 293 | ||
365 | /** | 294 | /** |
366 | * move all elements from src to the head of dst | 295 | * move all elements from src to the head of dst |
@@ -371,16 +300,7 @@ static inline void eina_clist_move_tail(Eina_Clist *dst, Eina_Clist *src) | |||
371 | * @post @a src is initialized but empty after this operation | 300 | * @post @a src is initialized but empty after this operation |
372 | * @since 1.1.0 | 301 | * @since 1.1.0 |
373 | */ | 302 | */ |
374 | static inline void eina_clist_move_head(Eina_Clist *dst, Eina_Clist *src) | 303 | static inline void eina_clist_move_head(Eina_Clist *dst, Eina_Clist *src); |
375 | { | ||
376 | if (eina_clist_empty(src)) return; | ||
377 | |||
378 | dst->next->prev = src->prev; | ||
379 | src->prev->next = dst->next; | ||
380 | dst->next = src->next; | ||
381 | src->next->prev = dst; | ||
382 | eina_clist_init(src); | ||
383 | } | ||
384 | 304 | ||
385 | /** | 305 | /** |
386 | * iterate through the list | 306 | * iterate through the list |
@@ -441,15 +361,17 @@ static inline void eina_clist_move_head(Eina_Clist *dst, Eina_Clist *src) | |||
441 | #define EINA_CLIST_ENTRY(elem, type, field) \ | 361 | #define EINA_CLIST_ENTRY(elem, type, field) \ |
442 | ((type *)((char *)(elem) - (unsigned long)(&((type *)0)->field))) | 362 | ((type *)((char *)(elem) - (unsigned long)(&((type *)0)->field))) |
443 | 363 | ||
444 | /* | 364 | #include "eina_inline_clist.x" |
365 | |||
366 | /** | ||
445 | * @} | 367 | * @} |
446 | */ | 368 | */ |
447 | 369 | ||
448 | /* | 370 | /** |
449 | * @} | 371 | * @} |
450 | */ | 372 | */ |
451 | 373 | ||
452 | /* | 374 | /** |
453 | * @} | 375 | * @} |
454 | */ | 376 | */ |
455 | 377 | ||