Nigel Rantor / azure_c_shared_utility

Fork of azure_c_shared_utility by Azure IoT

Embed: (wiki syntax)

« Back to documentation index

map.h File Reference

map.h File Reference

Map is a module that implements a dictionary of STRING_HANDLE keys to STRING_HANDLE values. More...

Go to the source code of this file.

Functions

 DEFINE_ENUM (MAP_RESULT, MAP_RESULT_VALUES)
 Enumeration specifying the status of calls to various APIs in this module.
 MOCKABLE_FUNCTION (, MAP_HANDLE, Map_Create, MAP_FILTER_CALLBACK, mapFilterFunc)
 Creates a new, empty map.
 MOCKABLE_FUNCTION (, void, Map_Destroy, MAP_HANDLE, handle)
 Release all resources associated with the map.
 MOCKABLE_FUNCTION (, MAP_HANDLE, Map_Clone, MAP_HANDLE, handle)
 Creates a copy of the map indicated by handle and returns a handle to it.
 MOCKABLE_FUNCTION (, MAP_RESULT, Map_Add, MAP_HANDLE, handle, const char *, key, const char *, value)
 Adds a key/value pair to the map.
 MOCKABLE_FUNCTION (, MAP_RESULT, Map_AddOrUpdate, MAP_HANDLE, handle, const char *, key, const char *, value)
 Adds/updates a key/value pair to the map.
 MOCKABLE_FUNCTION (, MAP_RESULT, Map_Delete, MAP_HANDLE, handle, const char *, key)
 Removes a key and its associated value from the map.
 MOCKABLE_FUNCTION (, MAP_RESULT, Map_ContainsKey, MAP_HANDLE, handle, const char *, key, bool *, keyExists)
 This function returns a boolean value in keyExists if the map contains a key with the same value the parameter key.
 MOCKABLE_FUNCTION (, MAP_RESULT, Map_ContainsValue, MAP_HANDLE, handle, const char *, value, bool *, valueExists)
 This function returns true in valueExists if at least one <key,value> pair exists in the map where the entry's value is equal to the parameter value.
 MOCKABLE_FUNCTION (, const char *, Map_GetValueFromKey, MAP_HANDLE, handle, const char *, key)
 Retrieves the value of a stored key.
 MOCKABLE_FUNCTION (, MAP_RESULT, Map_GetInternals, MAP_HANDLE, handle, const char *const **, keys, const char *const **, values, size_t *, count)
 Retrieves the complete list of keys and values from the map in values and keys.

Detailed Description

Map is a module that implements a dictionary of STRING_HANDLE keys to STRING_HANDLE values.

Definition in file map.h.


Function Documentation

DEFINE_ENUM ( MAP_RESULT  ,
MAP_RESULT_VALUES   
)

Enumeration specifying the status of calls to various APIs in this module.

MOCKABLE_FUNCTION ( MAP_RESULT  ,
Map_GetInternals  ,
MAP_HANDLE  ,
handle  ,
const char *const **  ,
keys  ,
const char *const **  ,
values  ,
size_t *  ,
count   
)

Retrieves the complete list of keys and values from the map in values and keys.

Also writes the size of the list in count.

Parameters:
handleThe handle to an existing map.
keysThe location where the list of keys is to be written.
valuesThe location where the list of values is to be written.
countThe number of stored keys and values is written at the location indicated by this pointer.
Returns:
Returns MAP_OK if the keys and values are retrieved and written successfully or an error code otherwise.
MOCKABLE_FUNCTION ( const char *  ,
Map_GetValueFromKey  ,
MAP_HANDLE  ,
handle  ,
const char *  ,
key   
)

Retrieves the value of a stored key.

Parameters:
handleThe handle to an existing map.
keyThe key to be looked up in the map.
Returns:
Returns NULL in case the input arguments are NULL or if the requested key is not found in the map. Returns a pointer to the key's value otherwise.
MOCKABLE_FUNCTION ( MAP_RESULT  ,
Map_ContainsValue  ,
MAP_HANDLE  ,
handle  ,
const char *  ,
value  ,
bool *  ,
valueExists   
)

This function returns true in valueExists if at least one <key,value> pair exists in the map where the entry's value is equal to the parameter value.

