Function rcutils_string_map_init

Function Documentation

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.

This function initializes the rcutils_string_map_t with a given initial capacity for entries. Note this does not allocate space for keys or values in the map, just the arrays of pointers to the keys and values. rcutils_string_map_set() should still be used when assigning values.

The string_map argument should point to allocated memory and should have been zero initialized with rcutils_get_zero_initialized_string_map(). For example:

rcutils_string_map_t string_map = rcutils_get_zero_initialized_string_map();
rcutils_ret_t ret =
  rcutils_string_map_init(&string_map, 10, rcutils_get_default_allocator());
if (ret != RCUTILS_RET_OK) {
  // ... do error handling
}
// ... use the string map and when done:
ret = rcutils_string_map_fini(&string_map);
if (ret != RCUTILS_RET_OK) {
  // ... do error handling
}
Parameters:
  • string_map[inout] rcutils_string_map_t to be initialized

  • initial_capacity[in] the amount of initial capacity for the string map

  • allocator[in] the allocator to use through out the lifetime of the map

Returns:

RCUTILS_RET_OK if successful, or

Returns:

RCUTILS_RET_INVALID_ARGUMENT for invalid arguments, or

Returns:

RCUTILS_RET_BAD_ALLOC if memory allocation fails, or

Returns:

RCUTILS_RET_STRING_MAP_ALREADY_INIT if already initialized, or

Returns:

RCUTILS_RET_ERROR if an unknown error occurs.