Include <config.h> unconditionally.
[gnulib.git] / lib / gl_list.c
1 /* Abstract sequential list data type.
2    Copyright (C) 2006 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 2, or (at your option)
8    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, write to the Free Software Foundation,
17    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
18
19 #include <config.h>
20
21 /* Specification.  */
22 #include "gl_list.h"
23
24 #if !HAVE_INLINE
25
26 /* Define all functions of this file as inline accesses to the
27    struct gl_list_implementation.
28    Use #define to avoid a warning because of extern vs. static.  */
29
30 gl_list_t
31 gl_list_create_empty (gl_list_implementation_t implementation,
32                       gl_listelement_equals_fn equals_fn,
33                       gl_listelement_hashcode_fn hashcode_fn,
34                       bool allow_duplicates)
35 {
36   return implementation->create_empty (implementation, equals_fn, hashcode_fn,
37                                        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                 bool allow_duplicates,
45                 size_t count, const void **contents)
46 {
47   return implementation->create (implementation, equals_fn, hashcode_fn,
48                                  allow_duplicates, count, contents);
49 }
50
51 size_t
52 gl_list_size (gl_list_t list)
53 {
54   return ((const struct gl_list_impl_base *) list)->vtable
55          ->size (list);
56 }
57
58 const void *
59 gl_list_node_value (gl_list_t list, gl_list_node_t node)
60 {
61   return ((const struct gl_list_impl_base *) list)->vtable
62          ->node_value (list, node);
63 }
64
65 gl_list_node_t
66 gl_list_next_node (gl_list_t list, gl_list_node_t node)
67 {
68   return ((const struct gl_list_impl_base *) list)->vtable
69          ->next_node (list, node);
70 }
71
72 gl_list_node_t
73 gl_list_previous_node (gl_list_t list, gl_list_node_t node)
74 {
75   return ((const struct gl_list_impl_base *) list)->vtable
76          ->previous_node (list, node);
77 }
78
79 const void *
80 gl_list_get_at (gl_list_t list, size_t position)
81 {
82   return ((const struct gl_list_impl_base *) list)->vtable
83          ->get_at (list, position);
84 }
85
86 gl_list_node_t
87 gl_list_set_at (gl_list_t list, size_t position, const void *elt)
88 {
89   return ((const struct gl_list_impl_base *) list)->vtable
90          ->set_at (list, position, elt);
91 }
92
93 gl_list_node_t
94 gl_list_search (gl_list_t list, const void *elt)
95 {
96   return ((const struct gl_list_impl_base *) list)->vtable
97          ->search (list, elt);
98 }
99
100 size_t
101 gl_list_indexof (gl_list_t list, const void *elt)
102 {
103   return ((const struct gl_list_impl_base *) list)->vtable
104          ->indexof (list, elt);
105 }
106
107 gl_list_node_t
108 gl_list_add_first (gl_list_t list, const void *elt)
109 {
110   return ((const struct gl_list_impl_base *) list)->vtable
111          ->add_first (list, elt);
112 }
113
114 gl_list_node_t
115 gl_list_add_last (gl_list_t list, const void *elt)
116 {
117   return ((const struct gl_list_impl_base *) list)->vtable
118          ->add_last (list, elt);
119 }
120
121 gl_list_node_t
122 gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
123 {
124   return ((const struct gl_list_impl_base *) list)->vtable
125          ->add_before (list, node, elt);
126 }
127
128 gl_list_node_t
129 gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
130 {
131   return ((const struct gl_list_impl_base *) list)->vtable
132          ->add_after (list, node, elt);
133 }
134
135 gl_list_node_t
136 gl_list_add_at (gl_list_t list, size_t position, const void *elt)
137 {
138   return ((const struct gl_list_impl_base *) list)->vtable
139          ->add_at (list, position, elt);
140 }
141
142 bool
143 gl_list_remove_node (gl_list_t list, gl_list_node_t node)
144 {
145   return ((const struct gl_list_impl_base *) list)->vtable
146          ->remove_node (list, node);
147 }
148
149 bool
150 gl_list_remove_at (gl_list_t list, size_t position)
151 {
152   return ((const struct gl_list_impl_base *) list)->vtable
153          ->remove_at (list, position);
154 }
155
156 bool
157 gl_list_remove (gl_list_t list, const void *elt)
158 {
159   return ((const struct gl_list_impl_base *) list)->vtable
160          ->remove (list, elt);
161 }
162
163 void
164 gl_list_free (gl_list_t list)
165 {
166   ((const struct gl_list_impl_base *) list)->vtable->list_free (list);
167 }
168
169 gl_list_iterator_t
170 gl_list_iterator (gl_list_t list)
171 {
172   return ((const struct gl_list_impl_base *) list)->vtable
173          ->iterator (list);
174 }
175
176 gl_list_iterator_t
177 gl_list_iterator_from_to (gl_list_t list, size_t start_index, size_t end_index)
178 {
179   return ((const struct gl_list_impl_base *) list)->vtable
180          ->iterator_from_to (list, start_index, end_index);
181 }
182
183 bool
184 gl_list_iterator_next (gl_list_iterator_t *iterator,
185                        const void **eltp, gl_list_node_t *nodep)
186 {
187   return iterator->vtable->iterator_next (iterator, eltp, nodep);
188 }
189
190 void
191 gl_list_iterator_free (gl_list_iterator_t *iterator)
192 {
193   iterator->vtable->iterator_free (iterator);
194 }
195
196 gl_list_node_t
197 gl_sortedlist_search (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
198 {
199   return ((const struct gl_list_impl_base *) list)->vtable
200          ->sortedlist_search (list, compar, elt);
201 }
202
203 size_t
204 gl_sortedlist_indexof (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
205 {
206   return ((const struct gl_list_impl_base *) list)->vtable
207          ->sortedlist_indexof (list, compar, elt);
208 }
209
210 gl_list_node_t
211 gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
212 {
213   return ((const struct gl_list_impl_base *) list)->vtable
214          ->sortedlist_add (list, compar, elt);
215 }
216
217 bool
218 gl_sortedlist_remove (gl_list_t list, gl_listelement_compar_fn compar, const void *elt)
219 {
220   return ((const struct gl_list_impl_base *) list)->vtable
221          ->sortedlist_remove (list, compar, elt);
222 }
223
224 #endif