diff options
author | Hop311 <Hop3114@gmail.com> | 2023-09-26 18:15:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-26 18:15:43 +0200 |
commit | ca3996510ed6e26a81c781992d33c335ca250a16 (patch) | |
tree | e456ce0a8355ae2936d78a99b6c77ef785a8e5d5 /src/openvic-simulation/Modifier.cpp | |
parent | 63e462fceff981f79bcbae53e8d90fc59733e8c2 (diff) | |
parent | 1c7b3239ab4e9f75d0605e5da852daf5afaa8c4a (diff) |
Merge pull request #35 from OpenVicProject/expect-modifier-keys
Expect modifier value + keys function
Diffstat (limited to 'src/openvic-simulation/Modifier.cpp')
-rw-r--r-- | src/openvic-simulation/Modifier.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/openvic-simulation/Modifier.cpp b/src/openvic-simulation/Modifier.cpp index 9fa0691..3ec5474 100644 --- a/src/openvic-simulation/Modifier.cpp +++ b/src/openvic-simulation/Modifier.cpp @@ -131,8 +131,8 @@ bool ModifierManager::setup_modifier_effects() { return ret; } -node_callback_t ModifierManager::expect_modifier_value(callback_t<ModifierValue&&> callback, key_value_callback_t default_callback) const { - return [this, callback, default_callback](ast::NodeCPtr root) -> bool { +node_callback_t ModifierManager::expect_modifier_value(callback_t<ModifierValue&&> modifier_callback, key_value_callback_t default_callback) const { + return [this, modifier_callback, default_callback](ast::NodeCPtr root) -> bool { ModifierValue modifier; bool ret = expect_dictionary( [this, &modifier, default_callback](std::string_view key, ast::NodeCPtr value) -> bool { @@ -149,7 +149,17 @@ node_callback_t ModifierManager::expect_modifier_value(callback_t<ModifierValue& return default_callback(key, value); } )(root); - ret &= callback(std::move(modifier)); + ret &= modifier_callback(std::move(modifier)); + return ret; + }; +} + +node_callback_t ModifierManager::_expect_modifier_value_and_keys(callback_t<ModifierValue&&> modifier_callback, key_map_t&& key_map) const { + return [this, modifier_callback, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> bool { + bool ret = expect_modifier_value( + modifier_callback, dictionary_keys_callback(key_map, false) + )(node); + ret &= check_key_map_counts(key_map); return ret; }; } |