Mercurial > gnulib
annotate lib/gl_xmap.h @ 40057:b06060465f09
maint: Run 'make update-copyright'
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 01 Jan 2019 00:25:11 +0100 |
parents | 6e03d13e4ae0 |
children |
rev | line source |
---|---|
40021 | 1 /* Abstract map data type, with out-of-memory checking. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
40021
diff
changeset
|
2 Copyright (C) 2009-2019 Free Software Foundation, Inc. |
40021 | 3 Written by Bruno Haible <bruno@clisp.org>, 2018. |
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_XMAP_H | |
19 #define _GL_XMAP_H | |
20 | |
21 #include "gl_map.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_XMAP_INLINE | |
29 # define GL_XMAP_INLINE _GL_INLINE | |
30 #endif | |
31 | |
32 | |
33 #ifdef __cplusplus | |
34 extern "C" { | |
35 #endif | |
36 | |
37 /* These functions are thin wrappers around the corresponding functions with | |
38 _nx_ infix from gl_map.h. Upon out-of-memory, they invoke xalloc_die (), | |
39 instead of returning an error indicator. */ | |
40 #if 0 /* These are defined inline below. */ | |
41 extern gl_map_t gl_map_create_empty (gl_map_implementation_t implementation, | |
42 gl_mapkey_equals_fn equals_fn, | |
43 gl_mapkey_hashcode_fn hashcode_fn, | |
44 gl_mapkey_dispose_fn kdispose_fn, | |
45 gl_mapvalue_dispose_fn vdispose_fn); | |
46 extern bool gl_map_put (gl_map_t map, const void *key, const void *value); | |
47 extern bool gl_map_getput (gl_map_t map, const void *key, const void *value, | |
48 const void **oldvaluep); | |
49 #endif | |
50 | |
51 GL_XMAP_INLINE gl_map_t | |
52 gl_map_create_empty (gl_map_implementation_t implementation, | |
53 gl_mapkey_equals_fn equals_fn, | |
54 gl_mapkey_hashcode_fn hashcode_fn, | |
55 gl_mapkey_dispose_fn kdispose_fn, | |
56 gl_mapvalue_dispose_fn vdispose_fn) | |
57 { | |
58 gl_map_t result = | |
59 gl_map_nx_create_empty (implementation, equals_fn, hashcode_fn, | |
60 kdispose_fn, vdispose_fn); | |
61 if (result == NULL) | |
62 xalloc_die (); | |
63 return result; | |
64 } | |
65 | |
66 GL_XMAP_INLINE bool | |
67 gl_map_put (gl_map_t map, const void *key, const void *value) | |
68 { | |
69 int result = gl_map_nx_put (map, key, value); | |
70 if (result < 0) | |
71 xalloc_die (); | |
72 return result; | |
73 } | |
74 | |
75 GL_XMAP_INLINE bool | |
76 gl_map_getput (gl_map_t map, const void *key, const void *value, | |
77 const void **oldvaluep) | |
78 { | |
79 int result = gl_map_nx_getput (map, key, value, oldvaluep); | |
80 if (result < 0) | |
81 xalloc_die (); | |
82 return result; | |
83 } | |
84 | |
85 #ifdef __cplusplus | |
86 } | |
87 #endif | |
88 | |
89 _GL_INLINE_HEADER_END | |
90 | |
91 #endif /* _GL_XMAP_H */ |