158 * for which you do not want to reserve memory right from the beginning. |
158 * for which you do not want to reserve memory right from the beginning. |
159 */ |
159 */ |
160 extern CxMap *const cxEmptyMap; |
160 extern CxMap *const cxEmptyMap; |
161 |
161 |
162 /** |
162 /** |
163 * Advises the map to store copies of the objects (default mode of operation). |
|
164 * |
|
165 * Retrieving objects from this map will yield pointers to the copies stored |
|
166 * within this list. |
|
167 * |
|
168 * @param map the map |
|
169 * @see cxMapStorePointers() |
|
170 */ |
|
171 cx_attr_nonnull |
|
172 static inline void cxMapStoreObjects(CxMap *map) { |
|
173 map->collection.store_pointer = false; |
|
174 } |
|
175 |
|
176 /** |
|
177 * Advises the map to only store pointers to the objects. |
|
178 * |
|
179 * Retrieving objects from this list will yield the original pointers stored. |
|
180 * |
|
181 * @note This function forcibly sets the element size to the size of a pointer. |
|
182 * Invoking this function on a non-empty map that already stores copies of |
|
183 * objects is undefined. |
|
184 * |
|
185 * @param map the map |
|
186 * @see cxMapStoreObjects() |
|
187 */ |
|
188 cx_attr_nonnull |
|
189 static inline void cxMapStorePointers(CxMap *map) { |
|
190 map->collection.store_pointer = true; |
|
191 map->collection.elem_size = sizeof(void *); |
|
192 } |
|
193 |
|
194 /** |
|
195 * Returns true, if this map is storing pointers instead of the actual data. |
|
196 * |
|
197 * @param map |
|
198 * @return true, if this map is storing pointers |
|
199 * @see cxMapStorePointers() |
|
200 */ |
|
201 cx_attr_nonnull |
|
202 static inline bool cxMapIsStoringPointers(const CxMap *map) { |
|
203 return map->collection.store_pointer; |
|
204 } |
|
205 |
|
206 /** |
|
207 * Deallocates the memory of the specified map. |
163 * Deallocates the memory of the specified map. |
208 * |
164 * |
209 * Also calls the content destructor functions for each element, if specified. |
165 * Also calls the content destructor functions for each element, if specified. |
210 * |
166 * |
211 * @param map the map to be freed |
167 * @param map the map to be freed |
759 * @param map (@c CxMap*) the map |
715 * @param map (@c CxMap*) the map |
760 * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key |
716 * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key |
761 * @param targetbuf (@c void*) the buffer where the element shall be copied to |
717 * @param targetbuf (@c void*) the buffer where the element shall be copied to |
762 * @retval zero success |
718 * @retval zero success |
763 * @retval non-zero the key was not found |
719 * @retval non-zero the key was not found |
764 * |
720 * |
765 * @see cxMapStorePointers() |
|
766 * @see cxMapRemove() |
721 * @see cxMapRemove() |
767 */ |
722 */ |
768 #define cxMapRemoveAndGet(map, key, targetbuf) _Generic((key), \ |
723 #define cxMapRemoveAndGet(map, key, targetbuf) _Generic((key), \ |
769 CxHashKey: cx_map_remove_and_get, \ |
724 CxHashKey: cx_map_remove_and_get, \ |
770 cxstring: cx_map_remove_and_get_cxstr, \ |
725 cxstring: cx_map_remove_and_get_cxstr, \ |