1.1 --- a/src/cx/map.h Sun May 21 14:56:10 2023 +0200 1.2 +++ b/src/cx/map.h Sun May 21 15:07:31 2023 +0200 1.3 @@ -63,6 +63,24 @@ 1.4 }; 1.5 1.6 /** 1.7 + * The type of iterator for a map. 1.8 + */ 1.9 +enum cx_map_iterator_type { 1.10 + /** 1.11 + * Iterates over key/value pairs. 1.12 + */ 1.13 + CX_MAP_ITERATOR_PAIRS, 1.14 + /** 1.15 + * Iterates over keys only. 1.16 + */ 1.17 + CX_MAP_ITERATOR_KEYS, 1.18 + /** 1.19 + * Iterates over values only. 1.20 + */ 1.21 + CX_MAP_ITERATOR_VALUES 1.22 +}; 1.23 + 1.24 +/** 1.25 * The class definition for arbitrary maps. 1.26 */ 1.27 struct cx_map_class_s { 1.28 @@ -108,40 +126,10 @@ 1.29 ); 1.30 1.31 /** 1.32 - * Iterator over the key/value pairs. 1.33 + * Creates an iterator for this map. 1.34 */ 1.35 __attribute__((__nonnull__, __warn_unused_result__)) 1.36 - CxIterator (*iterator)(CxMap const *map); 1.37 - 1.38 - /** 1.39 - * Iterator over the keys. 1.40 - */ 1.41 - __attribute__((__nonnull__, __warn_unused_result__)) 1.42 - CxIterator (*iterator_keys)(CxMap const *map); 1.43 - 1.44 - /** 1.45 - * Iterator over the values. 1.46 - */ 1.47 - __attribute__((__nonnull__, __warn_unused_result__)) 1.48 - CxIterator (*iterator_values)(CxMap const *map); 1.49 - 1.50 - /** 1.51 - * Mutating iterator over the key/value pairs. 1.52 - */ 1.53 - __attribute__((__nonnull__, __warn_unused_result__)) 1.54 - CxMutIterator (*mut_iterator)(CxMap *map); 1.55 - 1.56 - /** 1.57 - * Mutating iterator over the keys. 1.58 - */ 1.59 - __attribute__((__nonnull__, __warn_unused_result__)) 1.60 - CxMutIterator (*mut_iterator_keys)(CxMap *map); 1.61 - 1.62 - /** 1.63 - * Mutating iterator over the values. 1.64 - */ 1.65 - __attribute__((__nonnull__, __warn_unused_result__)) 1.66 - CxMutIterator (*mut_iterator_values)(CxMap *map); 1.67 + CxIterator (*iterator)(CxMap const *map, enum cx_map_iterator_type type); 1.68 }; 1.69 1.70 /** 1.71 @@ -228,7 +216,7 @@ 1.72 */ 1.73 __attribute__((__nonnull__, __warn_unused_result__)) 1.74 static inline CxIterator cxMapIteratorValues(CxMap *map) { 1.75 - return map->cl->iterator_values(map); 1.76 + return map->cl->iterator(map, CX_MAP_ITERATOR_VALUES); 1.77 } 1.78 1.79 /** 1.80 @@ -244,7 +232,7 @@ 1.81 */ 1.82 __attribute__((__nonnull__, __warn_unused_result__)) 1.83 static inline CxIterator cxMapIteratorKeys(CxMap *map) { 1.84 - return map->cl->iterator_keys(map); 1.85 + return map->cl->iterator(map, CX_MAP_ITERATOR_KEYS); 1.86 } 1.87 1.88 /** 1.89 @@ -262,7 +250,7 @@ 1.90 */ 1.91 __attribute__((__nonnull__, __warn_unused_result__)) 1.92 static inline CxIterator cxMapIterator(CxMap *map) { 1.93 - return map->cl->iterator(map); 1.94 + return map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS); 1.95 } 1.96 1.97 1.98 @@ -276,9 +264,7 @@ 1.99 * @return an iterator for the currently stored values 1.100 */ 1.101 __attribute__((__nonnull__, __warn_unused_result__)) 1.102 -static inline CxMutIterator cxMapMutIteratorValues(CxMap *map) { 1.103 - return map->cl->mut_iterator_values(map); 1.104 -} 1.105 +CxMutIterator cxMapMutIteratorValues(CxMap *map); 1.106 1.107 /** 1.108 * Creates a mutating iterator over the keys of a map. 1.109 @@ -292,9 +278,7 @@ 1.110 * @return an iterator for the currently stored keys 1.111 */ 1.112 __attribute__((__nonnull__, __warn_unused_result__)) 1.113 -static inline CxMutIterator cxMapMutIteratorKeys(CxMap *map) { 1.114 - return map->cl->mut_iterator_keys(map); 1.115 -} 1.116 +CxMutIterator cxMapMutIteratorKeys(CxMap *map); 1.117 1.118 /** 1.119 * Creates a mutating iterator for a map. 1.120 @@ -310,9 +294,7 @@ 1.121 * @see cxMapMutIteratorValues() 1.122 */ 1.123 __attribute__((__nonnull__, __warn_unused_result__)) 1.124 -static inline CxMutIterator cxMapMutIterator(CxMap *map) { 1.125 - return map->cl->mut_iterator(map); 1.126 -} 1.127 +CxMutIterator cxMapMutIterator(CxMap *map); 1.128 1.129 #ifdef __cplusplus 1.130 } // end the extern "C" block here, because we want to start overloading