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