finalise NEWS.stable
[gnulib.git] / lib / gl_xlist.h
1 /* Abstract sequential list data type, with out-of-memory checking.
2    Copyright (C) 2009-2013 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 #if 0 /* These are defined inline below.  */
37 extern gl_list_t gl_list_create_empty (gl_list_implementation_t implementation,
38                                        gl_listelement_equals_fn equals_fn,
39                                        gl_listelement_hashcode_fn hashcode_fn,
40                                        gl_listelement_dispose_fn dispose_fn,
41                                        bool allow_duplicates);
42 extern gl_list_t gl_list_create (gl_list_implementation_t implementation,
43                                  gl_listelement_equals_fn equals_fn,
44                                  gl_listelement_hashcode_fn hashcode_fn,
45                                  gl_listelement_dispose_fn dispose_fn,
46                                  bool allow_duplicates,
47                                  size_t count, const void **contents);
48 extern void gl_list_node_set_value (gl_list_t list, gl_list_node_t node,
49                                     const void *elt);
50 extern gl_list_node_t gl_list_set_at (gl_list_t list, size_t position,
51                                       const void *elt);
52 extern gl_list_node_t gl_list_add_first (gl_list_t list, const void *elt);
53 extern gl_list_node_t gl_list_add_last (gl_list_t list, const void *elt);
54 extern gl_list_node_t gl_list_add_before (gl_list_t list, gl_list_node_t node,
55                                           const void *elt);
56 extern gl_list_node_t gl_list_add_after (gl_list_t list, gl_list_node_t node,
57                                          const void *elt);
58 extern gl_list_node_t gl_list_add_at (gl_list_t list, size_t position,
59                                       const void *elt);
60 extern gl_list_node_t gl_sortedlist_add (gl_list_t list,
61                                          gl_listelement_compar_fn compar,
62                                          const void *elt);
63 #endif
64
65 GL_XLIST_INLINE gl_list_t
66 gl_list_create_empty (gl_list_implementation_t implementation,
67                       gl_listelement_equals_fn equals_fn,
68                       gl_listelement_hashcode_fn hashcode_fn,
69                       gl_listelement_dispose_fn dispose_fn,
70                       bool allow_duplicates)
71 {
72   gl_list_t result =
73     gl_list_nx_create_empty (implementation, equals_fn, hashcode_fn, dispose_fn,
74                              allow_duplicates);
75   if (result == NULL)
76     xalloc_die ();
77   return result;
78 }
79
80 GL_XLIST_INLINE gl_list_t
81 gl_list_create (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                 size_t count, const void **contents)
87 {
88   gl_list_t result =
89     gl_list_nx_create (implementation, equals_fn, hashcode_fn, dispose_fn,
90                        allow_duplicates, count, contents);
91   if (result == NULL)
92     xalloc_die ();
93   return result;
94 }
95
96 GL_XLIST_INLINE void
97 gl_list_node_set_value (gl_list_t list, gl_list_node_t node, const void *elt)
98 {
99   int result = gl_list_node_nx_set_value (list, node, elt);
100   if (result < 0)
101     xalloc_die ();
102 }
103
104 GL_XLIST_INLINE gl_list_node_t
105 gl_list_set_at (gl_list_t list, size_t position, const void *elt)
106 {
107   gl_list_node_t result = gl_list_nx_set_at (list, position, elt);
108   if (result == NULL)
109     xalloc_die ();
110   return result;
111 }
112
113 GL_XLIST_INLINE gl_list_node_t
114 gl_list_add_first (gl_list_t list, const void *elt)
115 {
116   gl_list_node_t result = gl_list_nx_add_first (list, elt);
117   if (result == NULL)
118     xalloc_die ();
119   return result;
120 }
121
122 GL_XLIST_INLINE gl_list_node_t
123 gl_list_add_last (gl_list_t list, const void *elt)
124 {
125   gl_list_node_t result = gl_list_nx_add_last (list, elt);
126   if (result == NULL)
127     xalloc_die ();
128   return result;
129 }
130
131 GL_XLIST_INLINE gl_list_node_t
132 gl_list_add_before (gl_list_t list, gl_list_node_t node, const void *elt)
133 {
134   gl_list_node_t result = gl_list_nx_add_before (list, node, elt);
135   if (result == NULL)
136     xalloc_die ();
137   return result;
138 }
139
140 GL_XLIST_INLINE gl_list_node_t
141 gl_list_add_after (gl_list_t list, gl_list_node_t node, const void *elt)
142 {
143   gl_list_node_t result = gl_list_nx_add_after (list, node, elt);
144   if (result == NULL)
145     xalloc_die ();
146   return result;
147 }
148
149 GL_XLIST_INLINE gl_list_node_t
150 gl_list_add_at (gl_list_t list, size_t position, const void *elt)
151 {
152   gl_list_node_t result = gl_list_nx_add_at (list, position, elt);
153   if (result == NULL)
154     xalloc_die ();
155   return result;
156 }
157
158 GL_XLIST_INLINE gl_list_node_t
159 gl_sortedlist_add (gl_list_t list, gl_listelement_compar_fn compar,
160                    const void *elt)
161 {
162   gl_list_node_t result = gl_sortedlist_nx_add (list, compar, elt);
163   if (result == NULL)
164     xalloc_die ();
165   return result;
166 }
167
168 #ifdef __cplusplus
169 }
170 #endif
171
172 _GL_INLINE_HEADER_END
173
174 #endif /* _GL_XLIST_H */