diff options
author | hop311 <hop3114@gmail.com> | 2024-01-22 21:02:58 +0100 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-01-23 23:14:53 +0100 |
commit | 268a6948c0400905dfc335427395519689f067f5 (patch) | |
tree | b30e9b5774130552fe97e27deaf0370d83920c43 /src/openvic-simulation/politics | |
parent | d4e597da089a81f719a9c33b46111d1c2c590124 (diff) |
Added reserve_more, expect_dictionary_key[s|_map]_reserve_length[_and_default]reserve_more
Diffstat (limited to 'src/openvic-simulation/politics')
-rw-r--r-- | src/openvic-simulation/politics/Government.cpp | 3 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Ideology.cpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Issue.cpp | 61 | ||||
-rw-r--r-- | src/openvic-simulation/politics/NationalFocus.cpp | 2 | ||||
-rw-r--r-- | src/openvic-simulation/politics/NationalValue.cpp | 4 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Rebel.cpp | 3 | ||||
-rw-r--r-- | src/openvic-simulation/politics/Rule.cpp | 2 |
7 files changed, 47 insertions, 33 deletions
diff --git a/src/openvic-simulation/politics/Government.cpp b/src/openvic-simulation/politics/Government.cpp index 49e0f2f..28f5d09 100644 --- a/src/openvic-simulation/politics/Government.cpp +++ b/src/openvic-simulation/politics/Government.cpp @@ -47,7 +47,8 @@ bool GovernmentTypeManager::add_government_type( /* REQUIREMENTS: FS-525, SIM-27 */ bool GovernmentTypeManager::load_government_types_file(IdeologyManager const& ideology_manager, ast::NodeCPtr root) { - bool ret = expect_dictionary_reserve_length(government_types, + bool ret = expect_dictionary_reserve_length( + government_types, [this, &ideology_manager](std::string_view government_type_identifier, ast::NodeCPtr government_type_value) -> bool { std::vector<Ideology const*> ideologies; bool elections = false, appoint_ruling_party = false; diff --git a/src/openvic-simulation/politics/Ideology.cpp b/src/openvic-simulation/politics/Ideology.cpp index 692b809..1848a0a 100644 --- a/src/openvic-simulation/politics/Ideology.cpp +++ b/src/openvic-simulation/politics/Ideology.cpp @@ -68,7 +68,8 @@ bool IdeologyManager::add_ideology( */ bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) { size_t expected_ideologies = 0; - bool ret = expect_dictionary_reserve_length(ideology_groups, + bool ret = expect_dictionary_reserve_length( + ideology_groups, [this, &expected_ideologies](std::string_view key, ast::NodeCPtr value) -> bool { bool ret = expect_length(add_variable_callback(expected_ideologies))(value); ret &= add_ideology_group(key); @@ -77,7 +78,7 @@ bool IdeologyManager::load_ideology_file(ast::NodeCPtr root) { )(root); lock_ideology_groups(); - ideologies.reserve(ideologies.size() + expected_ideologies); + reserve_more_ideologies(expected_ideologies); ret &= expect_dictionary([this](std::string_view ideology_group_key, ast::NodeCPtr ideology_group_value) -> bool { IdeologyGroup const* ideology_group = get_ideology_group_by_identifier(ideology_group_key); 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(); diff --git a/src/openvic-simulation/politics/NationalFocus.cpp b/src/openvic-simulation/politics/NationalFocus.cpp index f555172..22b91b2 100644 --- a/src/openvic-simulation/politics/NationalFocus.cpp +++ b/src/openvic-simulation/politics/NationalFocus.cpp @@ -84,7 +84,7 @@ bool NationalFocusManager::load_national_foci_file( )(root); lock_national_focus_groups(); - national_foci.reserve(expected_national_foci); + reserve_more_national_foci(expected_national_foci); ret &= expect_national_focus_group_dictionary([this, &pop_manager, &ideology_manager, &good_manager, &modifier_manager]( NationalFocusGroup const& group, ast::NodeCPtr group_node diff --git a/src/openvic-simulation/politics/NationalValue.cpp b/src/openvic-simulation/politics/NationalValue.cpp index 57c5652..a149acf 100644 --- a/src/openvic-simulation/politics/NationalValue.cpp +++ b/src/openvic-simulation/politics/NationalValue.cpp @@ -16,7 +16,8 @@ bool NationalValueManager::add_national_value(std::string_view identifier, Modif } bool NationalValueManager::load_national_values_file(ModifierManager const& modifier_manager, ast::NodeCPtr root) { - bool ret = expect_dictionary( + bool ret = expect_dictionary_reserve_length( + national_values, [this, &modifier_manager](std::string_view national_value_identifier, ast::NodeCPtr value) -> bool { ModifierValue modifiers; @@ -26,6 +27,7 @@ bool NationalValueManager::load_national_values_file(ModifierManager const& modi return ret; } )(root); + lock_national_values(); return ret; diff --git a/src/openvic-simulation/politics/Rebel.cpp b/src/openvic-simulation/politics/Rebel.cpp index 2f39bee..ce99d08 100644 --- a/src/openvic-simulation/politics/Rebel.cpp +++ b/src/openvic-simulation/politics/Rebel.cpp @@ -95,7 +95,8 @@ bool RebelManager::load_rebels_file( { "any", RebelType::independence_t::ANY } }; - bool ret = expect_dictionary( + bool ret = expect_dictionary_reserve_length( + rebel_types, [this, &ideology_manager, &government_type_manager](std::string_view identifier, ast::NodeCPtr node) -> bool { RebelType::icon_t icon = 0; RebelType::area_t area = RebelType::area_t::ALL; diff --git a/src/openvic-simulation/politics/Rule.cpp b/src/openvic-simulation/politics/Rule.cpp index 19e92af..ce0c319 100644 --- a/src/openvic-simulation/politics/Rule.cpp +++ b/src/openvic-simulation/politics/Rule.cpp @@ -161,7 +161,7 @@ bool RuleManager::setup_rules(BuildingTypeManager const& building_type_manager) for (auto const& [group, rule_list] : hardcoded_rules) { rule_count += rule_list.size(); } - rules.reserve(rule_count); + reserve_more_rules(rule_count); for (auto const& [group, rule_list] : hardcoded_rules) { for (std::string_view const& rule : rule_list) { |