renamed TESTMODEs
[mala.git] / engine / stringlist.h
blobbd93c1844a358dda7303c0e6d395a21136ff2ca2
1 /*
2 stringlist.h - MaLa stringlists
4 Copyright (C) 2004, 2005, Christian Thaeter <chth@gmx.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, contact me.
20 #ifndef MALA_STRINGLIST_H
21 #define MALA_STRINGLIST_H
23 #include "mala_types.h"
24 #include "strings.h"
27 * StringList
30 struct mala_stringlistnode_struct
32 CIRCLEQ_ENTRY(mala_stringlistnode_struct) node;
33 MalaString string;
37 #define MALA_STATIC_STRINGLIST_INIT(args...) \
38 (const char*[]){args, NULL}
41 static inline void
42 mala_stringlist_init (MalaStringList self);
45 static inline MalaStringListNode
46 mala_stringlist_head (MalaStringList self);
48 static inline MalaStringListNode
49 mala_stringlist_tail (MalaStringList self);
51 static inline void
52 mala_stringlist_fwd (MalaStringListNode_ref self);
55 static inline void
56 mala_stringlist_rev (MalaStringListNode_ref self);
58 static inline MalaStringListNode
59 mala_stringlist_next (MalaStringListNode self);
61 static inline MalaStringListNode
62 mala_stringlist_prev (MalaStringListNode self);
64 MalaStringList
65 mala_stringlist_new ();
67 MalaStringList
68 mala_stringlist_new_cstrs (char **cstrs,
69 int nelem,
70 MalaStringBucket bucket);
72 void
73 mala_stringlist_erase (MalaStringList head);
75 void
76 mala_stringlist_free (MalaStringList head);
78 void *
79 mala_stringlist_factory (MalaStringList_ref dest, char** src, MalaStringBucket bucket);
81 MalaStringListNode
82 mala_stringlist_head_new (MalaStringList head, MalaString str);
84 MalaStringListNode
85 mala_stringlist_tail_new (MalaStringList head, MalaString str);
87 MalaStringListNode
88 mala_stringlist_head_new_cstr (MalaStringList head, const char * cstr, MalaStringBucket bucket);
90 MalaStringListNode
91 mala_stringlist_tail_new_cstr (MalaStringList head, const char * cstr, MalaStringBucket bucket);
93 static inline void
94 mala_stringlist_tail_insert (MalaStringList head, MalaStringListNode self);
96 //static inline void
97 //mala_stringlist_tail_move (MalaStringList to, MalaStringList from, MalaStringListNode self);
99 MalaStringListNode
100 mala_stringlist_after_new (MalaStringList head,
101 MalaStringListNode pred,
102 MalaString str);
104 MalaStringListNode
105 mala_stringlist_before_new (MalaStringList head,
106 MalaStringListNode succ,
107 MalaString str);
110 MalaStringListNode
111 mala_stringlist_elem_remove (MalaStringList head,
112 MalaStringListNode elem);
114 void
115 mala_stringlist_elem_delete (MalaStringList head, MalaStringListNode elem);
118 mala_stringlist_char_exists (MalaStringList head, const char c);
121 static inline void
122 mala_stringlist_elem_delete_fwd (MalaStringList head, MalaStringListNode_ref elem);
124 static inline int
125 mala_stringlist_is_tail (MalaStringList head, MalaStringListNode elem);
127 static inline int
128 mala_stringlist_is_end (MalaStringList head, MalaStringListNode elem);
130 static inline int
131 mala_stringlist_is_single (MalaStringList head);
133 static inline int
134 mala_stringlist_is_empty (MalaStringList head);
136 static inline MalaStringListNode
137 mala_stringlist_node_remove (MalaStringList head, MalaStringListNode self);
141 static inline int mala_stringlist_insert_before (MalaStringList head,
142 MalaStringListNode succ,
143 MalaStringListNode elem);
144 static inline int mala_stringlist_insert_head (MalaStringList head, MalaStringListNode elem);
145 static inline int mala_stringlist_insert_tail (MalaStringList head, MalaStringListNode elem);
148 static inline int mala_stringlist_new_after (MalaStringList head,
149 MalaStringListNode pred,
150 MalaString str);
151 static inline int mala_stringlist_new_before (MalaStringList head,
152 MalaStringListNode succ,
153 MalaString str);
157 static inline MalaStringListNode mala_stringlist_head_new_cstr (MalaStringList head,
158 const char * cstr);
159 static inline MalaStringListNode mala_stringlist_tail_new_cstr (MalaStringList head,
160 const char * cstr);
165 * Inlines
167 #if 0
168 static inline void
169 mala_stringlist_insert_after (MalaStringList head,
170 MalaStringListNode pred,
171 MalaString str)
174 CIRCLEQ_INSERT_AFTER(head, TYPE *listelm, TYPE *elm, CIRCLEQ_ENTRY NAME);
177 static inline void
178 mala_stringlist_insert_before (MalaStringList head,
179 MalaStringListNode succ,
180 MalaString str)
182 CIRCLEQ_INSERT_BEFORE(CIRCLEQ_HEAD *head, TYPE *listelm, TYPE *elm, CIRCLEQ_ENTRY NAME);
184 static inline void
185 mala_stringlist_insert_head (MalaStringList head, MalaString str)
186 CIRCLEQ_INSERT_HEAD(CIRCLEQ_HEAD *head, TYPE *elm, CIRCLEQ_ENTRY NAME);
188 #endif
190 /* statics */
192 static inline void
193 mala_stringlist_elem_delete_fwd (MalaStringList head, MalaStringListNode_ref elem)
195 MalaStringListNode tmp = *elem;
196 *elem = (*elem)->node.cqe_next;
197 mala_stringlist_elem_delete (head, tmp);
200 static inline MalaStringListNode
201 mala_stringlist_node_remove (MalaStringList head, MalaStringListNode self)
203 CIRCLEQ_REMOVE (head, self, node);
204 return self;
207 static inline void
208 mala_stringlist_tail_insert (MalaStringList head, MalaStringListNode self)
210 CIRCLEQ_INSERT_TAIL (head, self, node);
214 static inline int
215 mala_stringlist_is_empty (MalaStringList head)
217 return head->cqh_first == (void *)head;
220 static inline void
221 mala_stringlist_fwd (MalaStringListNode_ref self)
223 *self = (*self)->node.cqe_next;
226 static inline void
227 mala_stringlist_rev (MalaStringListNode_ref self)
229 *self = (*self)->node.cqe_prev;
232 static inline MalaStringListNode
233 mala_stringlist_next (MalaStringListNode self)
235 return self->node.cqe_next;
238 static inline MalaStringListNode
239 mala_stringlist_prev (MalaStringListNode self)
241 return self->node.cqe_prev;
244 static inline void
245 mala_stringlist_init (MalaStringList self)
247 CIRCLEQ_INIT(self);
250 static inline MalaStringListNode
251 mala_stringlist_head (MalaStringList self)
253 return self->cqh_first;
256 static inline MalaStringListNode
257 mala_stringlist_tail (MalaStringList self)
259 return self->cqh_last;
262 static inline int
263 mala_stringlist_is_single (MalaStringList head)
265 return head->cqh_first != (void *)head && head->cqh_first->node.cqe_next == (void *)head;
268 static inline int
269 mala_stringlist_is_tail (MalaStringList head, MalaStringListNode elem)
271 return elem->node.cqe_next == (void *)head;
274 static inline int
275 mala_stringlist_is_end (MalaStringList head, MalaStringListNode elem)
277 return elem == (void *)head;
281 #endif /* MALA_STRINGLIST_H */
284 // Local Variables:
285 // mode: C
286 // c-file-style: "gnu"
287 // End:
288 // arch-tag: 44b2b6d9-80b8-43fa-938a-a492bd52cea2
289 // end_of_file