Bump to m4 1.4.19
[platform/upstream/m4.git] / lib / gl_xlist.h
1 /* Abstract sequential list data type, with out-of-memory checking.
2    Copyright (C) 2009-2021 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 <https://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 #ifndef _GL_INLINE_HEADER_BEGIN
25  #error "Please include config.h first."
26 #endif
27 _GL_INLINE_HEADER_BEGIN
28 #ifndef GL_XLIST_INLINE
29 # define GL_XLIST_INLINE _GL_INLINE
30 #endif
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /* These functions are thin wrappers around the corresponding functions with
37    _nx_ infix from gl_list.h.  Upon out-of-memory, they invoke xalloc_die (),
38    instead of returning an error indicator.  */
39 #if 0 /* These are defined inline below.  */
40 extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
41                                        gl_listelement_equals_fn equals_fn,
42                                        gl_listelement_hashcode_fn hashcode_fn,
43                                        gl_listelement_dispose_fn dispose_fn,
44                                        bool allow_duplicates);
45 extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
46                                  gl_listelement_equals_fn equals_fn,
47                                  gl_listelement_hashcode_fn hashcode_fn,
48                                  gl_listelement_dispose_fn dispose_fn,
49                                  bool allow_duplicates,
50                                  size_t count, const void **contents);
51 extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
52                                     const void *elt);
53 extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
54                                       const void *elt);
55 extern gl_list_node_t gl_list_set_first (gl_list_t list, const void *elt);
56 extern gl_list_node_t gl_list_set_last (gl_list_t list, const void *elt);
57 extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
58 extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
59 extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
60                                           const void *elt);
61 extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
62                                          const void *elt);
63 extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
64                                       const void *elt);
65 extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
66                                          gl_listelement_compar_fn compar,
67                                          const void *elt);
68 #endif
69
70 GL_XLIST_INLINE gl_list_t
71 gl_list_create_empty (gl_list_implementation_t implementation,
72                       gl_listelement_equals_fn equals_fn,
73                       gl_listelement_hashcode_fn hashcode_fn,
74                       gl_listelement_dispose_fn dispose_fn,
75                       bool allow_duplicates)
76 {
77   gl_list_t result =
78     gl_list_nx_create_empty (implementation, equals_fn, hashcode_fn, dispose_fn,
79                              allow_duplicates);
80   if (result == NULL)
81     xalloc_die ();
82   return result;
83 }
84
85 GL_XLIST_INLINE gl_list_t
86 gl_list_create (gl_list_implementation_t implementation,
87                 gl_listelement_equals_fn equals_fn,
88                 gl_listelement_hashcode_fn hashcode_fn,
89                 gl_listelement_dispose_fn dispose_fn,
90                 bool allow_duplicates,
91                 size_t count, const void **contents)
92 {
93   gl_list_t result =
94     gl_list_nx_create (implementation, equals_fn, hashcode_fn, dispose_fn,
95                        allow_duplicates, count, contents);
96   if (result == NULL)
97     xalloc_die ();
98   return result;
99 }
100
101 GL_XLIST_INLINE void
102 gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
103 {
104   int result = gl_list_node_nx_set_value (list, node, elt);
105   if (result < 0)
106     xalloc_die ();
107 }
108
109 GL_XLIST_INLINE gl_list_node_t
110 gl_list_set_at (gl_list_t list, size_t position, const void *elt)
111 {
112   gl_list_node_t result = gl_list_nx_set_at (list, position, elt);
113   if (result == NULL)
114     xalloc_die ();
115   return result;
116 }
117
118 GL_XLIST_INLINE gl_list_node_t
119 gl_list_set_first (gl_list_t list, const void *elt)
120 {
121   gl_list_node_t result = gl_list_nx_set_first (list, elt);
122   if (result == NULL)
123     xalloc_die ();
124   return result;
125 }
126
127 GL_XLIST_INLINE gl_list_node_t
128 gl_list_set_last (gl_list_t list, const void *elt)
129 {
130   gl_list_node_t result = gl_list_nx_set_last (list, elt);
131   if (result == NULL)
132     xalloc_die ();
133   return result;
134 }
135
136 GL_XLIST_INLINE gl_list_node_t
137 gl_list_add_first (gl_list_t list, const void *elt)
138 {
139   gl_list_node_t result = gl_list_nx_add_first (list, elt);
140   if (result == NULL)
141     xalloc_die ();
142   return result;
143 }
144
145 GL_XLIST_INLINE gl_list_node_t
146 gl_list_add_last (gl_list_t list, const void *elt)
147 {
148   gl_list_node_t result = gl_list_nx_add_last (list, elt);
149   if (result == NULL)
150     xalloc_die ();
151   return result;
152 }
153
154 GL_XLIST_INLINE gl_list_node_t
155 gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
156 {
157   gl_list_node_t result = gl_list_nx_add_before (list, node, elt);
158   if (result == NULL)
159     xalloc_die ();
160   return result;
161 }
162
163 GL_XLIST_INLINE gl_list_node_t
164 gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
165 {
166   gl_list_node_t result = gl_list_nx_add_after (list, node, elt);
167   if (result == NULL)
168     xalloc_die ();
169   return result;
170 }
171
172 GL_XLIST_INLINE gl_list_node_t
173 gl_list_add_at (gl_list_t list, size_t position, const void *elt)
174 {
175   gl_list_node_t result = gl_list_nx_add_at (list, position, elt);
176   if (result == NULL)
177     xalloc_die ();
178   return result;
179 }
180
181 GL_XLIST_INLINE gl_list_node_t
182 gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar,
183                    const void *elt)
184 {
185   gl_list_node_t result = gl_sortedlist_nx_add (list, compar, elt);
186   if (result == NULL)
187     xalloc_die ();
188   return result;
189 }
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 _GL_INLINE_HEADER_END
196
197 #endif /* _GL_XLIST_H */