385 static inline int cxMapPut( |
388 static inline int cxMapPut( |
386 CxMap *map, |
389 CxMap *map, |
387 CxHashKey const &key, |
390 CxHashKey const &key, |
388 void *value |
391 void *value |
389 ) { |
392 ) { |
390 return map->cl->put(map, key, value); |
393 return map->cl->put(map, key, value) == NULL; |
391 } |
394 } |
392 |
395 |
393 cx_attr_nonnull |
396 cx_attr_nonnull |
394 static inline int cxMapPut( |
397 static inline int cxMapPut( |
395 CxMap *map, |
398 CxMap *map, |
396 cxstring const &key, |
399 cxstring const &key, |
397 void *value |
400 void *value |
398 ) { |
401 ) { |
399 return map->cl->put(map, cx_hash_key_cxstr(key), value); |
402 return map->cl->put(map, cx_hash_key_cxstr(key), value) == NULL; |
400 } |
403 } |
401 |
404 |
402 cx_attr_nonnull |
405 cx_attr_nonnull |
403 static inline int cxMapPut( |
406 static inline int cxMapPut( |
404 CxMap *map, |
407 CxMap *map, |
405 cxmutstr const &key, |
408 cxmutstr const &key, |
406 void *value |
409 void *value |
407 ) { |
410 ) { |
408 return map->cl->put(map, cx_hash_key_cxstr(key), value); |
411 return map->cl->put(map, cx_hash_key_cxstr(key), value) == NULL; |
409 } |
412 } |
410 |
413 |
411 cx_attr_nonnull |
414 cx_attr_nonnull |
412 cx_attr_cstr_arg(2) |
415 cx_attr_cstr_arg(2) |
413 static inline int cxMapPut( |
416 static inline int cxMapPut( |
414 CxMap *map, |
417 CxMap *map, |
415 const char *key, |
418 const char *key, |
416 void *value |
419 void *value |
417 ) { |
420 ) { |
418 return map->cl->put(map, cx_hash_key_str(key), value); |
421 return map->cl->put(map, cx_hash_key_str(key), value) == NULL; |
|
422 } |
|
423 |
|
424 cx_attr_nonnull |
|
425 static inline void *cxMapEmplace( |
|
426 CxMap *map, |
|
427 CxHashKey const &key |
|
428 ) { |
|
429 return map->cl->put(map, key, NULL); |
|
430 } |
|
431 |
|
432 cx_attr_nonnull |
|
433 static inline void *cxMapEmplace( |
|
434 CxMap *map, |
|
435 cxstring const &key |
|
436 ) { |
|
437 return map->cl->put(map, cx_hash_key_cxstr(key), NULL); |
|
438 } |
|
439 |
|
440 cx_attr_nonnull |
|
441 static inline void *cxMapEmplace( |
|
442 CxMap *map, |
|
443 cxmutstr const &key |
|
444 ) { |
|
445 return map->cl->put(map, cx_hash_key_cxstr(key), NULL); |
|
446 } |
|
447 |
|
448 cx_attr_nonnull |
|
449 cx_attr_cstr_arg(2) |
|
450 static inline void *cxMapEmplace( |
|
451 CxMap *map, |
|
452 const char *key |
|
453 ) { |
|
454 return map->cl->put(map, cx_hash_key_str(key), NULL); |
419 } |
455 } |
420 |
456 |
421 cx_attr_nonnull |
457 cx_attr_nonnull |
422 cx_attr_nodiscard |
458 cx_attr_nodiscard |
423 static inline void *cxMapGet( |
459 static inline void *cxMapGet( |
606 char*: cx_map_put_str, \ |
642 char*: cx_map_put_str, \ |
607 const char*: cx_map_put_str) \ |
643 const char*: cx_map_put_str) \ |
608 (map, key, value) |
644 (map, key, value) |
609 |
645 |
610 /** |
646 /** |
|
647 * @copydoc cxMapEmplace() |
|
648 */ |
|
649 cx_attr_nonnull |
|
650 static inline void *cx_map_emplace( |
|
651 CxMap *map, |
|
652 CxHashKey key |
|
653 ) { |
|
654 return map->cl->put(map, key, NULL); |
|
655 } |
|
656 |
|
657 /** |
|
658 * @copydoc cxMapEmplace() |
|
659 */ |
|
660 cx_attr_nonnull |
|
661 static inline void *cx_map_emplace_cxstr( |
|
662 CxMap *map, |
|
663 cxstring key |
|
664 ) { |
|
665 return map->cl->put(map, cx_hash_key_cxstr(key), NULL); |
|
666 } |
|
667 |
|
668 /** |
|
669 * @copydoc cxMapEmplace() |
|
670 */ |
|
671 cx_attr_nonnull |
|
672 static inline void *cx_map_emplace_mustr( |
|
673 CxMap *map, |
|
674 cxmutstr key |
|
675 ) { |
|
676 return map->cl->put(map, cx_hash_key_cxstr(key), NULL); |
|
677 } |
|
678 |
|
679 /** |
|
680 * @copydoc cxMapEmplace() |
|
681 */ |
|
682 cx_attr_nonnull |
|
683 cx_attr_cstr_arg(2) |
|
684 static inline void *cx_map_emplace_str( |
|
685 CxMap *map, |
|
686 const char *key |
|
687 ) { |
|
688 return map->cl->put(map, cx_hash_key_str(key), NULL); |
|
689 } |
|
690 |
|
691 /** |
|
692 * Allocates memory for a value in the map associated with the specified key. |
|
693 * |
|
694 * A possible existing value will be overwritten. |
|
695 * If destructor functions are specified, they are called for |
|
696 * the overwritten element. |
|
697 * |
|
698 * If the map is storing pointers, this function returns a @c void** pointer, |
|
699 * meaning a pointer to that pointer. |
|
700 * |
|
701 * The @p key is always copied. |
|
702 * |
|
703 * @param map (@c CxMap*) the map |
|
704 * @param key (@c CxHashKey, @c char*, @c cxstring, or @c cxmutstr) the key |
|
705 * @return the pointer to the allocated memory or @c NULL if allocation fails |
|
706 * @retval zero success |
|
707 * @retval non-zero value on memory allocation failure |
|
708 */ |
|
709 #define cxMapEmplace(map, key) _Generic((key), \ |
|
710 CxHashKey: cx_map_emplace, \ |
|
711 cxstring: cx_map_emplace_cxstr, \ |
|
712 cxmutstr: cx_map_emplace_mustr, \ |
|
713 char*: cx_map_emplace_str, \ |
|
714 const char*: cx_map_emplace_str) \ |
|
715 (map, key) |
|
716 |
|
717 /** |
611 * @copydoc cxMapGet() |
718 * @copydoc cxMapGet() |
612 */ |
719 */ |
613 cx_attr_nonnull |
720 cx_attr_nonnull |
614 cx_attr_nodiscard |
721 cx_attr_nodiscard |
615 static inline void *cx_map_get( |
722 static inline void *cx_map_get( |