c-strtod, memcoll, readutmp: no 'static inline'
[gnulib.git] / lib / gl_xlist.h
1 /* Abstract sequential list data type, with out-of-memory checking.
2    Copyright (C) 2009-2012 Free Software Foundation, Inc.
3    Written by Bruno Haible <bruno@clisp.org>, 2009.
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 #ifndef _GL_XLIST_H
19 #define _GL_XLIST_H
20
21 #include "gl_list.h"
22 #include "xalloc.h"
23
24 _GL_INLINE_HEADER_BEGIN
25 #ifndef GL_XLIST_INLINE
26 # define GL_XLIST_INLINE _GL_INLINE
27 #endif
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /* These functions are thin wrappers around the corresponding functions with
34    _nx_ infix from gl_list.h.  Upon out-of-memory, they invoke xalloc_die (),
35    instead of returning an error indicator.  */
36 extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
37                                        gl_listelement_equals_fn equals_fn,
38                                        gl_listelement_hashcode_fn hashcode_fn,
39                                        gl_listelement_dispose_fn dispose_fn,
40                                        bool allow_duplicates);
41 extern gl_list_t 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 extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
48                                     const void *elt);
49 extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
50                                       const void *elt);
51 extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
52 extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
53 extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
54                                           const void *elt);
55 extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
56                                          const void *elt);
57 extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
58                                       const void *elt);
59 extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
60                                          gl_listelement_compar_fn compar,
61                                          const void *elt);
62
63 GL_XLIST_INLINE gl_list_t
64 gl_list_create_empty (gl_list_implementation_t implementation,
65                       gl_listelement_equals_fn equals_fn,
66                       gl_listelement_hashcode_fn hashcode_fn,
67                       gl_listelement_dispose_fn dispose_fn,
68                       bool allow_duplicates)
69 {
70   gl_list_t result =
71     gl_list_nx_create_empty (implementation, equals_fn, hashcode_fn, dispose_fn,
72                              allow_duplicates);
73   if (result == NULL)
74     xalloc_die ();
75   return result;
76 }
77
78 GL_XLIST_INLINE gl_list_t
79 gl_list_create (gl_list_implementation_t implementation,
80                 gl_listelement_equals_fn equals_fn,
81                 gl_listelement_hashcode_fn hashcode_fn,
82                 gl_listelement_dispose_fn dispose_fn,
83                 bool allow_duplicates,
84                 size_t count, const void **contents)
85 {
86   gl_list_t result =
87     gl_list_nx_create (implementation, equals_fn, hashcode_fn, dispose_fn,
88                        allow_duplicates, count, contents);
89   if (result == NULL)
90     xalloc_die ();
91   return result;
92 }
93
94 GL_XLIST_INLINE void
95 gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
96 {
97   int result = gl_list_node_nx_set_value (list, node, elt);
98   if (result < 0)
99     xalloc_die ();
100 }
101
102 GL_XLIST_INLINE gl_list_node_t
103 gl_list_set_at (gl_list_t list, size_t position, const void *elt)
104 {
105   gl_list_node_t result = gl_list_nx_set_at (list, position, elt);
106   if (result == NULL)
107     xalloc_die ();
108   return result;
109 }
110
111 GL_XLIST_INLINE gl_list_node_t
112 gl_list_add_first (gl_list_t list, const void *elt)
113 {
114   gl_list_node_t result = gl_list_nx_add_first (list, elt);
115   if (result == NULL)
116     xalloc_die ();
117   return result;
118 }
119
120 GL_XLIST_INLINE gl_list_node_t
121 gl_list_add_last (gl_list_t list, const void *elt)
122 {
123   gl_list_node_t result = gl_list_nx_add_last (list, elt);
124   if (result == NULL)
125     xalloc_die ();
126   return result;
127 }
128
129 GL_XLIST_INLINE gl_list_node_t
130 gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
131 {
132   gl_list_node_t result = gl_list_nx_add_before (list, node, elt);
133   if (result == NULL)
134     xalloc_die ();
135   return result;
136 }
137
138 GL_XLIST_INLINE gl_list_node_t
139 gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
140 {
141   gl_list_node_t result = gl_list_nx_add_after (list, node, elt);
142   if (result == NULL)
143     xalloc_die ();
144   return result;
145 }
146
147 GL_XLIST_INLINE gl_list_node_t
148 gl_list_add_at (gl_list_t list, size_t position, const void *elt)
149 {
150   gl_list_node_t result = gl_list_nx_add_at (list, position, elt);
151   if (result == NULL)
152     xalloc_die ();
153   return result;
154 }
155
156 GL_XLIST_INLINE gl_list_node_t
157 gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar,
158                    const void *elt)
159 {
160   gl_list_node_t result = gl_sortedlist_nx_add (list, compar, elt);
161   if (result == NULL)
162     xalloc_die ();
163   return result;
164 }
165
166 #ifdef __cplusplus
167 }
168 #endif
169
170 _GL_INLINE_HEADER_END
171
172 #endif /* _GL_XLIST_H */