182 |
182 |
183 cx_attr_nonnull |
183 cx_attr_nonnull |
184 cx_attr_export |
184 cx_attr_export |
185 int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value); |
185 int cx_kv_list_insert(CxList *list, size_t index, CxHashKey key, void *value); |
186 |
186 |
187 // Generic Functions |
|
188 #ifdef __cplusplus |
|
189 } // extern "C" |
|
190 cx_attr_nonnull |
|
191 static inline int cxKvListSetKey(CxList *list, size_t index, CxHashKey key) { |
|
192 return cx_kv_list_set_key(list, index, key); |
|
193 } |
|
194 |
|
195 cx_attr_nonnull |
|
196 static inline int cxKvListSetKey(CxList *list, size_t index, cxstring key) { |
|
197 return cx_kv_list_set_key(list, index, cx_hash_key_cxstr(key)); |
|
198 } |
|
199 |
|
200 cx_attr_nonnull |
|
201 static inline int cxKvListSetKey(CxList *list, size_t index, cxmutstr key) { |
|
202 return cx_kv_list_set_key(list, index, cx_hash_key_cxstr(key)); |
|
203 } |
|
204 |
|
205 cx_attr_nonnull |
|
206 cx_attr_cstr_arg(3) |
|
207 static inline int cxKvListSetKey(CxList *list, size_t index, const char *key) { |
|
208 return cx_kv_list_set_key(list, index, cx_hash_key_str(key)); |
|
209 } |
|
210 |
|
211 cx_attr_nonnull |
|
212 static inline int cxKvListInsert(CxList *list, size_t index, CxHashKey key, void *value) { |
|
213 return cx_kv_list_insert(list, index, key, value); |
|
214 } |
|
215 |
|
216 cx_attr_nonnull |
|
217 static inline int cxKvListInsert(CxList *list, size_t index, cxstring key, void *value) { |
|
218 return cx_kv_list_insert(list, index, cx_hash_key_cxstr(key), value); |
|
219 } |
|
220 |
|
221 cx_attr_nonnull |
|
222 static inline int cxKvListInsert(CxList *list, size_t index, cxmutstr key, void *value) { |
|
223 return cx_kv_list_insert(list, index, cx_hash_key_cxstr(key), value); |
|
224 } |
|
225 |
|
226 cx_attr_nonnull |
|
227 cx_attr_cstr_arg(3) |
|
228 static inline int cxKvListInsert(CxList *list, size_t index, const char *key, void *value) { |
|
229 return cx_kv_list_insert(list, index, cx_hash_key_str(key), value); |
|
230 } |
|
231 extern "C" { |
|
232 #else /* ! __cplusplus */ |
|
233 /** |
187 /** |
234 * Sets or updates the key of a list item. |
188 * Sets or updates the key of a list item. |
235 * |
189 * |
236 * This is, for example, useful when you have inserted an element using the CxList interface, |
190 * This is, for example, useful when you have inserted an element using the CxList interface, |
237 * and now you want to associate this element with a key. |
191 * and now you want to associate this element with a key. |
238 * |
192 * |
239 * @param list (@c CxList*) the list |
193 * @param list (@c CxList*) the list |
240 * @param index (@c size_t) the index of the element in the list |
194 * @param index (@c size_t) the index of the element in the list |
241 * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key |
195 * @param key (any supported key type) the key |
242 * @retval zero success |
196 * @retval zero success |
243 * @retval non-zero memory allocation failure or the index is out of bounds |
197 * @retval non-zero memory allocation failure or the index is out of bounds |
244 */ |
198 * @see CX_HASH_KEY() |
245 #define cxKvListSetKey(list, index, key) _Generic((key), \ |
199 */ |
246 CxHashKey: cx_kv_list_set_key, \ |
200 #define cxKvListSetKey(list, index, key) cx_kv_list_set_key(list, index, CX_HASH_KEY(key)) |
247 cxstring: cx_kv_list_set_key_cxstr, \ |
|
248 cxmutstr: cx_kv_list_set_key_mustr, \ |
|
249 char*: cx_kv_list_set_key_str, \ |
|
250 const char*: cx_kv_list_set_key_str) \ |
|
251 (list, index, key) |
|
252 |
|
253 cx_attr_nonnull |
|
254 static inline int cx_kv_list_set_key_cxstr(CxList *list, size_t index, cxstring key) { |
|
255 return cx_kv_list_set_key(list, index, cx_hash_key_cxstr(key)); |
|
256 } |
|
257 |
|
258 cx_attr_nonnull |
|
259 static inline int cx_kv_list_set_key_mustr(CxList *list, size_t index, cxmutstr key) { |
|
260 return cx_kv_list_set_key(list, index, cx_hash_key_cxstr(key)); |
|
261 } |
|
262 |
|
263 cx_attr_nonnull |
|
264 cx_attr_cstr_arg(3) |
|
265 static inline int cx_kv_list_set_key_str(CxList *list, size_t index, const char *key) { |
|
266 return cx_kv_list_set_key(list, index, cx_hash_key_str(key)); |
|
267 } |
|
268 |
201 |
269 /** |
202 /** |
270 * Inserts an item into the list at the specified index and associates it with the specified key. |
203 * Inserts an item into the list at the specified index and associates it with the specified key. |
271 * |
204 * |
272 * @param list (@c CxList*) the list |
205 * @param list (@c CxList*) the list |
273 * @param index (@c size_t) the index the inserted element shall have |
206 * @param index (@c size_t) the index the inserted element shall have |
274 * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key |
207 * @param key (any supported key type) the key |
275 * @param value (@c void*) the value |
208 * @param value (@c void*) the value |
276 * @retval zero success |
209 * @retval zero success |
277 * @retval non-zero memory allocation failure or the index is out of bounds |
210 * @retval non-zero memory allocation failure or the index is out of bounds |
278 */ |
211 * @see CX_HASH_KEY() |
279 #define cxKvListInsert(list, index, key, value) _Generic((key), \ |
212 */ |
280 CxHashKey: cx_kv_list_insert, \ |
213 #define cxKvListInsert(list, index, key, value) cx_kv_list_insert(list, index, CX_HASH_KEY(key), value) |
281 cxstring: cx_kv_list_insert_cxstr, \ |
214 |
282 cxmutstr: cx_kv_list_insert_mustr, \ |
|
283 char*: cx_kv_list_insert_str, \ |
|
284 const char*: cx_kv_list_insert_str) \ |
|
285 (list, index, key, value) |
|
286 |
|
287 cx_attr_nonnull |
|
288 static inline int cx_kv_list_insert_cxstr(CxList *list, size_t index, cxstring key, void *value) { |
|
289 return cx_kv_list_insert(list, index, cx_hash_key_cxstr(key), value); |
|
290 } |
|
291 |
|
292 cx_attr_nonnull |
|
293 static inline int cx_kv_list_insert_mustr(CxList *list, size_t index, cxmutstr key, void *value) { |
|
294 return cx_kv_list_insert(list, index, cx_hash_key_cxstr(key), value); |
|
295 } |
|
296 |
|
297 cx_attr_nonnull |
|
298 cx_attr_cstr_arg(3) |
|
299 static inline int cx_kv_list_insert_str(CxList *list, size_t index, const char *key, void *value) { |
|
300 return cx_kv_list_insert(list, index, cx_hash_key_str(key), value); |
|
301 } |
|
302 |
|
303 #endif |
|
304 |
215 |
305 /** |
216 /** |
306 * Removes the key of a list item. |
217 * Removes the key of a list item. |
307 * |
218 * |
308 * This can be useful if you want to explicitly remove an item from the lookup map. |
219 * This can be useful if you want to explicitly remove an item from the lookup map. |