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 
16 
17 #ifndef RCUTILS__TYPES__STRING_MAP_H_
18 #define RCUTILS__TYPES__STRING_MAP_H_
19 
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include <string.h>
26 
27 #include "rcutils/allocator.h"
29 #include "rcutils/macros.h"
31 
32 struct rcutils_string_map_impl_t;
33 
36 {
38  struct rcutils_string_map_impl_t * impl;
40 
42 
61 
63 
101  rcutils_string_map_t * string_map,
102  size_t initial_capacity,
103  rcutils_allocator_t allocator);
104 
106 
119 
121 
139 rcutils_string_map_get_capacity(const rcutils_string_map_t * string_map, size_t * capacity);
140 
142 
158 rcutils_string_map_get_size(const rcutils_string_map_t * string_map, size_t * size);
159 
161 
186 rcutils_string_map_reserve(rcutils_string_map_t * string_map, size_t capacity);
187 
189 
204 
206 
224 rcutils_string_map_set(rcutils_string_map_t * string_map, const char * key, const char * value);
225 
227 
258  rcutils_string_map_t * string_map,
259  const char * key,
260  const char * value);
261 
263 
278 rcutils_string_map_unset(rcutils_string_map_t * string_map, const char * key);
279 
281 
296 bool
297 rcutils_string_map_key_exists(const rcutils_string_map_t * string_map, const char * key);
298 
300 
313 bool
315  const rcutils_string_map_t * string_map,
316  const char * key,
317  size_t key_length);
318 
320 
343 const char *
344 rcutils_string_map_get(const rcutils_string_map_t * string_map, const char * key);
345 
347 
361 const char *
363  const rcutils_string_map_t * string_map,
364  const char * key,
365  size_t key_length);
366 
368 
409 const char *
411  const rcutils_string_map_t * string_map,
412  const char * key);
413 
415 
436  const rcutils_string_map_t * src_string_map,
437  rcutils_string_map_t * dst_string_map);
438 
439 #ifdef __cplusplus
440 }
441 #endif
442 
443 #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
A pointer to the PIMPL implementation type.
Definition: string_map.h:38
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
The structure holding the metadata for a string map.
Definition: string_map.h:35
rcutils_ret_t
int rcutils_ret_t
The type that holds a return value for an rcutils operation.
Definition: rcutils_ret.h:26
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
A macro to make the compiler warn when the return value of a function is not used.
Definition: macros.h:27
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
The structure holding the metadata for a string map.
rcutils_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:47
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.