Imported Upstream version 1.4.16
[platform/upstream/m4.git] / lib / gl_list.c
1 /* Abstract sequential list data type.
2    Copyright (C) 2006-2011 Free Software Foundation, Inc.
3    Written by Bruno Haible <bruno@clisp.org>, 2006.
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
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.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 #include <config.h>
19
20 /* Specification.  */
21 #include "gl_list.h"
22
23 #if !HAVE_INLINE
24
25 /* Define all functions of this file as inline accesses to the
26    struct gl_list_implementation.
27    Use #define to avoid a warning because of extern vs. static.  */
28
29 gl_list_t
30 gl_list_nx_create_empty (gl_list_implementation_t implementation,
31                          gl_listelement_equals_fn equals_fn,
32                          gl_listelement_hashcode_fn hashcode_fn,
33                          gl_listelement_dispose_fn dispose_fn,
34                          bool allow_duplicates)
35 {
36   return implementation->nx_create_empty (implementation, equals_fn,
37                                           hashcode_fn, dispose_fn,
38                                           allow_duplicates);
39 }
40
41 gl_list_t
42 gl_list_nx_create (gl_list_implementation_t implementation,
43                    gl_listelement_equals_fn equals_fn,
44                    gl_listelement_hashcode_fn hashcode_fn,
45                    gl_listelement_dispose_fn dispose_fn,
46                    bool allow_duplicates,
47                    size_t count, const void **contents)
48 {
49   return implementation->nx_create (implementation, equals_fn, hashcode_fn,
50                                     dispose_fn, allow_duplicates, count,
51                                     contents);
52 }
53
54 size_t
55 gl_list_size (gl_list_t list)
56 {
57   return ((const struct gl_list_impl_base *) list)->vtable
58          ->size (list);
59 }
60
61 const void *
62 gl_list_node_value (gl_list_t list, gl_list_node_t node)
63 {
64   return ((const struct gl_list_impl_base *) list)->vtable
65          ->node_value (list, node);
66 }
67
68 int
69 gl_list_node_nx_set_value (gl_list_t list, gl_list_node_t node,
70                            const void *elt)
71 {
72   return ((const struct gl_list_impl_base *) list)->vtable
73          ->node_nx_set_value (list, node, elt);
74 }
75
76 gl_list_node_t
77 gl_list_next_node (gl_list_t list, gl_list_node_t node)
78 {
79   return ((const struct gl_list_impl_base *) list)->vtable
80          ->next_node (list, node);
81 }
82
83 gl_list_node_t
84 gl_list_previous_node (gl_list_t list, gl_list_node_t node)
85 {
86   return ((const struct gl_list_impl_base *) list)->vtable
87          ->previous_node (list, node);
88 }
89
90 const void *
91 gl_list_get_at (gl_list_t list, size_t position)
92 {
93   return ((const struct gl_list_impl_base *) list)->vtable
94          ->get_at (list, position);
95 }
96
97 gl_list_node_t
98 gl_list_nx_set_at (gl_list_t list, size_t position, const void *elt)
99 {
100   return ((const struct gl_list_impl_base *) list)->vtable
101          ->nx_set_at (list, position, elt);
102 }
103
104 gl_list_node_t
105 gl_list_search (gl_list_t list, const void *elt)
106 {
107   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
108   return ((const struct gl_list_impl_base *) list)->vtable
109          ->search_from_to (list, 0, size, elt);
110 }
111
112 gl_list_node_t
113 gl_list_search_from (gl_list_t list, size_t start_index, const void *elt)
114 {
115   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
116   return ((const struct gl_list_impl_base *) list)->vtable
117          ->search_from_to (list, start_index, size, elt);
118 }
119
120 gl_list_node_t
121 gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt)
122 {
123   return ((const struct gl_list_impl_base *) list)->vtable
124          ->search_from_to (list, start_index, end_index, elt);
125 }
126
127 size_t
128 gl_list_indexof (gl_list_t list, const void *elt)
129 {
130   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
131   return ((const struct gl_list_impl_base *) list)->vtable
132          ->indexof_from_to (list, 0, size, elt);
133 }
134
135 size_t
136 gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt)
137 {
138   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
139   return ((const struct gl_list_impl_base *) list)->vtable
140          ->indexof_from_to (list, start_index, size, elt);
141 }
142
143 size_t
144 gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt)
145 {
146   return ((const struct gl_list_impl_base *) list)->vtable
147          ->indexof_from_to (list, start_index, end_index, elt);
148 }
149
150 gl_list_node_t
151 gl_list_nx_add_first (gl_list_t list, const void *elt)
152 {
153   return ((const struct gl_list_impl_base *) list)->vtable
154          ->nx_add_first (list, elt);
155 }
156
157 gl_list_node_t
158 gl_list_nx_add_last (gl_list_t list, const void *elt)
159 {
160   return ((const struct gl_list_impl_base *) list)->vtable
161          ->nx_add_last (list, elt);
162 }
163
164 gl_list_node_t
165 gl_list_nx_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
166 {
167   return ((const struct gl_list_impl_base *) list)->vtable
168          ->nx_add_before (list, node, elt);
169 }
170
171 gl_list_node_t
172 gl_list_nx_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
173 {
174   return ((const struct gl_list_impl_base *) list)->vtable
175          ->nx_add_after (list, node, elt);
176 }
177
178 gl_list_node_t
179 gl_list_nx_add_at (gl_list_t list, size_t position, const void *elt)
180 {
181   return ((const struct gl_list_impl_base *) list)->vtable
182          ->nx_add_at (list, position, elt);
183 }
184
185 bool
186 gl_list_remove_node (gl_list_t list, gl_list_node_t node)
187 {
188   return ((const struct gl_list_impl_base *) list)->vtable
189          ->remove_node (list, node);
190 }
191
192 bool
193 gl_list_remove_at (gl_list_t list, size_t position)
194 {
195   return ((const struct gl_list_impl_base *) list)->vtable
196          ->remove_at (list, position);
197 }
198
199 bool
200 gl_list_remove (gl_list_t list, const void *elt)
201 {
202   return ((const struct gl_list_impl_base *) list)->vtable
203          ->remove_elt (list, elt);
204 }
205
206 void
207 gl_list_free (gl_list_t list)
208 {
209   ((const struct gl_list_impl_base *) list)->vtable->list_free (list);
210 }
211
212 gl_list_iterator_t
213 gl_list_iterator (gl_list_t list)
214 {
215   return ((const struct gl_list_impl_base *) list)->vtable
216          ->iterator (list);
217 }
218
219 gl_list_iterator_t
220 gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index)
221 {
222   return ((const struct gl_list_impl_base *) list)->vtable
223          ->iterator_from_to (list, start_index, end_index);
224 }
225
226 bool
227 gl_list_iterator_next (gl_list_iterator_t *iterator,
228                        const void **eltp, gl_list_node_t *nodep)
229 {
230   return iterator->vtable->iterator_next (iterator, eltp, nodep);
231 }
232
233 void
234 gl_list_iterator_free (gl_list_iterator_t *iterator)
235 {
236   iterator->vtable->iterator_free (iterator);
237 }
238
239 gl_list_node_t
240 gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
241 {
242   return ((const struct gl_list_impl_base *) list)->vtable
243          ->sortedlist_search (list, compar, elt);
244 }
245
246 gl_list_node_t
247 gl_sortedlist_search_from_to (gl_list_t list, gl_listelement_compar_fn compar, size_t start_index, size_t end_index, const void *elt)
248 {
249   return ((const struct gl_list_impl_base *) list)->vtable
250          ->sortedlist_search_from_to (list, compar, start_index, end_index,
251                                       elt);
252 }
253
254 size_t
255 gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
256 {
257   return ((const struct gl_list_impl_base *) list)->vtable
258          ->sortedlist_indexof (list, compar, elt);
259 }
260
261 size_t
262 gl_sortedlist_indexof_from_to (gl_list_t list, gl_listelement_compar_fn compar, size_t start_index, size_t end_index, const void *elt)
263 {
264   return ((const struct gl_list_impl_base *) list)->vtable
265          ->sortedlist_indexof_from_to (list, compar, start_index, end_index,
266                                        elt);
267 }
268
269 gl_list_node_t
270 gl_sortedlist_nx_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
271 {
272   return ((const struct gl_list_impl_base *) list)->vtable
273          ->sortedlist_nx_add (list, compar, elt);
274 }
275
276 bool
277 gl_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
278 {
279   return ((const struct gl_list_impl_base *) list)->vtable
280          ->sortedlist_remove (list, compar, elt);
281 }
282
283 #endif