diff options
Diffstat (limited to 'libraries/eina/src/include/eina_inline_clist.x')
-rw-r--r-- | libraries/eina/src/include/eina_inline_clist.x | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/libraries/eina/src/include/eina_inline_clist.x b/libraries/eina/src/include/eina_inline_clist.x new file mode 100644 index 0000000..66223fe --- /dev/null +++ b/libraries/eina/src/include/eina_inline_clist.x | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | * Linked lists support | ||
3 | * | ||
4 | * Copyright (C) 2002 Alexandre Julliard | ||
5 | * Copyright (C) 2011 Mike McCormack (adapted for Eina) | ||
6 | * | ||
7 | * This library is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU Lesser General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2.1 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
20 | */ | ||
21 | |||
22 | #ifndef __EINA_CLIST_INLINE_H__ | ||
23 | #define __EINA_CLIST_INLINE_H__ | ||
24 | |||
25 | #include <stddef.h> | ||
26 | |||
27 | static inline void eina_clist_add_after(Eina_Clist *elem, Eina_Clist *to_add) | ||
28 | { | ||
29 | to_add->next = elem->next; | ||
30 | to_add->prev = elem; | ||
31 | elem->next->prev = to_add; | ||
32 | elem->next = to_add; | ||
33 | } | ||
34 | |||
35 | static inline void eina_clist_add_before(Eina_Clist *elem, Eina_Clist *to_add) | ||
36 | { | ||
37 | to_add->next = elem; | ||
38 | to_add->prev = elem->prev; | ||
39 | elem->prev->next = to_add; | ||
40 | elem->prev = to_add; | ||
41 | } | ||
42 | |||
43 | static inline void eina_clist_add_head(Eina_Clist *list, Eina_Clist *elem) | ||
44 | { | ||
45 | eina_clist_add_after(list, elem); | ||
46 | } | ||
47 | |||
48 | static inline void eina_clist_add_tail(Eina_Clist *list, Eina_Clist *elem) | ||
49 | { | ||
50 | eina_clist_add_before(list, elem); | ||
51 | } | ||
52 | |||
53 | static inline void eina_clist_element_init(Eina_Clist *elem) | ||
54 | { | ||
55 | elem->next = NULL; | ||
56 | elem->prev = NULL; | ||
57 | } | ||
58 | |||
59 | static inline int eina_clist_element_is_linked(Eina_Clist *elem) | ||
60 | { | ||
61 | return (elem->next != NULL && elem->prev != NULL); | ||
62 | } | ||
63 | |||
64 | static inline void eina_clist_remove(Eina_Clist *elem) | ||
65 | { | ||
66 | elem->next->prev = elem->prev; | ||
67 | elem->prev->next = elem->next; | ||
68 | eina_clist_element_init(elem); | ||
69 | } | ||
70 | |||
71 | static inline Eina_Clist *eina_clist_next(const Eina_Clist *list, const Eina_Clist *elem) | ||
72 | { | ||
73 | Eina_Clist *ret = elem->next; | ||
74 | if (elem->next == list) ret = NULL; | ||
75 | return ret; | ||
76 | } | ||
77 | |||
78 | static inline Eina_Clist *eina_clist_prev(const Eina_Clist *list, const Eina_Clist *elem) | ||
79 | { | ||
80 | Eina_Clist *ret = elem->prev; | ||
81 | if (elem->prev == list) ret = NULL; | ||
82 | return ret; | ||
83 | } | ||
84 | |||
85 | static inline Eina_Clist *eina_clist_head(const Eina_Clist *list) | ||
86 | { | ||
87 | return eina_clist_next(list, list); | ||
88 | } | ||
89 | |||
90 | static inline Eina_Clist *eina_clist_tail(const Eina_Clist *list) | ||
91 | { | ||
92 | return eina_clist_prev(list, list); | ||
93 | } | ||
94 | |||
95 | static inline int eina_clist_empty(const Eina_Clist *list) | ||
96 | { | ||
97 | return list->next == list; | ||
98 | } | ||
99 | |||
100 | static inline void eina_clist_init(Eina_Clist *list) | ||
101 | { | ||
102 | list->next = list->prev = list; | ||
103 | } | ||
104 | |||
105 | static inline unsigned int eina_clist_count(const Eina_Clist *list) | ||
106 | { | ||
107 | unsigned count = 0; | ||
108 | const Eina_Clist *ptr; | ||
109 | for (ptr = list->next; ptr != list; ptr = ptr->next) count++; | ||
110 | return count; | ||
111 | } | ||
112 | |||
113 | static inline void eina_clist_move_tail(Eina_Clist *dst, Eina_Clist *src) | ||
114 | { | ||
115 | if (eina_clist_empty(src)) return; | ||
116 | |||
117 | dst->prev->next = src->next; | ||
118 | src->next->prev = dst->prev; | ||
119 | dst->prev = src->prev; | ||
120 | src->prev->next = dst; | ||
121 | eina_clist_init(src); | ||
122 | } | ||
123 | |||
124 | static inline void eina_clist_move_head(Eina_Clist *dst, Eina_Clist *src) | ||
125 | { | ||
126 | if (eina_clist_empty(src)) return; | ||
127 | |||
128 | dst->next->prev = src->prev; | ||
129 | src->prev->next = dst->next; | ||
130 | dst->next = src->next; | ||
131 | src->next->prev = dst; | ||
132 | eina_clist_init(src); | ||
133 | } | ||
134 | |||
135 | #endif | ||