Sun, 05 Jan 2025 14:03:30 +0100
free functions should not be inline in release mode - relates to #541
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
4 | * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
29 | * @file map.h |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
30 | * @brief Interface for map implementations. |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
31 | * @author Mike Becker |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
32 | * @author Olaf Wintermann |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
33 | * @copyright 2-Clause BSD License |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
34 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | #ifndef UCX_MAP_H |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | #define UCX_MAP_H |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | |
681
502105523db7
fix common.h include problems - fixes #255
Mike Becker <universe@uap-core.de>
parents:
677
diff
changeset
|
39 | #include "common.h" |
677
b09aae58bba4
refactoring of collections to make use of destructors in map implementations
Mike Becker <universe@uap-core.de>
parents:
669
diff
changeset
|
40 | #include "collection.h" |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
41 | #include "string.h" |
563
69a83fad8a35
improve hash key handling
Mike Becker <universe@uap-core.de>
parents:
558
diff
changeset
|
42 | #include "hash_key.h" |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | #ifdef __cplusplus |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | extern "C" { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | #endif |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | /** Type for the UCX map. */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | typedef struct cx_map_s CxMap; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | /** Type for a map entry. */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | typedef struct cx_map_entry_s CxMapEntry; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | /** Type for map class definitions. */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | typedef struct cx_map_class_s cx_map_class; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | /** Structure for the UCX map. */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | struct cx_map_s { |
854
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
59 | /** |
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
60 | * Base attributes. |
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
61 | */ |
fe0d69d72bcd
fix members inherited by macro or include are not documented
Mike Becker <universe@uap-core.de>
parents:
853
diff
changeset
|
62 | CX_COLLECTION_BASE; |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
63 | /** The map class definition. */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | cx_map_class *cl; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
65 | }; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | /** |
709
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
68 | * The type of iterator for a map. |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
69 | */ |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
70 | enum cx_map_iterator_type { |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
71 | /** |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
72 | * Iterates over key/value pairs. |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
73 | */ |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
74 | CX_MAP_ITERATOR_PAIRS, |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
75 | /** |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
76 | * Iterates over keys only. |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
77 | */ |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
78 | CX_MAP_ITERATOR_KEYS, |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
79 | /** |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
80 | * Iterates over values only. |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
81 | */ |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
82 | CX_MAP_ITERATOR_VALUES |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
83 | }; |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
84 | |
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
85 | /** |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | * The class definition for arbitrary maps. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | struct cx_map_class_s { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | * Deallocates the entire memory. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
91 | */ |
993
b642eca4b956
make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents:
992
diff
changeset
|
92 | void (*deallocate)(struct cx_map_s *map); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
93 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
94 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
95 | * Removes all elements. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
96 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | void (*clear)(struct cx_map_s *map); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
98 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
99 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | * Add or overwrite an element. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
101 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
102 | int (*put)( |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | CxMap *map, |
563
69a83fad8a35
improve hash key handling
Mike Becker <universe@uap-core.de>
parents:
558
diff
changeset
|
104 | CxHashKey key, |
550
89b2a83728b1
#189 basic map implementation
Mike Becker <universe@uap-core.de>
parents:
549
diff
changeset
|
105 | void *value |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | ); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | * Returns an element. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | void *(*get)( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
112 | const CxMap *map, |
563
69a83fad8a35
improve hash key handling
Mike Becker <universe@uap-core.de>
parents:
558
diff
changeset
|
113 | CxHashKey key |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | ); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
116 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
117 | * Removes an element. |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
118 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
119 | * Implementations SHALL check if @p targetbuf is set and copy the elements |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
120 | * to the buffer without invoking any destructor. |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
121 | * When @p targetbuf is not set, the destructors SHALL be invoked. |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
122 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
123 | * The function SHALL return zero when the @p key was found and |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
124 | * non-zero, otherwise. |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
125 | */ |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
126 | int (*remove)( |
550
89b2a83728b1
#189 basic map implementation
Mike Becker <universe@uap-core.de>
parents:
549
diff
changeset
|
127 | CxMap *map, |
686
64919f63f059
add destructor functions for maps - fixes #253
Mike Becker <universe@uap-core.de>
parents:
685
diff
changeset
|
128 | CxHashKey key, |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
129 | void *targetbuf |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
130 | ); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
132 | /** |
709
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
133 | * Creates an iterator for this map. |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
134 | */ |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
135 | CxIterator (*iterator)(const CxMap *map, enum cx_map_iterator_type type); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
136 | }; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
137 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
138 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
139 | * A map entry. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
140 | */ |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | struct cx_map_entry_s { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | /** |
551
2946e13c89a4
#189 implement map iterators
Mike Becker <universe@uap-core.de>
parents:
550
diff
changeset
|
143 | * A pointer to the key. |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | */ |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
145 | const CxHashKey *key; |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | /** |
551
2946e13c89a4
#189 implement map iterators
Mike Becker <universe@uap-core.de>
parents:
550
diff
changeset
|
147 | * A pointer to the value. |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
148 | */ |
551
2946e13c89a4
#189 implement map iterators
Mike Becker <universe@uap-core.de>
parents:
550
diff
changeset
|
149 | void *value; |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
150 | }; |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | |
714
34565d898f1f
add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
152 | /** |
34565d898f1f
add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
153 | * A shared instance of an empty map. |
34565d898f1f
add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
154 | * |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
155 | * Writing to that map is not allowed. |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
156 | * |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
157 | * You can use this is a placeholder for initializing CxMap pointers |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
158 | * for which you do not want to reserve memory right from the beginning. |
714
34565d898f1f
add missing docs for cxEmptyMap
Mike Becker <universe@uap-core.de>
parents:
710
diff
changeset
|
159 | */ |
706
8c6edaccaef1
add empty map implementation - fixes #259
Mike Becker <universe@uap-core.de>
parents:
694
diff
changeset
|
160 | extern CxMap *const cxEmptyMap; |
8c6edaccaef1
add empty map implementation - fixes #259
Mike Becker <universe@uap-core.de>
parents:
694
diff
changeset
|
161 | |
658
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
162 | /** |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
163 | * Advises the map to store copies of the objects (default mode of operation). |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
164 | * |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
165 | * Retrieving objects from this map will yield pointers to the copies stored |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
166 | * within this list. |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
167 | * |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
168 | * @param map the map |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
169 | * @see cxMapStorePointers() |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
170 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
171 | cx_attr_nonnull |
658
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
172 | static inline void cxMapStoreObjects(CxMap *map) { |
856
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
173 | map->collection.store_pointer = false; |
658
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
174 | } |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
175 | |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
176 | /** |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
177 | * Advises the map to only store pointers to the objects. |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
178 | * |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
179 | * Retrieving objects from this list will yield the original pointers stored. |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
180 | * |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
181 | * @note This function forcibly sets the element size to the size of a pointer. |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
182 | * Invoking this function on a non-empty map that already stores copies of |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
183 | * objects is undefined. |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
184 | * |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
185 | * @param map the map |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
186 | * @see cxMapStoreObjects() |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
187 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
188 | cx_attr_nonnull |
658
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
189 | static inline void cxMapStorePointers(CxMap *map) { |
856
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
190 | map->collection.store_pointer = true; |
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
191 | map->collection.elem_size = sizeof(void *); |
658
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
192 | } |
56c62780582e
make hashmap store objects instead of pointers by default - fixes #239
Mike Becker <universe@uap-core.de>
parents:
630
diff
changeset
|
193 | |
857
4d12e34bb130
add missing convenience functions
Mike Becker <universe@uap-core.de>
parents:
856
diff
changeset
|
194 | /** |
4d12e34bb130
add missing convenience functions
Mike Becker <universe@uap-core.de>
parents:
856
diff
changeset
|
195 | * Returns true, if this map is storing pointers instead of the actual data. |
4d12e34bb130
add missing convenience functions
Mike Becker <universe@uap-core.de>
parents:
856
diff
changeset
|
196 | * |
4d12e34bb130
add missing convenience functions
Mike Becker <universe@uap-core.de>
parents:
856
diff
changeset
|
197 | * @param map |
4d12e34bb130
add missing convenience functions
Mike Becker <universe@uap-core.de>
parents:
856
diff
changeset
|
198 | * @return true, if this map is storing pointers |
4d12e34bb130
add missing convenience functions
Mike Becker <universe@uap-core.de>
parents:
856
diff
changeset
|
199 | * @see cxMapStorePointers() |
4d12e34bb130
add missing convenience functions
Mike Becker <universe@uap-core.de>
parents:
856
diff
changeset
|
200 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
201 | cx_attr_nonnull |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
202 | static inline bool cxMapIsStoringPointers(const CxMap *map) { |
857
4d12e34bb130
add missing convenience functions
Mike Becker <universe@uap-core.de>
parents:
856
diff
changeset
|
203 | return map->collection.store_pointer; |
4d12e34bb130
add missing convenience functions
Mike Becker <universe@uap-core.de>
parents:
856
diff
changeset
|
204 | } |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
205 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
206 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
207 | * Deallocates the memory of the specified map. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
208 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
209 | * Also calls the content destructor functions for each element, if specified. |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
210 | * |
993
b642eca4b956
make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents:
992
diff
changeset
|
211 | * @param map the map to be freed |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
212 | */ |
1109
89ec23988b88
free functions should not be inline in release mode - relates to #541
Mike Becker <universe@uap-core.de>
parents:
1102
diff
changeset
|
213 | void cxMapFree(CxMap *map); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
215 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
216 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
217 | * Clears a map by removing all elements. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
219 | * Also calls the content destructor functions for each element, if specified. |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
220 | * |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | * @param map the map to be cleared |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
222 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
223 | cx_attr_nonnull |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
224 | static inline void cxMapClear(CxMap *map) { |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
225 | map->cl->clear(map); |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
226 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
227 | |
856
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
228 | /** |
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
229 | * Returns the number of elements in this map. |
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
230 | * |
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
231 | * @param map the map |
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
232 | * @return the number of stored elements |
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
233 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
234 | cx_attr_nonnull |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
235 | static inline size_t cxMapSize(const CxMap *map) { |
856
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
236 | return map->collection.size; |
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
237 | } |
6bbbf219251d
fix name of collection base member (to avoid base.base)
Mike Becker <universe@uap-core.de>
parents:
855
diff
changeset
|
238 | |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
239 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
240 | * Creates a value iterator for a map. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
241 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
242 | * @note An iterator iterates over all elements successively. Therefore, the order |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
243 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
245 | * @param map the map to create the iterator for |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
246 | * @return an iterator for the currently stored values |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
247 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
248 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
249 | cx_attr_nodiscard |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
250 | static inline CxIterator cxMapIteratorValues(const CxMap *map) { |
709
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
251 | return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
252 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
253 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
254 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
255 | * Creates a key iterator for a map. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
256 | * |
564
5d8ad7a0ff71
fix obsolete documentation
Mike Becker <universe@uap-core.de>
parents:
563
diff
changeset
|
257 | * The elements of the iterator are keys of type CxHashKey. |
555
d79fbd028e26
fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents:
553
diff
changeset
|
258 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
259 | * @note An iterator iterates over all elements successively. Therefore, the order |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
260 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
261 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
262 | * @param map the map to create the iterator for |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
263 | * @return an iterator for the currently stored keys |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
264 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
265 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
266 | cx_attr_nodiscard |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
267 | static inline CxIterator cxMapIteratorKeys(const CxMap *map) { |
709
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
268 | return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
269 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
270 | |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
271 | /** |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
272 | * Creates an iterator for a map. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
273 | * |
555
d79fbd028e26
fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents:
553
diff
changeset
|
274 | * The elements of the iterator are key/value pairs of type CxMapEntry. |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
275 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
276 | * @note An iterator iterates over all elements successively. Therefore, the order |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
277 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
278 | * |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
279 | * @param map the map to create the iterator for |
555
d79fbd028e26
fix documentation for map iterators
Mike Becker <universe@uap-core.de>
parents:
553
diff
changeset
|
280 | * @return an iterator for the currently stored entries |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
281 | * @see cxMapIteratorKeys() |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
282 | * @see cxMapIteratorValues() |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
283 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
284 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
285 | cx_attr_nodiscard |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
286 | static inline CxIterator cxMapIterator(const CxMap *map) { |
709
1e8ba59e7911
simplify map class structure
Mike Becker <universe@uap-core.de>
parents:
706
diff
changeset
|
287 | return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
288 | } |
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
289 | |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
290 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
291 | /** |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
292 | * Creates a mutating iterator over the values of a map. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
293 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
294 | * @note An iterator iterates over all elements successively. Therefore, the order |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
295 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
296 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
297 | * @param map the map to create the iterator for |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
298 | * @return an iterator for the currently stored values |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
299 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
300 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
301 | cx_attr_nodiscard |
853
d4baf4dd55c3
simplify iterator structures
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
302 | CxIterator cxMapMutIteratorValues(CxMap *map); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
303 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
304 | /** |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
305 | * Creates a mutating iterator over the keys of a map. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
306 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
307 | * The elements of the iterator are keys of type CxHashKey. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
308 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
309 | * @note An iterator iterates over all elements successively. Therefore, the order |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
310 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
311 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
312 | * @param map the map to create the iterator for |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
313 | * @return an iterator for the currently stored keys |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
314 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
315 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
316 | cx_attr_nodiscard |
853
d4baf4dd55c3
simplify iterator structures
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
317 | CxIterator cxMapMutIteratorKeys(CxMap *map); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
318 | |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
319 | /** |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
320 | * Creates a mutating iterator for a map. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
321 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
322 | * The elements of the iterator are key/value pairs of type CxMapEntry. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
323 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
324 | * @note An iterator iterates over all elements successively. Therefore, the order |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
325 | * highly depends on the map implementation and may change arbitrarily when the contents change. |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
326 | * |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
327 | * @param map the map to create the iterator for |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
328 | * @return an iterator for the currently stored entries |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
329 | * @see cxMapMutIteratorKeys() |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
330 | * @see cxMapMutIteratorValues() |
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
331 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
332 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
333 | cx_attr_nodiscard |
853
d4baf4dd55c3
simplify iterator structures
Mike Becker <universe@uap-core.de>
parents:
759
diff
changeset
|
334 | CxIterator cxMapMutIterator(CxMap *map); |
630
ac5e7f789048
separate iterators and mutating iterators
Mike Becker <universe@uap-core.de>
parents:
564
diff
changeset
|
335 | |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
336 | #ifdef __cplusplus |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
337 | } // end the extern "C" block here, because we want to start overloading |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
338 | cx_attr_nonnull |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
339 | static inline int cxMapPut( |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
340 | CxMap *map, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
341 | CxHashKey const &key, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
342 | void *value |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
343 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
344 | return map->cl->put(map, key, value); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
345 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
346 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
347 | cx_attr_nonnull |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
348 | static inline int cxMapPut( |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
349 | CxMap *map, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
350 | cxstring const &key, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
351 | void *value |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
352 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
353 | return map->cl->put(map, cx_hash_key_cxstr(key), value); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
354 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
355 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
356 | cx_attr_nonnull |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
357 | static inline int cxMapPut( |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
358 | CxMap *map, |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
359 | cxmutstr const &key, |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
360 | void *value |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
361 | ) { |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
362 | return map->cl->put(map, cx_hash_key_cxstr(key), value); |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
363 | } |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
364 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
365 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
366 | cx_attr_cstr_arg(2) |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
367 | static inline int cxMapPut( |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
368 | CxMap *map, |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
369 | const char *key, |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
370 | void *value |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
371 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
372 | return map->cl->put(map, cx_hash_key_str(key), value); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
373 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
374 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
375 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
376 | cx_attr_nodiscard |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
377 | static inline void *cxMapGet( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
378 | const CxMap *map, |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
379 | CxHashKey const &key |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
380 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
381 | return map->cl->get(map, key); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
382 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
383 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
384 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
385 | cx_attr_nodiscard |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
386 | static inline void *cxMapGet( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
387 | const CxMap *map, |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
388 | cxstring const &key |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
389 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
390 | return map->cl->get(map, cx_hash_key_cxstr(key)); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
391 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
392 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
393 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
394 | cx_attr_nodiscard |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
395 | static inline void *cxMapGet( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
396 | const CxMap *map, |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
397 | cxmutstr const &key |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
398 | ) { |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
399 | return map->cl->get(map, cx_hash_key_cxstr(key)); |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
400 | } |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
401 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
402 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
403 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
404 | cx_attr_cstr_arg(2) |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
405 | static inline void *cxMapGet( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
406 | const CxMap *map, |
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
407 | const char *key |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
408 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
409 | return map->cl->get(map, cx_hash_key_str(key)); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
410 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
411 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
412 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
413 | static inline int cxMapRemove( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
414 | CxMap *map, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
415 | CxHashKey const &key |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
416 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
417 | return map->cl->remove(map, key, nullptr); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
418 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
419 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
420 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
421 | static inline int cxMapRemove( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
422 | CxMap *map, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
423 | cxstring const &key |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
424 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
425 | return map->cl->remove(map, cx_hash_key_cxstr(key), nullptr); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
426 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
427 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
428 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
429 | static inline int cxMapRemove( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
430 | CxMap *map, |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
431 | cxmutstr const &key |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
432 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
433 | return map->cl->remove(map, cx_hash_key_cxstr(key), nullptr); |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
434 | } |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
435 | |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
436 | cx_attr_nonnull |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
437 | cx_attr_cstr_arg(2) |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
438 | static inline int cxMapRemove( |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
439 | CxMap *map, |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
440 | const char *key |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
441 | ) { |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
442 | return map->cl->remove(map, cx_hash_key_str(key), nullptr); |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
443 | } |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
444 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
445 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
446 | cx_attr_access_w(3) |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
447 | static inline int cxMapRemoveAndGet( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
448 | CxMap *map, |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
449 | CxHashKey key, |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
450 | void *targetbuf |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
451 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
452 | return map->cl->remove(map, key, targetbuf); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
453 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
454 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
455 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
456 | cx_attr_access_w(3) |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
457 | static inline int cxMapRemoveAndGet( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
458 | CxMap *map, |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
459 | cxstring key, |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
460 | void *targetbuf |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
461 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
462 | return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
463 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
464 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
465 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
466 | cx_attr_access_w(3) |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
467 | static inline int cxMapRemoveAndGet( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
468 | CxMap *map, |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
469 | cxmutstr key, |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
470 | void *targetbuf |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
471 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
472 | return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
473 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
474 | |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
475 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
476 | cx_attr_access_w(3) |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
477 | cx_attr_cstr_arg(2) |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
478 | static inline int cxMapRemoveAndGet( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
479 | CxMap *map, |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
480 | const char *key, |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
481 | void *targetbuf |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
482 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
483 | return map->cl->remove(map, cx_hash_key_str(key), targetbuf); |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
484 | } |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
485 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
486 | #else // __cplusplus |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
487 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
488 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
489 | * @copydoc cxMapPut() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
490 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
491 | cx_attr_nonnull |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
492 | static inline int cx_map_put( |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
493 | CxMap *map, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
494 | CxHashKey key, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
495 | void *value |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
496 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
497 | return map->cl->put(map, key, value); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
498 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
499 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
500 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
501 | * @copydoc cxMapPut() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
502 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
503 | cx_attr_nonnull |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
504 | static inline int cx_map_put_cxstr( |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
505 | CxMap *map, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
506 | cxstring key, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
507 | void *value |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
508 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
509 | return map->cl->put(map, cx_hash_key_cxstr(key), value); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
510 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
511 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
512 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
513 | * @copydoc cxMapPut() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
514 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
515 | cx_attr_nonnull |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
516 | static inline int cx_map_put_mustr( |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
517 | CxMap *map, |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
518 | cxmutstr key, |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
519 | void *value |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
520 | ) { |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
521 | return map->cl->put(map, cx_hash_key_cxstr(key), value); |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
522 | } |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
523 | |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
524 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
525 | * @copydoc cxMapPut() |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
526 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
527 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
528 | cx_attr_cstr_arg(2) |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
529 | static inline int cx_map_put_str( |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
530 | CxMap *map, |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
531 | const char *key, |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
532 | void *value |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
533 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
534 | return map->cl->put(map, cx_hash_key_str(key), value); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
535 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
536 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
537 | /** |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
538 | * Puts a key/value-pair into the map. |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
539 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
540 | * A possible existing value will be overwritten. |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
541 | * |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
542 | * If this map is storing pointers, the @p value pointer is written |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
543 | * to the map. Otherwise, the memory is copied from @p value with |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
544 | * memcpy(). |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
545 | * |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
546 | * The @p key is always copied. |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
547 | * |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
548 | * @param map (@c CxMap*) the map |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
549 | * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
550 | * @param value (@c void*) the value |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
551 | * @retval zero success |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
552 | * @retval non-zero value on memory allocation failure |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
553 | */ |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
554 | #define cxMapPut(map, key, value) _Generic((key), \ |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
555 | CxHashKey: cx_map_put, \ |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
556 | cxstring: cx_map_put_cxstr, \ |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
557 | cxmutstr: cx_map_put_mustr, \ |
694
ac827d873c17
fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents:
692
diff
changeset
|
558 | char*: cx_map_put_str, \ |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
559 | const char*: cx_map_put_str) \ |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
560 | (map, key, value) |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
561 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
562 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
563 | * @copydoc cxMapGet() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
564 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
565 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
566 | cx_attr_nodiscard |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
567 | static inline void *cx_map_get( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
568 | const CxMap *map, |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
569 | CxHashKey key |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
570 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
571 | return map->cl->get(map, key); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
572 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
573 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
574 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
575 | * @copydoc cxMapGet() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
576 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
577 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
578 | cx_attr_nodiscard |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
579 | static inline void *cx_map_get_cxstr( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
580 | const CxMap *map, |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
581 | cxstring key |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
582 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
583 | return map->cl->get(map, cx_hash_key_cxstr(key)); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
584 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
585 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
586 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
587 | * @copydoc cxMapGet() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
588 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
589 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
590 | cx_attr_nodiscard |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
591 | static inline void *cx_map_get_mustr( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
592 | const CxMap *map, |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
593 | cxmutstr key |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
594 | ) { |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
595 | return map->cl->get(map, cx_hash_key_cxstr(key)); |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
596 | } |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
597 | |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
598 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
599 | * @copydoc cxMapGet() |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
600 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
601 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
602 | cx_attr_nodiscard |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
603 | cx_attr_cstr_arg(2) |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
604 | static inline void *cx_map_get_str( |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
605 | const CxMap *map, |
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
606 | const char *key |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
607 | ) { |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
608 | return map->cl->get(map, cx_hash_key_str(key)); |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
609 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
610 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
611 | /** |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
612 | * Retrieves a value by using a key. |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
613 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
614 | * If this map is storing pointers, the stored pointer is returned. |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
615 | * Otherwise, a pointer to the element within the map's memory |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
616 | * is returned (which is valid as long as the element stays in the map). |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
617 | * |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
618 | * @param map (@c CxMap*) the map |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
619 | * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
620 | * @return (@c void*) the value |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
621 | */ |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
622 | #define cxMapGet(map, key) _Generic((key), \ |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
623 | CxHashKey: cx_map_get, \ |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
624 | cxstring: cx_map_get_cxstr, \ |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
625 | cxmutstr: cx_map_get_mustr, \ |
694
ac827d873c17
fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents:
692
diff
changeset
|
626 | char*: cx_map_get_str, \ |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
627 | const char*: cx_map_get_str) \ |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
628 | (map, key) |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
629 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
630 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
631 | * @copydoc cxMapRemove() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
632 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
633 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
634 | static inline int cx_map_remove( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
635 | CxMap *map, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
636 | CxHashKey key |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
637 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
638 | return map->cl->remove(map, key, NULL); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
639 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
640 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
641 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
642 | * @copydoc cxMapRemove() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
643 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
644 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
645 | static inline int cx_map_remove_cxstr( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
646 | CxMap *map, |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
647 | cxstring key |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
648 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
649 | return map->cl->remove(map, cx_hash_key_cxstr(key), NULL); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
650 | } |
549
d7f0b5a9a985
#189 declare basic map functions
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
651 | |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
652 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
653 | * @copydoc cxMapRemove() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
654 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
655 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
656 | static inline int cx_map_remove_mustr( |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
657 | CxMap *map, |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
658 | cxmutstr key |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
659 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
660 | return map->cl->remove(map, cx_hash_key_cxstr(key), NULL); |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
661 | } |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
662 | |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
663 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
664 | * @copydoc cxMapRemove() |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
665 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
666 | cx_attr_nonnull |
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
667 | cx_attr_cstr_arg(2) |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
668 | static inline int cx_map_remove_str( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
669 | CxMap *map, |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
670 | const char *key |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
671 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
672 | return map->cl->remove(map, cx_hash_key_str(key), NULL); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
673 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
674 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
675 | /** |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
676 | * Removes a key/value-pair from the map by using the key. |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
677 | * |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
678 | * Always invokes the destructors functions, if any, on the removed element. |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
679 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
680 | * @param map (@c CxMap*) the map |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
681 | * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
682 | * @retval zero success |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
683 | * @retval non-zero the key was not found |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
684 | * |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
685 | * @see cxMapRemoveAndGet() |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
686 | */ |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
687 | #define cxMapRemove(map, key) _Generic((key), \ |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
688 | CxHashKey: cx_map_remove, \ |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
689 | cxstring: cx_map_remove_cxstr, \ |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
690 | cxmutstr: cx_map_remove_mustr, \ |
694
ac827d873c17
fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents:
692
diff
changeset
|
691 | char*: cx_map_remove_str, \ |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
692 | const char*: cx_map_remove_str) \ |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
693 | (map, key) |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
694 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
695 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
696 | * @copydoc cxMapRemoveAndGet() |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
697 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
698 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
699 | cx_attr_access_w(3) |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
700 | static inline int cx_map_remove_and_get( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
701 | CxMap *map, |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
702 | CxHashKey key, |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
703 | void *targetbuf |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
704 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
705 | return map->cl->remove(map, key, targetbuf); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
706 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
707 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
708 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
709 | * @copydoc cxMapRemoveAndGet() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
710 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
711 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
712 | cx_attr_access_w(3) |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
713 | static inline int cx_map_remove_and_get_cxstr( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
714 | CxMap *map, |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
715 | cxstring key, |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
716 | void *targetbuf |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
717 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
718 | return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
719 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
720 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
721 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
722 | * @copydoc cxMapRemoveAndGet() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
723 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
724 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
725 | cx_attr_access_w(3) |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
726 | static inline int cx_map_remove_and_get_mustr( |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
727 | CxMap *map, |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
728 | cxmutstr key, |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
729 | void *targetbuf |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
730 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
731 | return map->cl->remove(map, cx_hash_key_cxstr(key), targetbuf); |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
732 | } |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
733 | |
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
734 | /** |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
735 | * @copydoc cxMapRemoveAndGet() |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
736 | */ |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
737 | cx_attr_nonnull |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
738 | cx_attr_access_w(3) |
985
68754c7de906
major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents:
984
diff
changeset
|
739 | cx_attr_cstr_arg(2) |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
740 | static inline int cx_map_remove_and_get_str( |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
741 | CxMap *map, |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
742 | const char *key, |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
743 | void *targetbuf |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
744 | ) { |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
745 | return map->cl->remove(map, cx_hash_key_str(key), targetbuf); |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
746 | } |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
747 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
748 | /** |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
749 | * Removes a key/value-pair from the map by using the key. |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
750 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
751 | * This function will copy the contents of the removed element |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
752 | * to the target buffer must be guaranteed to be large enough |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
753 | * to hold the element (the map's element size). |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
754 | * The destructor functions, if any, will @em not be called. |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
755 | * |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
756 | * If this map is storing pointers, the element is the pointer itself |
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
757 | * and not the object it points to. |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
758 | * |
1102
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
759 | * @param map (@c CxMap*) the map |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
760 | * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
761 | * @param targetbuf (@c void*) the buffer where the element shall be copied to |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
762 | * @retval zero success |
db5e355e5349
refine docs for map.h - issue #548
Mike Becker <universe@uap-core.de>
parents:
994
diff
changeset
|
763 | * @retval non-zero the key was not found |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
764 | * |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
765 | * @see cxMapStorePointers() |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
766 | * @see cxMapRemove() |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
767 | */ |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
768 | #define cxMapRemoveAndGet(map, key, targetbuf) _Generic((key), \ |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
769 | CxHashKey: cx_map_remove_and_get, \ |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
770 | cxstring: cx_map_remove_and_get_cxstr, \ |
692
6ac92936cd44
add cxmutstr to the map generics
Mike Becker <universe@uap-core.de>
parents:
691
diff
changeset
|
771 | cxmutstr: cx_map_remove_and_get_mustr, \ |
694
ac827d873c17
fix missing controlling-expression for char const*
Mike Becker <universe@uap-core.de>
parents:
692
diff
changeset
|
772 | char*: cx_map_remove_and_get_str, \ |
890
54565fd74e74
move all const keywords to the west - fixes #426
Mike Becker <universe@uap-core.de>
parents:
857
diff
changeset
|
773 | const char*: cx_map_remove_and_get_str) \ |
994
3603bdf4a78b
remove map detach function - fixes #487
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
774 | (map, key, targetbuf) |
691
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
775 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
776 | #endif // __cplusplus |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
777 | |
65baf7f45ac8
bring a generic interface to CxMap
Mike Becker <universe@uap-core.de>
parents:
689
diff
changeset
|
778 | #endif // UCX_MAP_H |