Change copyright notice from GPLv2+ to GPLv3+.
[gnulib.git] / lib / gl_list.c
1 /* Abstract sequential list data type.
2    Copyright (C) 2006-2007 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_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->create_empty (implementation, equals_fn, hashcode_fn,
37                                        dispose_fn, allow_duplicates);
38 }
39
40 gl_list_t
41 gl_list_create (gl_list_implementation_t implementation,
42                 gl_listelement_equals_fn equals_fn,
43                 gl_listelement_hashcode_fn hashcode_fn,
44                 gl_listelement_dispose_fn dispose_fn,
45                 bool allow_duplicates,
46                 size_t count, const void **contents)
47 {
48   return implementation->create (implementation, equals_fn, hashcode_fn,
49                                  dispose_fn, allow_duplicates, count, contents);
50 }
51
52 size_t
53 gl_list_size (gl_list_t list)
54 {
55   return ((const struct gl_list_impl_base *) list)->vtable
56          ->size (list);
57 }
58
59 const void *
60 gl_list_node_value (gl_list_t list, gl_list_node_t node)
61 {
62   return ((const struct gl_list_impl_base *) list)->vtable
63          ->node_value (list, node);
64 }
65
66 gl_list_node_t
67 gl_list_next_node (gl_list_t list, gl_list_node_t node)
68 {
69   return ((const struct gl_list_impl_base *) list)->vtable
70          ->next_node (list, node);
71 }
72
73 gl_list_node_t
74 gl_list_previous_node (gl_list_t list, gl_list_node_t node)
75 {
76   return ((const struct gl_list_impl_base *) list)->vtable
77          ->previous_node (list, node);
78 }
79
80 const void *
81 gl_list_get_at (gl_list_t list, size_t position)
82 {
83   return ((const struct gl_list_impl_base *) list)->vtable
84          ->get_at (list, position);
85 }
86
87 gl_list_node_t
88 gl_list_set_at (gl_list_t list, size_t position, const void *elt)
89 {
90   return ((const struct gl_list_impl_base *) list)->vtable
91          ->set_at (list, position, elt);
92 }
93
94 gl_list_node_t
95 gl_list_search (gl_list_t list, const void *elt)
96 {
97   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
98   return ((const struct gl_list_impl_base *) list)->vtable
99          ->search_from_to (list, 0, size, elt);
100 }
101
102 gl_list_node_t
103 gl_list_search_from (gl_list_t list, size_t start_index, const void *elt)
104 {
105   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
106   return ((const struct gl_list_impl_base *) list)->vtable
107          ->search_from_to (list, start_index, size, elt);
108 }
109
110 gl_list_node_t
111 gl_list_search_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt)
112 {
113   return ((const struct gl_list_impl_base *) list)->vtable
114          ->search_from_to (list, start_index, end_index, elt);
115 }
116
117 size_t
118 gl_list_indexof (gl_list_t list, const void *elt)
119 {
120   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
121   return ((const struct gl_list_impl_base *) list)->vtable
122          ->indexof_from_to (list, 0, size, elt);
123 }
124
125 size_t
126 gl_list_indexof_from (gl_list_t list, size_t start_index, const void *elt)
127 {
128   size_t size = ((const struct gl_list_impl_base *) list)->vtable->size (list);
129   return ((const struct gl_list_impl_base *) list)->vtable
130          ->indexof_from_to (list, start_index, size, elt);
131 }
132
133 size_t
134 gl_list_indexof_from_to (gl_list_t list, size_t start_index, size_t end_index, const void *elt)
135 {
136   return ((const struct gl_list_impl_base *) list)->vtable
137          ->indexof_from_to (list, start_index, end_index, elt);
138 }
139
140 gl_list_node_t
141 gl_list_add_first (gl_list_t list, const void *elt)
142 {
143   return ((const struct gl_list_impl_base *) list)->vtable
144          ->add_first (list, elt);
145 }
146
147 gl_list_node_t
148 gl_list_add_last (gl_list_t list, const void *elt)
149 {
150   return ((const struct gl_list_impl_base *) list)->vtable
151          ->add_last (list, elt);
152 }
153
154 gl_list_node_t
155 gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
156 {
157   return ((const struct gl_list_impl_base *) list)->vtable
158          ->add_before (list, node, elt);
159 }
160
161 gl_list_node_t
162 gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
163 {
164   return ((const struct gl_list_impl_base *) list)->vtable
165          ->add_after (list, node, elt);
166 }
167
168 gl_list_node_t
169 gl_list_add_at (gl_list_t list, size_t position, const void *elt)
170 {
171   return ((const struct gl_list_impl_base *) list)->vtable
172          ->add_at (list, position, elt);
173 }
174
175 bool
176 gl_list_remove_node (gl_list_t list, gl_list_node_t node)
177 {
178   return ((const struct gl_list_impl_base *) list)->vtable
179          ->remove_node (list, node);
180 }
181
182 bool
183 gl_list_remove_at (gl_list_t list, size_t position)
184 {
185   return ((const struct gl_list_impl_base *) list)->vtable
186          ->remove_at (list, position);
187 }
188
189 bool
190 gl_list_remove (gl_list_t list, const void *elt)
191 {
192   return ((const struct gl_list_impl_base *) list)->vtable
193          ->remove (list, elt);
194 }
195
196 void
197 gl_list_free (gl_list_t list)
198 {
199   ((const struct gl_list_impl_base *) list)->vtable->list_free (list);
200 }
201
202 gl_list_iterator_t
203 gl_list_iterator (gl_list_t list)
204 {
205   return ((const struct gl_list_impl_base *) list)->vtable
206          ->iterator (list);
207 }
208
209 gl_list_iterator_t
210 gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index)
211 {
212   return ((const struct gl_list_impl_base *) list)->vtable
213          ->iterator_from_to (list, start_index, end_index);
214 }
215
216 bool
217 gl_list_iterator_next (gl_list_iterator_t *iterator,
218                        const void **eltp, gl_list_node_t *nodep)
219 {
220   return iterator->vtable->iterator_next (iterator, eltp, nodep);
221 }
222
223 void
224 gl_list_iterator_free (gl_list_iterator_t *iterator)
225 {
226   iterator->vtable->iterator_free (iterator);
227 }
228
229 gl_list_node_t
230 gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
231 {
232   return ((const struct gl_list_impl_base *) list)->vtable
233          ->sortedlist_search (list, compar, elt);
234 }
235
236 gl_list_node_t
237 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)
238 {
239   return ((const struct gl_list_impl_base *) list)->vtable
240          ->sortedlist_search_from_to (list, compar, start_index, end_index,
241                                       elt);
242 }
243
244 size_t
245 gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
246 {
247   return ((const struct gl_list_impl_base *) list)->vtable
248          ->sortedlist_indexof (list, compar, elt);
249 }
250
251 size_t
252 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)
253 {
254   return ((const struct gl_list_impl_base *) list)->vtable
255          ->sortedlist_indexof_from_to (list, compar, start_index, end_index,
256                                        elt);
257 }
258
259 gl_list_node_t
260 gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
261 {
262   return ((const struct gl_list_impl_base *) list)->vtable
263          ->sortedlist_add (list, compar, elt);
264 }
265
266 bool
267 gl_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
268 {
269   return ((const struct gl_list_impl_base *) list)->vtable
270          ->sortedlist_remove (list, compar, elt);
271 }
272
273 #endif