| 61 cx_map_class *cl; |
61 cx_map_class *cl; |
| 62 /** An allocator that is used for the map elements. */ |
62 /** An allocator that is used for the map elements. */ |
| 63 CxAllocator *allocator; |
63 CxAllocator *allocator; |
| 64 /** The number of elements currently stored. */ |
64 /** The number of elements currently stored. */ |
| 65 size_t size; |
65 size_t size; |
| 66 // TODO: elemsize + a flag if values shall be copied to the map |
66 /** |
| |
67 * The size of an element. |
| |
68 */ |
| |
69 size_t itemsize; |
| |
70 /** |
| |
71 * True, if this map shall store pointers instead |
| |
72 * of copies of objects. |
| |
73 */ |
| |
74 bool store_pointers; |
| 67 }; |
75 }; |
| 68 |
76 |
| 69 /** |
77 /** |
| 70 * The class definition for arbitrary maps. |
78 * The class definition for arbitrary maps. |
| 71 */ |
79 */ |
| 159 * A pointer to the value. |
167 * A pointer to the value. |
| 160 */ |
168 */ |
| 161 void *value; |
169 void *value; |
| 162 }; |
170 }; |
| 163 |
171 |
| |
172 /** |
| |
173 * Advises the map to store copies of the objects (default mode of operation). |
| |
174 * |
| |
175 * Retrieving objects from this map will yield pointers to the copies stored |
| |
176 * within this list. |
| |
177 * |
| |
178 * @param map the map |
| |
179 * @see cxMapStorePointers() |
| |
180 */ |
| |
181 __attribute__((__nonnull__)) |
| |
182 static inline void cxMapStoreObjects(CxMap *map) { |
| |
183 map->store_pointers = false; |
| |
184 } |
| |
185 |
| |
186 /** |
| |
187 * Advises the map to only store pointers to the objects. |
| |
188 * |
| |
189 * Retrieving objects from this list will yield the original pointers stored. |
| |
190 * |
| |
191 * @note This function forcibly sets the element size to the size of a pointer. |
| |
192 * Invoking this function on a non-empty map that already stores copies of |
| |
193 * objects is undefined. |
| |
194 * |
| |
195 * @param map the map |
| |
196 * @see cxMapStoreObjects() |
| |
197 */ |
| |
198 __attribute__((__nonnull__)) |
| |
199 static inline void cxMapStorePointers(CxMap *map) { |
| |
200 map->store_pointers = true; |
| |
201 map->itemsize = sizeof(void *); |
| |
202 } |
| |
203 |
| 164 |
204 |
| 165 /** |
205 /** |
| 166 * Deallocates the memory of the specified map. |
206 * Deallocates the memory of the specified map. |
| 167 * |
207 * |
| 168 * @param map the map to be destroyed |
208 * @param map the map to be destroyed |
| 219 /** |
259 /** |
| 220 * Removes a key/value-pair from the map by using the key. |
260 * Removes a key/value-pair from the map by using the key. |
| 221 * |
261 * |
| 222 * @param map the map |
262 * @param map the map |
| 223 * @param key the key |
263 * @param key the key |
| 224 * @return the removed value |
264 * @return if this map is storing pointers, the removed value, \c NULL otherwise |
| |
265 * @see cxMapStorePointers() |
| 225 */ |
266 */ |
| 226 __attribute__((__nonnull__, __warn_unused_result__)) |
267 __attribute__((__nonnull__, __warn_unused_result__)) |
| 227 static inline void *cxMapRemove( |
268 static inline void *cxMapRemove( |
| 228 CxMap *map, |
269 CxMap *map, |
| 229 CxHashKey key |
270 CxHashKey key |