Function rcutils_string_map_set_no_resize

Function Documentation

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.

If the map already contains the given key, the existing value will be replaced with the given value. If the map does not contain the given key, and the map has additional unused capacity, then it will store the given key and value in the map. If there is no unused capacity in the map, then RCUTILS_RET_NOT_ENOUGH_SPACE is returned.

The given key and value c strings are copied into the map, and so storage is allocated for them in the map when this function is called if necessary. The storage allocated for this purpose is reclaimed either when rcutils_string_map_fini() is called on this map or when using this function or rcutils_string_map_unset().

Any allocation that occurs in this functions uses the allocator of the map, which is given when the map is initialized in rcutils_string_map_init().

Parameters:
  • string_map[inout] rcutils_string_map_t to be updated

  • key[in] map key, must be null terminated c string

  • value[in] value for given map key, must be null terminated c string

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_INVALID if the string map is invalid, or

Returns:

RCUTILS_RET_NOT_ENOUGH_SPACE if map is full, or

Returns:

RCUTILS_RET_ERROR if an unknown error occurs.