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/pop | |
parent | d4e597da089a81f719a9c33b46111d1c2c590124 (diff) |
Added reserve_more, expect_dictionary_key[s|_map]_reserve_length[_and_default]reserve_more
Diffstat (limited to 'src/openvic-simulation/pop')
-rw-r--r-- | src/openvic-simulation/pop/Culture.cpp | 5 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.cpp | 17 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Pop.hpp | 3 | ||||
-rw-r--r-- | src/openvic-simulation/pop/Religion.cpp | 35 |
4 files changed, 37 insertions, 23 deletions
diff --git a/src/openvic-simulation/pop/Culture.cpp b/src/openvic-simulation/pop/Culture.cpp index 53273f5..9466e9f 100644 --- a/src/openvic-simulation/pop/Culture.cpp +++ b/src/openvic-simulation/pop/Culture.cpp @@ -74,7 +74,8 @@ bool CultureManager::add_culture( } bool CultureManager::load_graphical_culture_type_file(ast::NodeCPtr root) { - const bool ret = expect_list_reserve_length(graphical_culture_types, + const bool ret = expect_list_reserve_length( + graphical_culture_types, expect_identifier(std::bind_front(&CultureManager::add_graphical_culture_type, this)) )(root); lock_graphical_culture_types(); @@ -169,7 +170,7 @@ bool CultureManager::load_culture_file(CountryManager const& country_manager, as } )(root); lock_culture_groups(); - cultures.reserve(cultures.size() + total_expected_cultures); + reserve_more_cultures(total_expected_cultures); ret &= expect_culture_group_dictionary( [this, &country_manager](CultureGroup const& culture_group, ast::NodeCPtr culture_group_value) -> bool { diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp index d422038..643f313 100644 --- a/src/openvic-simulation/pop/Pop.cpp +++ b/src/openvic-simulation/pop/Pop.cpp @@ -273,10 +273,19 @@ bool PopManager::add_pop_type( return ret; } -void PopManager::reserve_pop_types(size_t count) { - stratas.reserve(stratas.size() + count); - pop_types.reserve(pop_types.size() + count); - delayed_parse_nodes.reserve(delayed_parse_nodes.size() + count); +void PopManager::reserve_all_pop_types(size_t size) { + reserve_more_stratas(size); + if (pop_types_are_locked()) { + Logger::error("Failed to reserve space for ", size, " pop types in PopManager - already locked!"); + } else { + reserve_more_pop_types(size); + reserve_more(delayed_parse_nodes, size); + } +} + +void PopManager::lock_all_pop_types() { + lock_stratas(); + lock_pop_types(); } static NodeCallback auto expect_needs_income(PopType::income_type_t& types) { diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp index 4e173bb..3e50c4d 100644 --- a/src/openvic-simulation/pop/Pop.hpp +++ b/src/openvic-simulation/pop/Pop.hpp @@ -286,7 +286,8 @@ namespace OpenVic { ast::NodeCPtr issues_node ); - void reserve_pop_types(size_t count); + void reserve_all_pop_types(size_t size); + void lock_all_pop_types(); bool load_pop_type_file( std::string_view filestem, UnitManager const& unit_manager, GoodManager const& good_manager, diff --git a/src/openvic-simulation/pop/Religion.cpp b/src/openvic-simulation/pop/Religion.cpp index 0527da7..3fa81bf 100644 --- a/src/openvic-simulation/pop/Religion.cpp +++ b/src/openvic-simulation/pop/Religion.cpp @@ -47,7 +47,8 @@ bool ReligionManager::add_religion( */ bool ReligionManager::load_religion_file(ast::NodeCPtr root) { size_t total_expected_religions = 0; - bool ret = expect_dictionary_reserve_length(religion_groups, + bool ret = expect_dictionary_reserve_length( + religion_groups, [this, &total_expected_religions](std::string_view key, ast::NodeCPtr value) -> bool { bool ret = expect_length(add_variable_callback(total_expected_religions))(value); ret &= add_religion_group(key); @@ -55,22 +56,24 @@ bool ReligionManager::load_religion_file(ast::NodeCPtr root) { } )(root); lock_religion_groups(); - religions.reserve(religions.size() + total_expected_religions); - ret &= expect_religion_group_dictionary([this](ReligionGroup const& religion_group, ast::NodeCPtr religion_group_value) -> bool { - return expect_dictionary([this, &religion_group](std::string_view key, ast::NodeCPtr value) -> bool { - colour_t colour = colour_t::null(); - Religion::icon_t icon = 0; - bool pagan = false; + reserve_more_religions(total_expected_religions); + ret &= expect_religion_group_dictionary( + [this](ReligionGroup const& religion_group, ast::NodeCPtr religion_group_value) -> bool { + return expect_dictionary([this, &religion_group](std::string_view key, ast::NodeCPtr value) -> bool { + colour_t colour = colour_t::null(); + Religion::icon_t icon = 0; + bool pagan = false; - bool ret = expect_dictionary_keys( - "icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)), - "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), - "pagan", ZERO_OR_ONE, expect_bool(assign_variable_callback(pagan)) - )(value); - ret &= add_religion(key, colour, religion_group, icon, pagan); - return ret; - })(religion_group_value); - })(root); + bool ret = expect_dictionary_keys( + "icon", ONE_EXACTLY, expect_uint(assign_variable_callback(icon)), + "color", ONE_EXACTLY, expect_colour(assign_variable_callback(colour)), + "pagan", ZERO_OR_ONE, expect_bool(assign_variable_callback(pagan)) + )(value); + ret &= add_religion(key, colour, religion_group, icon, pagan); + return ret; + })(religion_group_value); + } + )(root); lock_religions(); return ret; } |