carb::dictionary::setDictionaryFromStringMapping

Defined in carb/dictionary/DictionaryUtils.h

inline void carb::dictionary::setDictionaryFromStringMapping(IDictionary *id, Item *dict, const std::map<std::string, std::string> &mapping)

Sets a series of values in a dictionary based on keys and values in a map object.

Remark

This takes a map of path and value pairs and sets those values into the given dictionary dict. Each entry in the map identifies a potential new value to create in the dictionary. The paths to each of the new values do not have to already exist in the dictionary. The new items will be created as needed. If a given path already exists in the dictionary, its value is replaced with the one from the map. All values will attempt to auto-detect their type based on the content of the string value. See setDictionaryElementAutoType() for more info on how the types are detected.

Thread Safety

This itself operation is thread safe, but a race condition may still exist if multiple threads are trying to set the values for the same set of items simultaneously. The operation will succeed, but the value that gets set in each item in the end is undefined.

Note

If the map contains entries for an array and the array also exists in the dictionary, the resulting dictionary could have more or fewer elements in the array entries if the map either contained fewer items than the previous array’s size or contained a non-consecutive set of numbered elements in the array. If the array already exists in the dictionary, it will not be destroyed or removed before adding the new values.

Parameters
  • id[in] The IDictionary interface to use to access the items in the dictionary. This must not be nullptr. This must be the same interface that was originally used to create the dictionary dict.

  • dict[in] The base item to act as the root of where to set the values relative to. This may not be nullptr.

  • mapping[in] A map containing item paths (as the map keys) and their values to be set in the dictionary.

Returns

No return value.