NGen
Loading...
Searching...
No Matches
properties.hpp
1#ifndef NGEN_REALIZATION_CONFIG_PROPERTIES_H
2#define NGEN_REALIZATION_CONFIG_PROPERTIES_H
3
4#include <string>
5
6#include "JSONProperty.hpp"
7
8namespace realization{
9 namespace config{
10
23 inline void pattern_substitution(geojson::PropertyMap &properties, const std::string &key,
24 const std::string &pattern, const std::string &replacement)
25 {
26 auto it = properties.find(key);
27 // Do nothing and return if either the key isn't found or the associated property isn't a string
28 if (it == properties.end() || it->second.get_type() != geojson::PropertyType::String) {
29 return;
30 }
31
32 std::string value = it->second.as_string();
33
34 size_t id_index = value.find(pattern);
35
36 if (id_index != std::string::npos) {
37 do {
38 value = value.replace(id_index, sizeof(pattern.c_str()) - 2, replacement);
39 id_index = value.find(pattern);
40 } while (id_index != std::string::npos);
41
42 properties.erase(key);
43 properties.emplace(key, geojson::JSONProperty(key, value));
44 }
45 }
46
47 }//end namespace config
48}//end namespace realization
49
50#endif // NGEN_REALIZATION_CONFIG_PROPERTIES_H
@TODO: Convert JSONProperty into a variant of the supported types
Definition JSONProperty.hpp:161
std::map< std::string, JSONProperty > PropertyMap
Shorthand for a mapping between strings and properties.
Definition JSONProperty.hpp:21
void pattern_substitution(geojson::PropertyMap &properties, const std::string &key, const std::string &pattern, const std::string &replacement)
Perform in-place substitution on the given config property item, if the item and the pattern are pres...
Definition properties.hpp:23
Definition HY_CatchmentRealization.hpp:13