Parameters:
handleThe handle to an existing map.
valueThe value that the caller wants checked.
valueExistsThe function writes true at the address pointed at by this parameter if the value exists in the map and false otherwise.
Returns:
Returns MAP_OK if the check was performed successfully or an error code otherwise.
MOCKABLE_FUNCTION ( MAP_RESULT  ,
Map_ContainsKey  ,
MAP_HANDLE  ,
handle  ,
const char *  ,
key  ,
bool *  ,
keyExists   
)

This function returns a boolean value in keyExists if the map contains a key with the same value the parameter key.

Parameters:
handleThe handle to an existing map.
keyThe key that the caller wants checked.
keyExistsThe function writes true at the address pointed at by this parameter if the key exists in the map and false otherwise.
Returns:
Returns MAP_OK if the check was performed successfully or an error code otherwise.
MOCKABLE_FUNCTION ( MAP_RESULT  ,
Map_Delete  ,
MAP_HANDLE  ,
handle  ,
const char *  ,
key   
)

Removes a key and its associated value from the map.

Parameters:
handleThe handle to an existing map.
keyThe key of the item to be deleted.
Returns:
Returns MAP_OK if the key was deleted successfully or an error code otherwise.
MOCKABLE_FUNCTION ( MAP_RESULT  ,
Map_AddOrUpdate  ,
MAP_HANDLE  ,
handle  ,
const char *  ,
key  ,
const char *  ,
value   
)

Adds/updates a key/value pair to the map.

Parameters:
handleThe handle to an existing map.
keyThe key to be used for this map entry.
valueThe value to be associated with key.

This function behaves exactly like Map_Add except that if the key already exists in the map then it overwrites the value with the supplied value instead of returning an error. If a non-NULL pointer to a callback function was supplied via the mapFilterFunc parameter when Map_Create was called then that callback is invoked when a new entry is added or when an existing entry is updated and if the callback returns a non-zero value then the function cancels the add/update operation and returns MAP_FILTER_REJECT.

Returns:
If any of the input parameters are NULL then this function returns MAP_INVALID_ARG. If the filter function associated with the map rejects the entry then MAP_FILTER_REJECT is returned. In case an error occurs when the new key is added/updated in the map the function returns MAP_ERROR. If everything goes well then MAP_OK is returned.
MOCKABLE_FUNCTION ( MAP_RESULT  ,
Map_Add  ,
MAP_HANDLE  ,
handle  ,
const char *  ,
key  ,
const char *  ,
value   
)

Adds a key/value pair to the map.

Parameters:
handleThe handle to an existing map.
keyThe key to be used for this map entry.
valueThe value to be associated with key.

If a non-NULL pointer to a callback function was supplied via the mapFilterFunc parameter when Map_Create was called then that callback is invoked when a new entry is added and if the callback returns a non-zero value then the function cancels the add operation and returns MAP_FILTER_REJECT.

Returns:
If any of the input parameters are NULL then this function returns MAP_INVALID_ARG. If the key already exists in the map then MAP_KEYEXISTS is returned. If the filter function associated with the map rejects the entry then MAP_FILTER_REJECT is returned. In case an error occurs when the new key is added to the map the function returns MAP_ERROR. If everything goes well then MAP_OK is returned.
MOCKABLE_FUNCTION ( MAP_HANDLE  ,
Map_Clone  ,
MAP_HANDLE  ,
handle   
)

Creates a copy of the map indicated by handle and returns a handle to it.

Parameters:
handleThe handle to an existing map.
Returns:
A valid MAP_HANDLE to the cloned copy of the map or NULL in case an error occurs.
MOCKABLE_FUNCTION ( void  ,
Map_Destroy  ,
MAP_HANDLE  ,
handle   
)

Release all resources associated with the map.

Parameters:
handleThe handle to an existing map.
MOCKABLE_FUNCTION ( MAP_HANDLE  ,
Map_Create  ,
MAP_FILTER_CALLBACK  ,
mapFilterFunc   
)

Creates a new, empty map.

Parameters:
mapFilterFuncA callback function supplied by the caller that is invoked during calls to Map_Add and Map_AddOrUpdate to provide the caller an opportunity to indicate whether the new entry or the update to an existing entry can be made or not. The callback function can request that the operation be canceled by returning a non-zero value from the callback.
Returns:
A valid MAP_HANDLE or NULL in case an error occurs.