source: azure_iot_hub/trunk/azure_iothub/c-utility/inc/azure_c_shared_utility/map.h

Last change on this file was 389, checked in by coas-nagasima, 5 years ago

ビルドが通るよう更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 8.0 KB
Line 
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 map.h
5* @brief Map is a module that implements a dictionary of @c STRING_HANDLE
6* keys to @c STRING_HANDLE values.
7*/
8
9#ifndef MAP_H
10#define MAP_H
11
12#include "azure_c_shared_utility/macro_utils.h"
13#include "azure_c_shared_utility/strings.h"
14#include "azure_c_shared_utility/crt_abstractions.h"
15#include "azure_c_shared_utility/umock_c_prod.h"
16
17#ifdef __cplusplus
18#include <cstddef>
19extern "C"
20{
21#else
22#include <stddef.h>
23#endif
24
25#define MAP_RESULT_VALUES \
26 MAP_OK, \
27 MAP_ERROR, \
28 MAP_INVALIDARG, \
29 MAP_KEYEXISTS, \
30 MAP_KEYNOTFOUND, \
31 MAP_FILTER_REJECT
32
33/** @brief Enumeration specifying the status of calls to various APIs in this
34 * module.
35 */
36MU_DEFINE_ENUM(MAP_RESULT, MAP_RESULT_VALUES);
37
38typedef struct MAP_HANDLE_DATA_TAG* MAP_HANDLE;
39
40typedef int (*MAP_FILTER_CALLBACK)(const char* mapProperty, const char* mapValue);
41
42/**
43 * @brief Creates a new, empty map.
44 *
45 * @param mapFilterFunc A callback function supplied by the caller that is
46 * invoked during calls to ::Map_Add and
47 * ::Map_AddOrUpdate to provide the caller an
48 * opportunity to indicate whether the new entry or
49 * the update to an existing entry can be made or not.
50 * The callback function can request that the operation
51 * be canceled by returning a non-zero value from the
52 * callback.
53 *
54 * @return A valid @c MAP_HANDLE or @c NULL in case an error occurs.
55 */
56MOCKABLE_FUNCTION(, MAP_HANDLE, Map_Create, MAP_FILTER_CALLBACK, mapFilterFunc);
57
58/**
59 * @brief Release all resources associated with the map.
60 *
61 * @param handle The handle to an existing map.
62 */
63MOCKABLE_FUNCTION(, void, Map_Destroy, MAP_HANDLE, handle);
64
65/**
66 * @brief Creates a copy of the map indicated by @p handle and returns a
67 * handle to it.
68 *
69 * @param handle The handle to an existing map.
70 *
71 * @return A valid @c MAP_HANDLE to the cloned copy of the map or @c NULL
72 * in case an error occurs.
73 */
74MOCKABLE_FUNCTION(, MAP_HANDLE, Map_Clone, MAP_HANDLE, handle);
75
76/**
77 * @brief Adds a key/value pair to the map.
78 *
79 * @param handle The handle to an existing map.
80 * @param key The @c key to be used for this map entry.
81 * @param value The @c value to be associated with @p key.
82 *
83 * If a non-NULL pointer to a callback function was supplied
84 * via the @c mapFilterFunc parameter when ::Map_Create was
85 * called then that callback is invoked when a new entry is
86 * added and if the callback returns a non-zero value then
87 * the function cancels the add operation and returns
88 * @c MAP_FILTER_REJECT.
89 *
90 * @return If any of the input parameters are @c NULL then this function
91 * returns @c MAP_INVALID_ARG. If the key already exists in the
92 * map then @c MAP_KEYEXISTS is returned. If the filter function
93 * associated with the map rejects the entry then
94 * @c MAP_FILTER_REJECT is returned. In case an error occurs when
95 * the new key is added to the map the function returns @c MAP_ERROR.
96 * If everything goes well then @c MAP_OK is returned.
97 */
98MOCKABLE_FUNCTION(, MAP_RESULT, Map_Add, MAP_HANDLE, handle, const char*, key, const char*, value);
99
100/**
101 * @brief Adds/updates a key/value pair to the map.
102 *
103 * @param handle The handle to an existing map.
104 * @param key The @c key to be used for this map entry.
105 * @param value The @c value to be associated with @p key.
106 *
107 * This function behaves exactly like ::Map_Add except that if the key
108 * already exists in the map then it overwrites the value with the
109 * supplied value instead of returning an error. If a non-NULL pointer
110 * to a callback function was supplied via the @c mapFilterFunc parameter
111 * when ::Map_Create was called then that callback is invoked when a new
112 * entry is added or when an existing entry is updated and if the
113 * callback returns a non-zero value then the function cancels the
114 * add/update operation and returns @c MAP_FILTER_REJECT.
115 *
116 * @return If any of the input parameters are @c NULL then this function
117 * returns @c MAP_INVALID_ARG. If the filter function associated
118 * with the map rejects the entry then @c MAP_FILTER_REJECT is
119 * returned. In case an error occurs when the new key is
120 * added/updated in the map the function returns @c MAP_ERROR. If
121 * everything goes well then @c MAP_OK is returned.
122 */
123MOCKABLE_FUNCTION(, MAP_RESULT, Map_AddOrUpdate, MAP_HANDLE, handle, const char*, key, const char*, value);
124
125/**
126 * @brief Removes a key and its associated value from the map.
127 *
128 * @param handle The handle to an existing map.
129 * @param key The @c key of the item to be deleted.
130 *
131 * @return Returns @c MAP_OK if the key was deleted successfully or an
132 * error code otherwise.
133 */
134MOCKABLE_FUNCTION(, MAP_RESULT, Map_Delete, MAP_HANDLE, handle, const char*, key);
135
136/**
137 * @brief This function returns a boolean value in @p keyExists if the map
138 * contains a key with the same value the parameter @p key.
139 *
140 * @param handle The handle to an existing map.
141 * @param key The key that the caller wants checked.
142 * @param keyExists The function writes @c true at the address pointed at
143 * by this parameter if the key exists in the map and
144 * @c false otherwise.
145 *
146 * @return Returns @c MAP_OK if the check was performed successfully or an
147 * error code otherwise.
148 */
149MOCKABLE_FUNCTION(, MAP_RESULT, Map_ContainsKey, MAP_HANDLE, handle, const char*, key, bool*, keyExists);
150
151/**
152 * @brief This function returns @c true in @p valueExists if at
153 * least one <key,value> pair exists in the map where the entry's
154 * value is equal to the parameter @c value.
155 *
156 * @param handle The handle to an existing map.
157 * @param value The value that the caller wants checked.
158 * @param valueExists The function writes @c true at the address pointed at
159 * by this parameter if the value exists in the map and
160 * @c false otherwise.
161 *
162 * @return Returns @c MAP_OK if the check was performed successfully or an
163 * error code otherwise.
164 */
165MOCKABLE_FUNCTION(, MAP_RESULT, Map_ContainsValue, MAP_HANDLE, handle, const char*, value, bool*, valueExists);
166
167/**
168 * @brief Retrieves the value of a stored key.
169 *
170 * @param handle The handle to an existing map.
171 * @param key The key to be looked up in the map.
172 *
173 * @return Returns @c NULL in case the input arguments are @c NULL or if the
174 * requested key is not found in the map. Returns a pointer to the
175 * key's value otherwise.
176 */
177MOCKABLE_FUNCTION(, const char*, Map_GetValueFromKey, MAP_HANDLE, handle, const char*, key);
178
179/**
180 * @brief Retrieves the complete list of keys and values from the map
181 * in @p values and @p keys. Also writes the size of the list
182 * in @p count.
183 *
184 * @param handle The handle to an existing map.
185 * @param keys The location where the list of keys is to be written.
186 * @param values The location where the list of values is to be written.
187 * @param count The number of stored keys and values is written at the
188 * location indicated by this pointer.
189 *
190 * @return Returns @c MAP_OK if the keys and values are retrieved and written
191 * successfully or an error code otherwise.
192 */
193MOCKABLE_FUNCTION(, MAP_RESULT, Map_GetInternals, MAP_HANDLE, handle, const char*const**, keys, const char*const**, values, size_t*, count);
194
195/*this API creates a JSON object from the content of the map*/
196MOCKABLE_FUNCTION(, STRING_HANDLE, Map_ToJSON, MAP_HANDLE, handle);
197
198#ifdef __cplusplus
199}
200#endif
201
202#endif /* MAP_H */
Note: See TracBrowser for help on using the repository browser.