61 /** The map class definition. */ |
61 /** The map class definition. */ |
62 cx_map_class *cl; |
62 cx_map_class *cl; |
63 }; |
63 }; |
64 |
64 |
65 /** |
65 /** |
|
66 * The type of iterator for a map. |
|
67 */ |
|
68 enum cx_map_iterator_type { |
|
69 /** |
|
70 * Iterates over key/value pairs. |
|
71 */ |
|
72 CX_MAP_ITERATOR_PAIRS, |
|
73 /** |
|
74 * Iterates over keys only. |
|
75 */ |
|
76 CX_MAP_ITERATOR_KEYS, |
|
77 /** |
|
78 * Iterates over values only. |
|
79 */ |
|
80 CX_MAP_ITERATOR_VALUES |
|
81 }; |
|
82 |
|
83 /** |
66 * The class definition for arbitrary maps. |
84 * The class definition for arbitrary maps. |
67 */ |
85 */ |
68 struct cx_map_class_s { |
86 struct cx_map_class_s { |
69 /** |
87 /** |
70 * Deallocates the entire memory. |
88 * Deallocates the entire memory. |
106 CxHashKey key, |
124 CxHashKey key, |
107 bool destroy |
125 bool destroy |
108 ); |
126 ); |
109 |
127 |
110 /** |
128 /** |
111 * Iterator over the key/value pairs. |
129 * Creates an iterator for this map. |
112 */ |
130 */ |
113 __attribute__((__nonnull__, __warn_unused_result__)) |
131 __attribute__((__nonnull__, __warn_unused_result__)) |
114 CxIterator (*iterator)(CxMap const *map); |
132 CxIterator (*iterator)(CxMap const *map, enum cx_map_iterator_type type); |
115 |
|
116 /** |
|
117 * Iterator over the keys. |
|
118 */ |
|
119 __attribute__((__nonnull__, __warn_unused_result__)) |
|
120 CxIterator (*iterator_keys)(CxMap const *map); |
|
121 |
|
122 /** |
|
123 * Iterator over the values. |
|
124 */ |
|
125 __attribute__((__nonnull__, __warn_unused_result__)) |
|
126 CxIterator (*iterator_values)(CxMap const *map); |
|
127 |
|
128 /** |
|
129 * Mutating iterator over the key/value pairs. |
|
130 */ |
|
131 __attribute__((__nonnull__, __warn_unused_result__)) |
|
132 CxMutIterator (*mut_iterator)(CxMap *map); |
|
133 |
|
134 /** |
|
135 * Mutating iterator over the keys. |
|
136 */ |
|
137 __attribute__((__nonnull__, __warn_unused_result__)) |
|
138 CxMutIterator (*mut_iterator_keys)(CxMap *map); |
|
139 |
|
140 /** |
|
141 * Mutating iterator over the values. |
|
142 */ |
|
143 __attribute__((__nonnull__, __warn_unused_result__)) |
|
144 CxMutIterator (*mut_iterator_values)(CxMap *map); |
|
145 }; |
133 }; |
146 |
134 |
147 /** |
135 /** |
148 * A map entry. |
136 * A map entry. |
149 */ |
137 */ |
223 * |
218 * |
224 * @param map the map to create the iterator for |
219 * @param map the map to create the iterator for |
225 * @return an iterator for the currently stored values |
220 * @return an iterator for the currently stored values |
226 */ |
221 */ |
227 __attribute__((__nonnull__, __warn_unused_result__)) |
222 __attribute__((__nonnull__, __warn_unused_result__)) |
228 static inline CxIterator cxMapIteratorValues(CxMap *map) { |
223 static inline CxIterator cxMapIteratorValues(CxMap const *map) { |
229 return map->cl->iterator_values(map); |
224 return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES); |
230 } |
225 } |
231 |
226 |
232 /** |
227 /** |
233 * Creates a key iterator for a map. |
228 * Creates a key iterator for a map. |
234 * |
229 * |
239 * |
234 * |
240 * @param map the map to create the iterator for |
235 * @param map the map to create the iterator for |
241 * @return an iterator for the currently stored keys |
236 * @return an iterator for the currently stored keys |
242 */ |
237 */ |
243 __attribute__((__nonnull__, __warn_unused_result__)) |
238 __attribute__((__nonnull__, __warn_unused_result__)) |
244 static inline CxIterator cxMapIteratorKeys(CxMap *map) { |
239 static inline CxIterator cxMapIteratorKeys(CxMap const *map) { |
245 return map->cl->iterator_keys(map); |
240 return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS); |
246 } |
241 } |
247 |
242 |
248 /** |
243 /** |
249 * Creates an iterator for a map. |
244 * Creates an iterator for a map. |
250 * |
245 * |
257 * @return an iterator for the currently stored entries |
252 * @return an iterator for the currently stored entries |
258 * @see cxMapIteratorKeys() |
253 * @see cxMapIteratorKeys() |
259 * @see cxMapIteratorValues() |
254 * @see cxMapIteratorValues() |
260 */ |
255 */ |
261 __attribute__((__nonnull__, __warn_unused_result__)) |
256 __attribute__((__nonnull__, __warn_unused_result__)) |
262 static inline CxIterator cxMapIterator(CxMap *map) { |
257 static inline CxIterator cxMapIterator(CxMap const *map) { |
263 return map->cl->iterator(map); |
258 return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS); |
264 } |
259 } |
265 |
260 |
266 |
261 |
267 /** |
262 /** |
268 * Creates a mutating iterator over the values of a map. |
263 * Creates a mutating iterator over the values of a map. |
272 * |
267 * |
273 * @param map the map to create the iterator for |
268 * @param map the map to create the iterator for |
274 * @return an iterator for the currently stored values |
269 * @return an iterator for the currently stored values |
275 */ |
270 */ |
276 __attribute__((__nonnull__, __warn_unused_result__)) |
271 __attribute__((__nonnull__, __warn_unused_result__)) |
277 static inline CxMutIterator cxMapMutIteratorValues(CxMap *map) { |
272 CxMutIterator cxMapMutIteratorValues(CxMap *map); |
278 return map->cl->mut_iterator_values(map); |
|
279 } |
|
280 |
273 |
281 /** |
274 /** |
282 * Creates a mutating iterator over the keys of a map. |
275 * Creates a mutating iterator over the keys of a map. |
283 * |
276 * |
284 * The elements of the iterator are keys of type CxHashKey. |
277 * The elements of the iterator are keys of type CxHashKey. |
288 * |
281 * |
289 * @param map the map to create the iterator for |
282 * @param map the map to create the iterator for |
290 * @return an iterator for the currently stored keys |
283 * @return an iterator for the currently stored keys |
291 */ |
284 */ |
292 __attribute__((__nonnull__, __warn_unused_result__)) |
285 __attribute__((__nonnull__, __warn_unused_result__)) |
293 static inline CxMutIterator cxMapMutIteratorKeys(CxMap *map) { |
286 CxMutIterator cxMapMutIteratorKeys(CxMap *map); |
294 return map->cl->mut_iterator_keys(map); |
|
295 } |
|
296 |
287 |
297 /** |
288 /** |
298 * Creates a mutating iterator for a map. |
289 * Creates a mutating iterator for a map. |
299 * |
290 * |
300 * The elements of the iterator are key/value pairs of type CxMapEntry. |
291 * The elements of the iterator are key/value pairs of type CxMapEntry. |
306 * @return an iterator for the currently stored entries |
297 * @return an iterator for the currently stored entries |
307 * @see cxMapMutIteratorKeys() |
298 * @see cxMapMutIteratorKeys() |
308 * @see cxMapMutIteratorValues() |
299 * @see cxMapMutIteratorValues() |
309 */ |
300 */ |
310 __attribute__((__nonnull__, __warn_unused_result__)) |
301 __attribute__((__nonnull__, __warn_unused_result__)) |
311 static inline CxMutIterator cxMapMutIterator(CxMap *map) { |
302 CxMutIterator cxMapMutIterator(CxMap *map); |
312 return map->cl->mut_iterator(map); |
|
313 } |
|
314 |
303 |
315 #ifdef __cplusplus |
304 #ifdef __cplusplus |
316 } // end the extern "C" block here, because we want to start overloading |
305 } // end the extern "C" block here, because we want to start overloading |
317 |
306 |
318 /** |
307 /** |