![]() |
ucx
UAP Common Extensions
|
Interface for map implementations. More...
Go to the source code of this file.
Data Structures | |
struct | cx_map_s |
Structure for the UCX map. More... | |
struct | cx_map_entry_s |
A map entry. More... | |
struct | cx_map_iterator_s |
Internal iterator struct - use CxMapIterator. More... | |
struct | cx_map_class_s |
The class definition for arbitrary maps. More... | |
Macros | |
#define | cxMapPut(map, key, value) |
Puts a key/value-pair into the map. | |
#define | cxMapGet(map, key) |
Retrieves a value by using a key. | |
#define | cxMapRemove(map, key) |
Removes a key/value-pair from the map by using the key. | |
#define | cxMapRemoveAndGet(map, key, targetbuf) |
Removes a key/value-pair from the map by using the key. | |
Typedefs | |
typedef struct cx_map_s | CxMap |
Type for the UCX map. | |
typedef struct cx_map_entry_s | CxMapEntry |
Type for a map entry. | |
typedef struct cx_map_iterator_s | CxMapIterator |
Type for a map iterator. | |
typedef struct cx_map_class_s | cx_map_class |
Type for map class definitions. | |
Enumerations | |
enum | cx_map_iterator_type { CX_MAP_ITERATOR_PAIRS , CX_MAP_ITERATOR_KEYS , CX_MAP_ITERATOR_VALUES } |
The type of iterator for a map. More... | |
Functions | |
void | cxMapFree (CxMap *map) |
Deallocates the memory of the specified map. | |
static void | cxMapClear (CxMap *map) |
Clears a map by removing all elements. | |
static size_t | cxMapSize (const CxMap *map) |
Returns the number of elements in this map. | |
static CxMapIterator | cxMapIteratorValues (const CxMap *map) |
Creates a value iterator for a map. | |
static CxMapIterator | cxMapIteratorKeys (const CxMap *map) |
Creates a key iterator for a map. | |
static CxMapIterator | cxMapIterator (const CxMap *map) |
Creates an iterator for a map. | |
CxMapIterator | cxMapMutIteratorValues (CxMap *map) |
Creates a mutating iterator over the values of a map. | |
CxMapIterator | cxMapMutIteratorKeys (CxMap *map) |
Creates a mutating iterator over the keys of a map. | |
CxMapIterator | cxMapMutIterator (CxMap *map) |
Creates a mutating iterator for a map. | |
static int | cx_map_put (CxMap *map, CxHashKey key, void *value) |
Puts a key/value-pair into the map. | |
static int | cx_map_put_cxstr (CxMap *map, cxstring key, void *value) |
Puts a key/value-pair into the map. | |
static int | cx_map_put_mustr (CxMap *map, cxmutstr key, void *value) |
Puts a key/value-pair into the map. | |
static int | cx_map_put_str (CxMap *map, const char *key, void *value) |
Puts a key/value-pair into the map. | |
static void * | cx_map_get (const CxMap *map, CxHashKey key) |
Retrieves a value by using a key. | |
static void * | cx_map_get_cxstr (const CxMap *map, cxstring key) |
Retrieves a value by using a key. | |
static void * | cx_map_get_mustr (const CxMap *map, cxmutstr key) |
Retrieves a value by using a key. | |
static void * | cx_map_get_str (const CxMap *map, const char *key) |
Retrieves a value by using a key. | |
static int | cx_map_remove (CxMap *map, CxHashKey key) |
Removes a key/value-pair from the map by using the key. | |
static int | cx_map_remove_cxstr (CxMap *map, cxstring key) |
Removes a key/value-pair from the map by using the key. | |
static int | cx_map_remove_mustr (CxMap *map, cxmutstr key) |
Removes a key/value-pair from the map by using the key. | |
static int | cx_map_remove_str (CxMap *map, const char *key) |
Removes a key/value-pair from the map by using the key. | |
static int | cx_map_remove_and_get (CxMap *map, CxHashKey key, void *targetbuf) |
Removes a key/value-pair from the map by using the key. | |
static int | cx_map_remove_and_get_cxstr (CxMap *map, cxstring key, void *targetbuf) |
Removes a key/value-pair from the map by using the key. | |
static int | cx_map_remove_and_get_mustr (CxMap *map, cxmutstr key, void *targetbuf) |
Removes a key/value-pair from the map by using the key. | |
static int | cx_map_remove_and_get_str (CxMap *map, const char *key, void *targetbuf) |
Removes a key/value-pair from the map by using the key. | |
Variables | |
CxMap *const | cxEmptyMap |
A shared instance of an empty map. | |
Interface for map implementations.
#define cxMapGet | ( | map, | |
key ) |
Retrieves a value by using a key.
If this map is storing pointers, the stored pointer is returned. Otherwise, a pointer to the element within the map's memory is returned (which is valid as long as the element stays in the map).
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
void*
) the value #define cxMapPut | ( | map, | |
key, | |||
value ) |
Puts a key/value-pair into the map.
A possible existing value will be overwritten. If destructor functions are specified, they are called for the overwritten element.
If this map is storing pointers, the value
pointer is written to the map. Otherwise, the memory is copied from value
with memcpy().
The key
is always copied.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
value | (void* ) the value |
zero | success |
non-zero | value on memory allocation failure |
#define cxMapRemove | ( | map, | |
key ) |
Removes a key/value-pair from the map by using the key.
Always invokes the destructors functions, if any, on the removed element.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
zero | success |
non-zero | the key was not found |
#define cxMapRemoveAndGet | ( | map, | |
key, | |||
targetbuf ) |
Removes a key/value-pair from the map by using the key.
This function will copy the contents of the removed element to the target buffer, which must be guaranteed to be large enough to hold the element (the map's element size). The destructor functions, if any, will not be called.
If this map is storing pointers, the element is the pointer itself and not the object it points to.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
targetbuf | (void* ) the buffer where the element shall be copied to |
zero | success |
non-zero | the key was not found |
enum cx_map_iterator_type |
Retrieves a value by using a key.
If this map is storing pointers, the stored pointer is returned. Otherwise, a pointer to the element within the map's memory is returned (which is valid as long as the element stays in the map).
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
void*
) the value Retrieves a value by using a key.
If this map is storing pointers, the stored pointer is returned. Otherwise, a pointer to the element within the map's memory is returned (which is valid as long as the element stays in the map).
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
void*
) the value Retrieves a value by using a key.
If this map is storing pointers, the stored pointer is returned. Otherwise, a pointer to the element within the map's memory is returned (which is valid as long as the element stays in the map).
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
void*
) the value
|
inlinestatic |
Retrieves a value by using a key.
If this map is storing pointers, the stored pointer is returned. Otherwise, a pointer to the element within the map's memory is returned (which is valid as long as the element stays in the map).
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
void*
) the value Puts a key/value-pair into the map.
A possible existing value will be overwritten. If destructor functions are specified, they are called for the overwritten element.
If this map is storing pointers, the value
pointer is written to the map. Otherwise, the memory is copied from value
with memcpy().
The key
is always copied.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
value | (void* ) the value |
zero | success |
non-zero | value on memory allocation failure |
Puts a key/value-pair into the map.
A possible existing value will be overwritten. If destructor functions are specified, they are called for the overwritten element.
If this map is storing pointers, the value
pointer is written to the map. Otherwise, the memory is copied from value
with memcpy().
The key
is always copied.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
value | (void* ) the value |
zero | success |
non-zero | value on memory allocation failure |
Puts a key/value-pair into the map.
A possible existing value will be overwritten. If destructor functions are specified, they are called for the overwritten element.
If this map is storing pointers, the value
pointer is written to the map. Otherwise, the memory is copied from value
with memcpy().
The key
is always copied.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
value | (void* ) the value |
zero | success |
non-zero | value on memory allocation failure |
|
inlinestatic |
Puts a key/value-pair into the map.
A possible existing value will be overwritten. If destructor functions are specified, they are called for the overwritten element.
If this map is storing pointers, the value
pointer is written to the map. Otherwise, the memory is copied from value
with memcpy().
The key
is always copied.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
value | (void* ) the value |
zero | success |
non-zero | value on memory allocation failure |
Removes a key/value-pair from the map by using the key.
Always invokes the destructors functions, if any, on the removed element.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
zero | success |
non-zero | the key was not found |
Removes a key/value-pair from the map by using the key.
This function will copy the contents of the removed element to the target buffer, which must be guaranteed to be large enough to hold the element (the map's element size). The destructor functions, if any, will not be called.
If this map is storing pointers, the element is the pointer itself and not the object it points to.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
targetbuf | (void* ) the buffer where the element shall be copied to |
zero | success |
non-zero | the key was not found |
Removes a key/value-pair from the map by using the key.
This function will copy the contents of the removed element to the target buffer, which must be guaranteed to be large enough to hold the element (the map's element size). The destructor functions, if any, will not be called.
If this map is storing pointers, the element is the pointer itself and not the object it points to.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
targetbuf | (void* ) the buffer where the element shall be copied to |
zero | success |
non-zero | the key was not found |
Removes a key/value-pair from the map by using the key.
This function will copy the contents of the removed element to the target buffer, which must be guaranteed to be large enough to hold the element (the map's element size). The destructor functions, if any, will not be called.
If this map is storing pointers, the element is the pointer itself and not the object it points to.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
targetbuf | (void* ) the buffer where the element shall be copied to |
zero | success |
non-zero | the key was not found |
|
inlinestatic |
Removes a key/value-pair from the map by using the key.
This function will copy the contents of the removed element to the target buffer, which must be guaranteed to be large enough to hold the element (the map's element size). The destructor functions, if any, will not be called.
If this map is storing pointers, the element is the pointer itself and not the object it points to.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
targetbuf | (void* ) the buffer where the element shall be copied to |
zero | success |
non-zero | the key was not found |
Removes a key/value-pair from the map by using the key.
Always invokes the destructors functions, if any, on the removed element.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
zero | success |
non-zero | the key was not found |
Removes a key/value-pair from the map by using the key.
Always invokes the destructors functions, if any, on the removed element.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
zero | success |
non-zero | the key was not found |
|
inlinestatic |
Removes a key/value-pair from the map by using the key.
Always invokes the destructors functions, if any, on the removed element.
map | (CxMap* ) the map |
key | (CxHashKey , char* , cxstring , or cxmutstr ) the key |
zero | success |
non-zero | the key was not found |
|
inlinestatic |
Clears a map by removing all elements.
Also calls the content destructor functions for each element, if specified.
map | the map to be cleared |
void cxMapFree | ( | CxMap * | map | ) |
Deallocates the memory of the specified map.
Also calls the content destructor functions for each element, if specified.
map | the map to be freed |
|
inlinestatic |
Creates an iterator for a map.
The elements of the iterator are key/value pairs of type CxMapEntry and the pointer returned during iterator shall be treated as const
CxMapEntry*
.
map | the map to create the iterator for |
|
inlinestatic |
Creates a key iterator for a map.
The elements of the iterator are keys of type CxHashKey and the pointer returned during iterator shall be treated as const
CxHashKey*
.
map | the map to create the iterator for |
|
inlinestatic |
Creates a value iterator for a map.
When the map is storing pointers, those pointers are returned. Otherwise, the iterator iterates over pointers to the memory within the map where the respective elements are stored.
map | the map to create the iterator for |
CxMapIterator cxMapMutIterator | ( | CxMap * | map | ) |
Creates a mutating iterator for a map.
The elements of the iterator are key/value pairs of type CxMapEntry and the pointer returned during iterator shall be treated as const
CxMapEntry*
.
map | the map to create the iterator for |
CxMapIterator cxMapMutIteratorKeys | ( | CxMap * | map | ) |
Creates a mutating iterator over the keys of a map.
The elements of the iterator are keys of type CxHashKey and the pointer returned during iterator shall be treated as const
CxHashKey*
.
map | the map to create the iterator for |
CxMapIterator cxMapMutIteratorValues | ( | CxMap * | map | ) |
Creates a mutating iterator over the values of a map.
When the map is storing pointers, those pointers are returned. Otherwise, the iterator iterates over pointers to the memory within the map where the respective elements are stored.
map | the map to create the iterator for |
|
inlinestatic |
Returns the number of elements in this map.
map | the map |
|
extern |
A shared instance of an empty map.
Writing to that map is not allowed.
You can use this is a placeholder for initializing CxMap pointers for which you do not want to reserve memory right from the beginning.