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