diff options
author | hop311 <hop3114@gmail.com> | 2024-01-08 23:19:39 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-01-08 23:19:39 +0100 |
commit | 83802dfead4938e6f98b4b9961b286e06ab78b18 (patch) | |
tree | b0b404a1826d455767b16d3e3ae1d6bf7516e06d /src/openvic-simulation/politics/Rule.cpp | |
parent | 79b8b73304753fedab822e6aa859fa15673f52cc (diff) |
Added map_callback and expect_item_dictionary_reserve_length
Diffstat (limited to 'src/openvic-simulation/politics/Rule.cpp')
-rw-r--r-- | src/openvic-simulation/politics/Rule.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/openvic-simulation/politics/Rule.cpp b/src/openvic-simulation/politics/Rule.cpp index 9ac992a..19e92af 100644 --- a/src/openvic-simulation/politics/Rule.cpp +++ b/src/openvic-simulation/politics/Rule.cpp @@ -109,8 +109,8 @@ bool RuleSet::set_rule(Rule const* rule, bool value) { Logger::error("Invalid rule - null!"); return false; } - rule_map_t& rule_map = rule_groups[rule->get_group()]; - return rule_groups[rule->get_group()].emplace(rule, value).second; + rule_groups[rule->get_group()][rule] = value; + return true; } RuleSet& RuleSet::operator|=(RuleSet const& right) { @@ -193,10 +193,9 @@ node_callback_t RuleManager::expect_rule_set(callback_t<RuleSet&&> ruleset_callb if (rule != nullptr) { return expect_bool( [&ruleset, rule](bool value) -> bool { - if (!ruleset.rule_groups[rule->get_group()].emplace(rule, value).second) { - Logger::warning("Duplicate rule entry: ", rule, " - ignoring!"); - } - return true; + /* Wrapped in a lambda function so that the rule group is only initialised + * if the value bool is successfully parsed. */ + return map_callback(ruleset.rule_groups[rule->get_group()], rule)(value); } )(rule_value); } else { |