1 #ifndef UTOPIA_MODELS_ENVIRONMENT_TOOLS_HH
2 #define UTOPIA_MODELS_ENVIRONMENT_TOOLS_HH
20 const std::string& context)
22 const auto mode_key = get_as<std::string>(
"mode", cfg);
24 if (mode_key ==
"add") {
27 else if (mode_key ==
"set") {
31 throw std::invalid_argument(
"The `mode` argument for configuration of "
32 "environment function " + context +
" can be 'add' or 'set', but "
33 "was '" + mode_key +
"'!");
38 template <
typename Time>
40 bool invoke_always =
true;
43 if (not cfg.IsMap()) {
45 return {invoke_always, times};
50 invoke_always =
false;
51 auto times_list = get_as<std::vector<Time>>(
"times", cfg);
58 std::remove_if(times_list.begin(), times_list.end(),
59 [](
auto& t){ return (t <= 0); }),
64 times.insert(times_list.begin(), times_list.end());
67 return {invoke_always, times};
72 template <
typename Time>
73 std::tuple<bool, bool, std::set<Time>>
76 bool invoke_at_initialization = get_as<bool>(
"invoke_at_initialization",
79 auto [invoke_always, times] = extract_times<Time>(cfg);
81 return {invoke_at_initialization, invoke_always, times};
85 template <
typename Time>
88 auto times_list = get_as<std::vector<Time>>(
"times", cfg, {0});
89 auto time_start = times_list.front();
90 for (
auto t : times_list) {
91 if (t < time_start and t >= 0)
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:71
Time extract_time_start(const DataIO::Config &cfg)
Given a configuration, extracts the time of first function invocation.
Definition: tools.hh:86
ValMode extract_val_mode(const DataIO::Config &cfg, const std::string &context)
Given a configuration node, extract the value mode.
Definition: tools.hh:19
std::pair< bool, std::set< Time > > extract_times(const DataIO::Config &cfg)
Definition: tools.hh:39
ValMode
Value calculation mode.
Definition: tools.hh:10
std::tuple< bool, bool, std::set< Time > > extract_times_and_initialization(const DataIO::Config &cfg)
Definition: tools.hh:74
@ Set
Set a value, discarding the current state.
@ Add
Add the new value to the existing value.
Definition: env_param_func_collection.hh:8