diff options
Diffstat (limited to 'src/openvic-simulation/politics')
-rw-r--r-- | src/openvic-simulation/politics/Rule.cpp | 28 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Rule.hpp | 6 |
2 files changed, 11 insertions, 23 deletions
diff --git a/src/openvic-simulation/politics/Rule.cpp b/src/openvic-simulation/politics/Rule.cpp index f2c0f8d..75c868a 100644 --- a/src/openvic-simulation/politics/Rule.cpp +++ b/src/openvic-simulation/politics/Rule.cpp @@ -98,13 +98,9 @@ RuleSet::rule_map_t const& RuleSet::get_rule_group(Rule::rule_group_t group, boo return empty_map; } -bool RuleSet::get_rule(Rule const* rule, bool* successful) const { - if (rule == nullptr) { - Logger::error("Invalid rule - null!"); - return false; - } - rule_map_t const& rule_map = get_rule_group(rule->get_group()); - const rule_map_t::const_iterator it = rule_map.find(rule); +bool RuleSet::get_rule(Rule const& rule, bool* successful) const { + rule_map_t const& rule_map = get_rule_group(rule.get_group()); + const rule_map_t::const_iterator it = rule_map.find(&rule); if (it != rule_map.end()) { if (successful != nullptr) { *successful = true; @@ -114,23 +110,15 @@ bool RuleSet::get_rule(Rule const* rule, bool* successful) const { if (successful != nullptr) { *successful = false; } - return Rule::is_default_enabled(rule->get_group()); + return Rule::is_default_enabled(rule.get_group()); } -bool RuleSet::has_rule(Rule const* rule) const { - if (rule == nullptr) { - Logger::error("Invalid rule - null!"); - return false; - } - return get_rule_group(rule->get_group()).contains(rule); +bool RuleSet::has_rule(Rule const& rule) const { + return get_rule_group(rule.get_group()).contains(&rule); } -bool RuleSet::set_rule(Rule const* rule, bool value) { - if (rule == nullptr) { - Logger::error("Invalid rule - null!"); - return false; - } - rule_groups[rule->get_group()][rule] = value; +bool RuleSet::set_rule(Rule const& rule, bool value) { + rule_groups[rule.get_group()][&rule] = value; return true; } diff --git a/src/openvic-simulation/politics/Rule.hpp b/src/openvic-simulation/politics/Rule.hpp index 579299b..af02846 100644 --- a/src/openvic-simulation/politics/Rule.hpp +++ b/src/openvic-simulation/politics/Rule.hpp @@ -66,11 +66,11 @@ namespace OpenVic { bool empty() const; rule_map_t const& get_rule_group(Rule::rule_group_t group, bool* successful = nullptr) const; - bool get_rule(Rule const* rule, bool* successful = nullptr) const; - bool has_rule(Rule const* rule) const; + bool get_rule(Rule const& rule, bool* successful = nullptr) const; + bool has_rule(Rule const& rule) const; /* Sets the rule to the specified value. Returns false if there was an existing rule, regardless of its value. */ - bool set_rule(Rule const* rule, bool value); + bool set_rule(Rule const& rule, bool value); RuleSet& operator|=(RuleSet const& right); RuleSet operator|(RuleSet const& right) const; |