tests update
[mala.git] / engine / stringlist.h
blobfae660e0397e6cc9f3794fc1a882693b03bcb695
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 <stdio.h>
24 #include "mala_types.h"
25 #include "engine.h"
26 #include "strings.h"
27 #include "llist.h"
30 #define MALA_STATIC_STRINGLIST_INIT(args...) \
31 (const char*[]){args, NULL}
35 * StringList
38 struct mala_stringlist_struct
40 llist node;
41 MalaString string;
44 /*gc support*/
45 acogc_mark_result
46 mala_stringlist_acogc_mark (void* o);
48 void
49 mala_stringlist_acogc_initize (void * o);
51 void
52 mala_stringlist_acogc_finalize (void * o);
55 /* constructors */
56 MalaStringList
57 mala_stringlist_new (MalaEngine engine);
59 MalaStringList
60 mala_stringlist_copy (MalaStringList source, MalaEngine engine);
62 void
63 mala_stringlist_append_cstrs (MalaStringList self, int nelem, char** cstrs, MalaEngine engine);
65 void
66 mala_stringlist_append_literal_cstrs (MalaStringList self, int nelem, char** cstrs, MalaEngine engine);
68 MalaStringList
69 mala_stringlist_node_new_literal_cstr (const char * cstr, MalaEngine engine);
71 MalaStringList
72 mala_stringlist_node_new_cstr (const char * cstr, MalaEngine engine);
74 MalaStringList
75 mala_stringlist_node_new (MalaString str, MalaEngine engine);
77 /* declarations */
78 static inline void
79 mala_stringlist_insert_after_stringlist (MalaStringList self, MalaStringList src);
81 static inline MalaString
82 mala_stringlist_string_from_llist (const_LList self);
84 static inline const char *
85 mala_stringlist_cstr_from_llist (const_LList self);
87 void
88 mala_stringlist_dump (MalaStringList self, FILE * f,
89 const char* head,
90 const char* before,
91 const char* fmt,
92 const char* after,
93 const char* foot);
95 static inline MalaString
96 mala_stringlist_string (MalaStringList self);
98 static inline MalaStringList
99 mala_stringlist_next (MalaStringList self);
101 static inline void
102 mala_stringlist_fwd (MalaStringList_ref self);
104 static inline void
105 mala_stringlist_rev (MalaStringList_ref self);
107 static inline void
108 mala_stringlist_remove (MalaStringList self);
110 static inline void
111 mala_stringlist_insert_tail (MalaStringList self, MalaStringList node);
113 static inline void
114 mala_stringlist_insert_head (MalaStringList self, MalaStringList node);
116 #define mala_stringlist_insert_before mala_stringlist_insert_tail
117 #define mala_stringlist_insert_after mala_stringlist_insert_head
119 /* inlines */
120 static inline void
121 mala_stringlist_insert_after_stringlist (MalaStringList self, MalaStringList src)
123 llist_insert_list_after (&src->node, &self->node);
126 static inline MalaString
127 mala_stringlist_string (MalaStringList self)
129 return self->string;
132 static inline MalaStringList
133 mala_stringlist_head_get (MalaStringList self)
135 return LLIST_TO_STRUCTP(llist_get_next (&self->node), mala_stringlist, node);
138 static inline MalaString
139 mala_stringlist_string_from_llist (const_LList self)
141 return LLIST_TO_STRUCTP(self, mala_stringlist, node)->string;
144 static inline const char *
145 mala_stringlist_cstr_from_llist (const_LList self)
147 return mala_string_cstr (mala_stringlist_string_from_llist (self));
150 static inline void
151 mala_stringlist_fwd (MalaStringList_ref self)
153 *self = LLIST_TO_STRUCTP (llist_get_next (&(*self)->node), mala_stringlist, node);
156 static inline void
157 mala_stringlist_rev (MalaStringList_ref self)
159 *self = LLIST_TO_STRUCTP (llist_get_prev (&(*self)->node), mala_stringlist, node);
162 static inline void
163 mala_stringlist_remove (MalaStringList self)
165 llist_unlink (&self->node);
168 static inline MalaStringList
169 mala_stringlist_next (MalaStringList self)
171 return LLIST_TO_STRUCTP (llist_get_next(&self->node), mala_stringlist, node);
174 static inline void
175 mala_stringlist_insert_tail (MalaStringList self, MalaStringList node)
177 llist_insert_tail (&self->node, &node->node);
180 static inline void
181 mala_stringlist_insert_head (MalaStringList self, MalaStringList node)
183 llist_insert_head (&self->node, &node->node);
186 static inline MalaStringList
187 mala_stringlist_tail_get (MalaStringList self)
189 return LLIST_TO_STRUCTP(llist_get_tail (&self->node), mala_stringlist, node);
192 static inline int
193 mala_stringlist_is_end (MalaStringList self, MalaStringList other)
195 return self == other;
198 #endif /* MALA_STRINGLIST_H */
201 // Local Variables:
202 // mode: C
203 // c-file-style: "gnu"
204 // End:
205 // arch-tag: 44b2b6d9-80b8-43fa-938a-a492bd52cea2
206 // end_of_file