Imported Upstream version 1.4.16
[platform/upstream/m4.git] / lib / gl_xoset.h
1 /* Abstract ordered set data type, with out-of-memory checking.
2    Copyright (C) 2009-2011 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_XOSET_H
19 #define _GL_XOSET_H
20
21 #include "gl_oset.h"
22 #include "xalloc.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 /* These functions are thin wrappers around the corresponding functions with
29    _nx_ infix from gl_oset.h.  Upon out-of-memory, they invoke xalloc_die (),
30    instead of returning an error indicator.  */
31 extern gl_oset_t gl_oset_create_empty (gl_oset_implementation_t implementation,
32                                        gl_setelement_compar_fn compar_fn,
33                                        gl_setelement_dispose_fn dispose_fn);
34 extern bool gl_oset_add (gl_oset_t set, const void *elt);
35
36 #if HAVE_INLINE
37
38 # define gl_oset_create_empty gl_oset_create_empty_inline
39 static inline gl_oset_t
40 gl_oset_create_empty (gl_oset_implementation_t implementation,
41                       gl_setelement_compar_fn compar_fn,
42                       gl_setelement_dispose_fn dispose_fn)
43 {
44   gl_oset_t result =
45     gl_oset_nx_create_empty (implementation, compar_fn, dispose_fn);
46   if (result == NULL)
47     xalloc_die ();
48   return result;
49 }
50
51 # define gl_oset_add gl_oset_add_inline
52 static inline bool
53 gl_oset_add (gl_oset_t set, const void *elt)
54 {
55   int result = gl_oset_nx_add (set, elt);
56   if (result < 0)
57     xalloc_die ();
58   return result;
59 }
60
61 #endif
62
63 #ifdef __cplusplus
64 }
65 #endif
66
67 #endif /* _GL_XOSET_H */