src/cx/map.h

changeset 709
1e8ba59e7911
parent 706
8c6edaccaef1
child 710
2dd409ed056f
equal deleted inserted replaced
708:1caed6c9ba68 709:1e8ba59e7911
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 */
226 * @param map the map to create the iterator for 214 * @param map the map to create the iterator for
227 * @return an iterator for the currently stored values 215 * @return an iterator for the currently stored values
228 */ 216 */
229 __attribute__((__nonnull__, __warn_unused_result__)) 217 __attribute__((__nonnull__, __warn_unused_result__))
230 static inline CxIterator cxMapIteratorValues(CxMap *map) { 218 static inline CxIterator cxMapIteratorValues(CxMap *map) {
231 return map->cl->iterator_values(map); 219 return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);
232 } 220 }
233 221
234 /** 222 /**
235 * Creates a key iterator for a map. 223 * Creates a key iterator for a map.
236 * 224 *
242 * @param map the map to create the iterator for 230 * @param map the map to create the iterator for
243 * @return an iterator for the currently stored keys 231 * @return an iterator for the currently stored keys
244 */ 232 */
245 __attribute__((__nonnull__, __warn_unused_result__)) 233 __attribute__((__nonnull__, __warn_unused_result__))
246 static inline CxIterator cxMapIteratorKeys(CxMap *map) { 234 static inline CxIterator cxMapIteratorKeys(CxMap *map) {
247 return map->cl->iterator_keys(map); 235 return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);
248 } 236 }
249 237
250 /** 238 /**
251 * Creates an iterator for a map. 239 * Creates an iterator for a map.
252 * 240 *
260 * @see cxMapIteratorKeys() 248 * @see cxMapIteratorKeys()
261 * @see cxMapIteratorValues() 249 * @see cxMapIteratorValues()
262 */ 250 */
263 __attribute__((__nonnull__, __warn_unused_result__)) 251 __attribute__((__nonnull__, __warn_unused_result__))
264 static inline CxIterator cxMapIterator(CxMap *map) { 252 static inline CxIterator cxMapIterator(CxMap *map) {
265 return map->cl->iterator(map); 253 return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);
266 } 254 }
267 255
268 256
269 /** 257 /**
270 * Creates a mutating iterator over the values of a map. 258 * Creates a mutating iterator over the values of a map.
274 * 262 *
275 * @param map the map to create the iterator for 263 * @param map the map to create the iterator for
276 * @return an iterator for the currently stored values 264 * @return an iterator for the currently stored values
277 */ 265 */
278 __attribute__((__nonnull__, __warn_unused_result__)) 266 __attribute__((__nonnull__, __warn_unused_result__))
279 static inline CxMutIterator cxMapMutIteratorValues(CxMap *map) { 267 CxMutIterator cxMapMutIteratorValues(CxMap *map);
280 return map->cl->mut_iterator_values(map);
281 }
282 268
283 /** 269 /**
284 * Creates a mutating iterator over the keys of a map. 270 * Creates a mutating iterator over the keys of a map.
285 * 271 *
286 * The elements of the iterator are keys of type CxHashKey. 272 * The elements of the iterator are keys of type CxHashKey.
290 * 276 *
291 * @param map the map to create the iterator for 277 * @param map the map to create the iterator for
292 * @return an iterator for the currently stored keys 278 * @return an iterator for the currently stored keys
293 */ 279 */
294 __attribute__((__nonnull__, __warn_unused_result__)) 280 __attribute__((__nonnull__, __warn_unused_result__))
295 static inline CxMutIterator cxMapMutIteratorKeys(CxMap *map) { 281 CxMutIterator cxMapMutIteratorKeys(CxMap *map);
296 return map->cl->mut_iterator_keys(map);
297 }
298 282
299 /** 283 /**
300 * Creates a mutating iterator for a map. 284 * Creates a mutating iterator for a map.
301 * 285 *
302 * The elements of the iterator are key/value pairs of type CxMapEntry. 286 * The elements of the iterator are key/value pairs of type CxMapEntry.
308 * @return an iterator for the currently stored entries 292 * @return an iterator for the currently stored entries
309 * @see cxMapMutIteratorKeys() 293 * @see cxMapMutIteratorKeys()
310 * @see cxMapMutIteratorValues() 294 * @see cxMapMutIteratorValues()
311 */ 295 */
312 __attribute__((__nonnull__, __warn_unused_result__)) 296 __attribute__((__nonnull__, __warn_unused_result__))
313 static inline CxMutIterator cxMapMutIterator(CxMap *map) { 297 CxMutIterator cxMapMutIterator(CxMap *map);
314 return map->cl->mut_iterator(map);
315 }
316 298
317 #ifdef __cplusplus 299 #ifdef __cplusplus
318 } // end the extern "C" block here, because we want to start overloading 300 } // end the extern "C" block here, because we want to start overloading
319 301
320 /** 302 /**

mercurial