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/pop/Culture.cpp | 8 ++++---- src/openvic-simulation/pop/Culture.hpp | 10 +++++----- src/openvic-simulation/pop/Pop.cpp | 24 +++++++++--------------- 3 files changed, 18 insertions(+), 24 deletions(-) (limited to 'src/openvic-simulation/pop') diff --git a/src/openvic-simulation/pop/Culture.cpp b/src/openvic-simulation/pop/Culture.cpp index 9b9d6c2..2cd6005 100644 --- a/src/openvic-simulation/pop/Culture.cpp +++ b/src/openvic-simulation/pop/Culture.cpp @@ -16,7 +16,7 @@ CultureGroup::CultureGroup( Culture::Culture( std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group, - std::vector&& new_first_names, std::vector&& new_last_names + name_list_t&& new_first_names, name_list_t&& new_last_names ) : HasIdentifierAndColour { new_identifier, new_colour, false }, group { new_group }, first_names { std::move(new_first_names) }, last_names { std::move(new_last_names) } {} @@ -51,8 +51,8 @@ bool CultureManager::add_culture_group( } bool CultureManager::add_culture( - std::string_view identifier, colour_t colour, CultureGroup const& group, std::vector&& first_names, - std::vector&& last_names + std::string_view identifier, colour_t colour, CultureGroup const& group, name_list_t&& first_names, + name_list_t&& last_names ) { if (!culture_groups.is_locked()) { Logger::error("Cannot register cultures until culture groups are locked!"); @@ -99,7 +99,7 @@ bool CultureManager::_load_culture( ) { colour_t colour = colour_t::null(); - std::vector first_names, last_names; + name_list_t first_names, last_names; bool ret = expect_dictionary_keys( "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), diff --git a/src/openvic-simulation/pop/Culture.hpp b/src/openvic-simulation/pop/Culture.hpp index 1c6b75f..c8dfe7a 100644 --- a/src/openvic-simulation/pop/Culture.hpp +++ b/src/openvic-simulation/pop/Culture.hpp @@ -40,14 +40,14 @@ namespace OpenVic { private: CultureGroup const& PROPERTY(group); - const std::vector PROPERTY(first_names); - const std::vector PROPERTY(last_names); + const name_list_t PROPERTY(first_names); + const name_list_t PROPERTY(last_names); // TODO - radicalism, primary tag Culture( std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group, - std::vector&& new_first_names, std::vector&& new_last_names + name_list_t&& new_first_names, name_list_t&& new_last_names ); public: @@ -75,8 +75,8 @@ namespace OpenVic { ); bool add_culture( - std::string_view identifier, colour_t colour, CultureGroup const& group, std::vector&& first_names, - std::vector&& last_names + std::string_view identifier, colour_t colour, CultureGroup const& group, name_list_t&& first_names, + name_list_t&& last_names ); bool load_graphical_culture_type_file(ast::NodeCPtr root); diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index ce310e1..0c70842 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -194,14 +194,12 @@ bool PopManager::load_pop_type_file( "country_migration_target", ZERO_OR_ONE, country_migration_target.expect_conditional_weight(ConditionalWeight::FACTOR), "migration_target", ZERO_OR_ONE, migration_target.expect_conditional_weight(ConditionalWeight::FACTOR), "promote_to", ZERO_OR_ONE, assign_variable_callback(promote_to_node), - "ideologies", ZERO_OR_ONE, ideology_manager.expect_ideology_dictionary( + "ideologies", ZERO_OR_ONE, ideology_manager.expect_ideology_dictionary_reserve_length( + ideologies, [&filestem, &ideologies](Ideology const& ideology, ast::NodeCPtr node) -> bool { ConditionalWeight weight { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }; bool ret = weight.expect_conditional_weight(ConditionalWeight::FACTOR)(node); - if (!ideologies.emplace(&ideology, std::move(weight)).second) { - Logger::error("Duplicate ideology in pop type ", filestem, " ideology weights: ", ideology); - ret = false; - } + ret &= map_callback(ideologies, &ideology)(std::move(weight)); return ret; } ), @@ -233,7 +231,8 @@ bool PopManager::load_delayed_parse_pop_type_data(IssueManager const& issue_mana for (size_t index = 0; index < delayed_parse_promote_to_and_issues_nodes.size(); ++index) { const auto [promote_to_node, issues_node] = delayed_parse_promote_to_and_issues_nodes[index]; PopType* pop_type = pop_types.get_item_by_index(index); - if (promote_to_node != nullptr && !expect_pop_type_dictionary( + if (promote_to_node != nullptr && !expect_pop_type_dictionary_reserve_length( + pop_type->promote_to, [pop_type](PopType const& type, ast::NodeCPtr node) -> bool { if (pop_type == &type) { Logger::error("Pop type ", type, " cannot have promotion weight to itself!"); @@ -241,17 +240,15 @@ bool PopManager::load_delayed_parse_pop_type_data(IssueManager const& issue_mana } ConditionalWeight weight { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }; bool ret = weight.expect_conditional_weight(ConditionalWeight::FACTOR)(node); - if (!pop_type->promote_to.emplace(&type, std::move(weight)).second) { - Logger::error("Duplicate pop type in pop type ", pop_type, " promotion weights: ", type); - ret = false; - } + ret &= map_callback(pop_type->promote_to, &type)(std::move(weight)); return ret; } )(promote_to_node)) { Logger::error("Errors parsing pop type ", pop_type, " promotion weights!"); ret = false; } - if (issues_node != nullptr && !expect_dictionary( + if (issues_node != nullptr && !expect_dictionary_reserve_length( + pop_type->issues, [pop_type, &issue_manager](std::string_view key, ast::NodeCPtr node) -> bool { Issue const* issue = issue_manager.get_issue_by_identifier(key); if (issue == nullptr) { @@ -263,10 +260,7 @@ bool PopManager::load_delayed_parse_pop_type_data(IssueManager const& issue_mana } ConditionalWeight weight { scope_t::POP, scope_t::POP, scope_t::NO_SCOPE }; bool ret = weight.expect_conditional_weight(ConditionalWeight::FACTOR)(node); - if (!pop_type->issues.emplace(issue, std::move(weight)).second) { - Logger::error("Duplicate issue in pop type ", pop_type, " issue weights: ", issue->get_identifier()); - ret = false; - } + ret &= map_callback(pop_type->issues, issue)(std::move(weight)); return ret; } )(issues_node)) { -- cgit v1.2.3-56-ga3b1