aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/politics/Issue.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-01-24 01:47:16 +0100
committer GitHub <noreply@github.com>2024-01-24 01:47:16 +0100
commit6bcb1e70a15755ceb0aaa13a080f85f8edb50911 (patch)
treeb30e9b5774130552fe97e27deaf0370d83920c43 /src/openvic-simulation/politics/Issue.cpp
parentd4e597da089a81f719a9c33b46111d1c2c590124 (diff)
parent268a6948c0400905dfc335427395519689f067f5 (diff)
Merge pull request #137 from OpenVicProject/reserve_more
Added reserve_more, expect_dictionary_key[s|_map]_reserve_length[_and_default]
Diffstat (limited to 'src/openvic-simulation/politics/Issue.cpp')
-rw-r--r--src/openvic-simulation/politics/Issue.cpp61
1 files changed, 35 insertions, 26 deletions
diff --git a/src/openvic-simulation/politics/Issue.cpp b/src/openvic-simulation/politics/Issue.cpp
index 30dc1cd..d8fe52e 100644
--- a/src/openvic-simulation/politics/Issue.cpp
+++ b/src/openvic-simulation/politics/Issue.cpp
@@ -191,7 +191,8 @@ bool IssueManager::_load_reform(
bool IssueManager::load_issues_file(ModifierManager const& modifier_manager, RuleManager const& rule_manager, ast::NodeCPtr root) {
size_t expected_issue_groups = 0;
size_t expected_reform_groups = 0;
- bool ret = expect_dictionary_reserve_length(reform_types,
+ bool ret = expect_dictionary_reserve_length(
+ reform_types,
[this, &expected_issue_groups, &expected_reform_groups](std::string_view key, ast::NodeCPtr value) -> bool {
if (key == "party_issues") {
return expect_length(add_variable_callback(expected_issue_groups))(value);
@@ -206,12 +207,12 @@ bool IssueManager::load_issues_file(ModifierManager const& modifier_manager, Rul
)(root);
lock_reform_types();
- issue_groups.reserve(issue_groups.size() + expected_issue_groups);
- reform_groups.reserve(reform_groups.size() + expected_reform_groups);
+ reserve_more_issue_groups(expected_issue_groups);
+ reserve_more_reform_groups(expected_reform_groups);
size_t expected_issues = 0;
size_t expected_reforms = 0;
- ret &= expect_dictionary_reserve_length(issue_groups,
+ ret &= expect_dictionary(
[this, &expected_issues, &expected_reforms](std::string_view type_key, ast::NodeCPtr type_value) -> bool {
if (type_key == "party_issues") {
return expect_dictionary([this, &expected_issues](std::string_view key, ast::NodeCPtr value) -> bool {
@@ -230,28 +231,36 @@ bool IssueManager::load_issues_file(ModifierManager const& modifier_manager, Rul
lock_issue_groups();
lock_reform_groups();
- issues.reserve(issues.size() + expected_issues);
- reforms.reserve(reforms.size() + expected_reforms);
-
- ret &= expect_dictionary([this, &modifier_manager, &rule_manager](std::string_view type_key, ast::NodeCPtr type_value) -> bool {
- return expect_dictionary([this, &modifier_manager, &rule_manager, type_key](std::string_view group_key, ast::NodeCPtr group_value) -> bool {
- if (type_key == "party_issues") {
- IssueGroup const* issue_group = get_issue_group_by_identifier(group_key);
- return expect_dictionary([this, &modifier_manager, &rule_manager, issue_group](std::string_view key, ast::NodeCPtr value) -> bool {
- return _load_issue(modifier_manager, rule_manager, key, issue_group, value);
- })(group_value);
- } else {
- ReformGroup const* reform_group = get_reform_group_by_identifier(group_key);
- size_t ordinal = 0;
- return expect_dictionary([this, &modifier_manager, &rule_manager, reform_group, &ordinal](std::string_view key, ast::NodeCPtr value) -> bool {
- if (key == "next_step_only" || key == "administrative") {
- return true;
- }
- return _load_reform(modifier_manager, rule_manager, ordinal++, key, reform_group, value);
- })(group_value);
- }
- })(type_value);
- })(root);
+ reserve_more_issues(expected_issues);
+ reserve_more_reforms(expected_reforms);
+
+ ret &= expect_dictionary(
+ [this, &modifier_manager, &rule_manager](std::string_view type_key, ast::NodeCPtr type_value) -> bool {
+ return expect_dictionary([this, &modifier_manager, &rule_manager, type_key](
+ std::string_view group_key, ast::NodeCPtr group_value
+ ) -> bool {
+ if (type_key == "party_issues") {
+ IssueGroup const* issue_group = get_issue_group_by_identifier(group_key);
+ return expect_dictionary([this, &modifier_manager, &rule_manager, issue_group](
+ std::string_view key, ast::NodeCPtr value
+ ) -> bool {
+ return _load_issue(modifier_manager, rule_manager, key, issue_group, value);
+ })(group_value);
+ } else {
+ ReformGroup const* reform_group = get_reform_group_by_identifier(group_key);
+ size_t ordinal = 0;
+ return expect_dictionary([this, &modifier_manager, &rule_manager, reform_group, &ordinal](
+ std::string_view key, ast::NodeCPtr value
+ ) -> bool {
+ if (key == "next_step_only" || key == "administrative") {
+ return true;
+ }
+ return _load_reform(modifier_manager, rule_manager, ordinal++, key, reform_group, value);
+ })(group_value);
+ }
+ })(type_value);
+ }
+ )(root);
lock_issues();
lock_reforms();