[388] | 1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
| 3 |
|
---|
| 4 | /** @file constmap.h
|
---|
| 5 | * @brief ConstMap is a module that implements a read-only dictionary
|
---|
| 6 | * of @c const char* keys to @c const char* values.
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | #ifndef CONSTMAP_H
|
---|
| 10 | #define CONSTMAP_H
|
---|
| 11 |
|
---|
| 12 | #include "azure_c_shared_utility/macro_utils.h"
|
---|
| 13 | #include "azure_c_shared_utility/crt_abstractions.h"
|
---|
| 14 | #include "azure_c_shared_utility/map.h"
|
---|
| 15 | #include "azure_c_shared_utility/umock_c_prod.h"
|
---|
| 16 |
|
---|
| 17 | #ifdef __cplusplus
|
---|
| 18 | #include <cstddef>
|
---|
| 19 | extern "C"
|
---|
| 20 | {
|
---|
| 21 | #else
|
---|
| 22 | #include <stddef.h>
|
---|
| 23 | #endif
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | #define CONSTMAP_RESULT_VALUES \
|
---|
| 27 | CONSTMAP_OK, \
|
---|
| 28 | CONSTMAP_ERROR, \
|
---|
| 29 | CONSTMAP_INVALIDARG, \
|
---|
| 30 | CONSTMAP_KEYNOTFOUND
|
---|
| 31 |
|
---|
| 32 | /** @brief Enumeration specifying the status of calls to various APIs in this
|
---|
| 33 | * module.
|
---|
| 34 | */
|
---|
| 35 | MU_DEFINE_ENUM(CONSTMAP_RESULT, CONSTMAP_RESULT_VALUES);
|
---|
| 36 |
|
---|
| 37 | typedef struct CONSTMAP_HANDLE_DATA_TAG* CONSTMAP_HANDLE;
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | * @brief Creates a new read-only map from a map handle.
|
---|
| 42 | *
|
---|
| 43 | * @param sourceMap The map from which we will populate key,value
|
---|
| 44 | * into the read-only map.
|
---|
| 45 | *
|
---|
| 46 | * @return A valid @c CONSTMAP_HANDLE or @c NULL in case an error occurs.
|
---|
| 47 | */
|
---|
| 48 | MOCKABLE_FUNCTION(, CONSTMAP_HANDLE, ConstMap_Create, MAP_HANDLE, sourceMap);
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | * @brief Destroy a read-only map. Deallocate memory associated with handle.
|
---|
| 52 | * @param handle Handle to a read-only map.
|
---|
| 53 | */
|
---|
| 54 | MOCKABLE_FUNCTION(, void, ConstMap_Destroy, CONSTMAP_HANDLE, handle);
|
---|
| 55 |
|
---|
| 56 | /**
|
---|
| 57 | * @brief Clone a read-only map from another read-only map.
|
---|
| 58 | * @param handle Handle to a read-only map.
|
---|
| 59 | * @return A valid @c CONSTMAP_HANDLE or @c NULL in case an error occurs.
|
---|
| 60 | */
|
---|
| 61 | MOCKABLE_FUNCTION(, CONSTMAP_HANDLE, ConstMap_Clone, CONSTMAP_HANDLE, handle);
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
| 64 | * @brief Create a map handle populated from the read-only map.
|
---|
| 65 | * @param handle Handle to a read-only map.
|
---|
| 66 | * @return A valid @c MAP_HANDLE or @c NULL in case an error occurs.
|
---|
| 67 | *
|
---|
| 68 | * The new MAP_HANDLE needs to be destroyed when it is no longer needed.
|
---|
| 69 | */
|
---|
| 70 | MOCKABLE_FUNCTION(, MAP_HANDLE, ConstMap_CloneWriteable, CONSTMAP_HANDLE, handle);
|
---|
| 71 |
|
---|
| 72 | /**
|
---|
| 73 | * @brief This function returns a true if the map contains a key
|
---|
| 74 | * with the same value the parameter @p key.
|
---|
| 75 | *
|
---|
| 76 | * @param handle The handle to an existing map.
|
---|
| 77 | * @param key The key that the caller wants checked.
|
---|
| 78 | *
|
---|
| 79 | * @return The function returns @c true if the key exists
|
---|
| 80 | * in the map and @c false if key is not found or
|
---|
| 81 | * parameters are invalid.
|
---|
| 82 | */
|
---|
| 83 | MOCKABLE_FUNCTION(, bool, ConstMap_ContainsKey, CONSTMAP_HANDLE, handle, const char*, key);
|
---|
| 84 |
|
---|
| 85 | /**
|
---|
| 86 | * @brief This function returns @c true if at least one <key,value> pair
|
---|
| 87 | * exists in the map where the entry's value is equal to the
|
---|
| 88 | * parameter @c value.
|
---|
| 89 | *
|
---|
| 90 | * @param handle The handle to an existing map.
|
---|
| 91 | * @param value The value that the caller wants checked.
|
---|
| 92 | *
|
---|
| 93 | * @return The function returns @c true if the value exists
|
---|
| 94 | * in the map and @c false if value is not found or
|
---|
| 95 | * parameters are invalid.
|
---|
| 96 | */
|
---|
| 97 | MOCKABLE_FUNCTION(, bool, ConstMap_ContainsValue, CONSTMAP_HANDLE, handle, const char*, value);
|
---|
| 98 |
|
---|
| 99 | /**
|
---|
| 100 | * @brief Retrieves the value of a stored key.
|
---|
| 101 | *
|
---|
| 102 | * @param handle The handle to an existing map.
|
---|
| 103 | * @param key The key to be looked up in the map.
|
---|
| 104 | *
|
---|
| 105 | * @return Returns @c NULL in case the input arguments are @c NULL or if the
|
---|
| 106 | * requested key is not found in the map. Returns a pointer to the
|
---|
| 107 | * key's value otherwise.
|
---|
| 108 | */
|
---|
| 109 | MOCKABLE_FUNCTION(, const char*, ConstMap_GetValue, CONSTMAP_HANDLE, handle, const char*, key);
|
---|
| 110 |
|
---|
| 111 | /**
|
---|
| 112 | * @brief Retrieves the complete list of keys and values from the map
|
---|
| 113 | * in @p values and @p keys. Also writes the size of the list
|
---|
| 114 | * in @p count.
|
---|
| 115 | *
|
---|
| 116 | * @param handle The handle to an existing map.
|
---|
| 117 | * @param keys The location where the list of keys is to be written.
|
---|
| 118 | * @param values The location where the list of values is to be written.
|
---|
| 119 | * @param count The number of stored keys and values is written at the
|
---|
| 120 | * location indicated by this pointer.
|
---|
| 121 | *
|
---|
| 122 | * @return Returns @c CONSTMAP_OK if the keys and values are retrieved
|
---|
| 123 | * and written successfully or an error code otherwise.
|
---|
| 124 | */
|
---|
| 125 | MOCKABLE_FUNCTION(, CONSTMAP_RESULT, ConstMap_GetInternals, CONSTMAP_HANDLE, handle, const char*const**, keys, const char*const**, values, size_t*, count);
|
---|
| 126 |
|
---|
| 127 |
|
---|
| 128 | #ifdef __cplusplus
|
---|
| 129 | }
|
---|
| 130 | #endif
|
---|
| 131 |
|
---|
| 132 | #endif /* CONSTMAP_H */
|
---|