rcutils  master
C API providing common utilities and data structures.
string_map.h
Go to the documentation of this file.
1 // Copyright 2017 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCUTILS__TYPES__STRING_MAP_H_
16 #define RCUTILS__TYPES__STRING_MAP_H_
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #include <string.h>
24 
25 #include "rcutils/allocator.h"
27 #include "rcutils/macros.h"
29 
30 struct rcutils_string_map_impl_t;
31 
33 {
34  struct rcutils_string_map_impl_t * impl;
36 
38 /*
39  * This function returns an empty and zero initialized string map struct.
40  *
41  * Example:
42  *
43  * ```c
44  * // Do not do this:
45  * // rcutils_string_map_t foo;
46  * // rcutils_string_map_fini(&foo); // undefined behavior!
47  *
48  * // Do this instead:
49  * rcutils_string_map_t bar = rcutils_get_zero_initialized_string_map();
50  * rcutils_string_map_fini(&bar); // ok
51  * ```
52  * */
57 
59 
97  rcutils_string_map_t * string_map,
98  size_t initial_capacity,
99  rcutils_allocator_t allocator);
100 
102 
115 
117 
135 rcutils_string_map_get_capacity(const rcutils_string_map_t * string_map, size_t * capacity);
136 
138 
154 rcutils_string_map_get_size(const rcutils_string_map_t * string_map, size_t * size);
155 
157 
182 rcutils_string_map_reserve(rcutils_string_map_t * string_map, size_t capacity);
183 
185 
200 
202 
220 rcutils_string_map_set(rcutils_string_map_t * string_map, const char * key, const char * value);
221 
223 
254  rcutils_string_map_t * string_map,
255  const char * key,
256  const char * value);
257 
259 
274 rcutils_string_map_unset(rcutils_string_map_t * string_map, const char * key);
275 
277 
292 bool
293 rcutils_string_map_key_exists(const rcutils_string_map_t * string_map, const char * key);
294 
296 
309 bool
311  const rcutils_string_map_t * string_map,
312  const char * key,
313  size_t key_length);
314 
316 
339 const char *
340 rcutils_string_map_get(const rcutils_string_map_t * string_map, const char * key);
341 
343 
357 const char *
359  const rcutils_string_map_t * string_map,
360  const char * key,
361  size_t key_length);
362 
364 
405 const char *
407  const rcutils_string_map_t * string_map,
408  const char * key);
409 
411 
432  const rcutils_string_map_t * src_string_map,
433  rcutils_string_map_t * dst_string_map);
434 
435 #ifdef __cplusplus
436 }
437 #endif
438 
439 #endif // RCUTILS__TYPES__STRING_MAP_H_
rcutils_string_map_key_existsn
bool rcutils_string_map_key_existsn(const rcutils_string_map_t *string_map, const char *key, size_t key_length)
Get whether or not a key of known length exists.
rcutils_string_map_t::impl
struct rcutils_string_map_impl_t * impl
Definition: string_map.h:34
rcutils_get_zero_initialized_string_map
rcutils_string_map_t rcutils_get_zero_initialized_string_map()
Return an empty string map struct.
rcutils_string_map_key_exists
bool rcutils_string_map_key_exists(const rcutils_string_map_t *string_map, const char *key)
Get whether or not a key exists.
rcutils_string_map_get_capacity
rcutils_ret_t rcutils_string_map_get_capacity(const rcutils_string_map_t *string_map, size_t *capacity)
Get the current capacity of the string map.
rcutils_string_map_getn
const char * rcutils_string_map_getn(const rcutils_string_map_t *string_map, const char *key, size_t key_length)
Get value given a key and key length.
rcutils_string_map_set_no_resize
rcutils_ret_t rcutils_string_map_set_no_resize(rcutils_string_map_t *string_map, const char *key, const char *value)
Set a key value pair in the map but only if the map has enough capacity.
macros.h
rcutils_string_map_reserve
rcutils_ret_t rcutils_string_map_reserve(rcutils_string_map_t *string_map, size_t capacity)
Reserve a given amount of capacity in the map.
rcutils_string_map_unset
rcutils_ret_t rcutils_string_map_unset(rcutils_string_map_t *string_map, const char *key)
Unset a key value pair in the map.
RCUTILS_PUBLIC_TYPE
#define RCUTILS_PUBLIC_TYPE
Definition: visibility_control.h:29
rcutils_string_map_copy
rcutils_ret_t rcutils_string_map_copy(const rcutils_string_map_t *src_string_map, rcutils_string_map_t *dst_string_map)
Copy all the key value pairs from one map into another, overwritting and resizing if needed.
rcutils_string_map_t
Definition: string_map.h:32
rcutils_ret_t
int rcutils_ret_t
Definition: rcutils_ret.h:23
rcutils_string_map_get
const char * rcutils_string_map_get(const rcutils_string_map_t *string_map, const char *key)
Get value given a key.
RCUTILS_WARN_UNUSED
#define RCUTILS_WARN_UNUSED
Definition: macros.h:24
rcutils_ret.h
rcutils_string_map_get_next_key
const char * rcutils_string_map_get_next_key(const rcutils_string_map_t *string_map, const char *key)
Get the next key in the map, unless NULL is given, then get the first key.
visibility_control.h
rcutils_string_map_t
struct rcutils_string_map_t rcutils_string_map_t
rcutils_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:45
allocator.h
rcutils_string_map_set
rcutils_ret_t rcutils_string_map_set(rcutils_string_map_t *string_map, const char *key, const char *value)
Set a key value pair in the map, increasing capacity if necessary.
RCUTILS_PUBLIC
#define RCUTILS_PUBLIC
Definition: visibility_control.h:23
rcutils_string_map_get_size
rcutils_ret_t rcutils_string_map_get_size(const rcutils_string_map_t *string_map, size_t *size)
Get the current size of the string map.
rcutils_string_map_fini
rcutils_ret_t rcutils_string_map_fini(rcutils_string_map_t *string_map)
Finalize the previously initialized string map struct.
rcutils_string_map_clear
rcutils_ret_t rcutils_string_map_clear(rcutils_string_map_t *string_map)
Remove all key value pairs from the map.
rcutils_string_map_init
rcutils_ret_t rcutils_string_map_init(rcutils_string_map_t *string_map, size_t initial_capacity, rcutils_allocator_t allocator)
Initialize a rcutils_string_map_t, allocating space for given capacity.