From 83802dfead4938e6f98b4b9961b286e06ab78b18 Mon Sep 17 00:00:00 2001 From: hop311 Date: Mon, 8 Jan 2024 22:19:39 +0000 Subject: Added map_callback and expect_item_dictionary_reserve_length --- src/openvic-simulation/politics/Rule.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/openvic-simulation/politics/Rule.cpp') 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_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 { -- cgit v1.2.3-56-ga3b1