Skip to content

Commit e5b6551

Browse files
authored
Merge pull request #449 from OpenVicProject/prefer/span-2
Move even more const reference vectors to span
2 parents 8de8708 + 9f5e346 commit e5b6551

39 files changed

+745
-244
lines changed

src/openvic-simulation/GameManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bool GameManager::load_mod_descriptors(std::span<const std::string> descriptors)
2121
return true;
2222
}
2323

24-
bool GameManager::set_roots(Dataloader::path_vector_t const& roots, Dataloader::path_vector_t const& replace_paths) {
24+
bool GameManager::set_roots(Dataloader::path_span_t roots, Dataloader::path_span_t replace_paths) {
2525
if (!dataloader.set_roots(roots, replace_paths)) {
2626
Logger::error("Failed to set dataloader roots!");
2727
return false;

src/openvic-simulation/GameManager.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <optional>
4+
#include <span>
45

56
#include "openvic-simulation/DefinitionManager.hpp"
67
#include "openvic-simulation/InstanceManager.hpp"
@@ -35,7 +36,7 @@ namespace OpenVic {
3536
return instance_manager ? &*instance_manager : nullptr;
3637
}
3738

38-
bool set_roots(Dataloader::path_vector_t const& roots, Dataloader::path_vector_t const& replace_paths);
39+
bool set_roots(Dataloader::path_span_t roots, Dataloader::path_span_t replace_paths);
3940

4041
bool load_mod_descriptors(std::span<const std::string> descriptors);
4142

src/openvic-simulation/country/CountryDefinition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ node_callback_t CountryDefinitionManager::load_country_party(
153153
std::string_view party_name;
154154
Date start_date, end_date;
155155
Ideology const* ideology = nullptr;
156-
CountryParty::policy_map_t policies { &politics_manager.get_issue_manager().get_issue_groups() };
156+
CountryParty::policy_map_t policies { politics_manager.get_issue_manager().get_issue_groups() };
157157

158158
bool ret = expect_dictionary_keys_and_default(
159159
[&politics_manager, &policies, &party_name](std::string_view key, ast::NodeCPtr value) -> bool {

src/openvic-simulation/country/CountryInstance.cpp

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "openvic-simulation/country/CountryDefinition.hpp"
77
#include "openvic-simulation/defines/Define.hpp"
88
#include "openvic-simulation/DefinitionManager.hpp"
9+
#include "openvic-simulation/economy/BuildingType.hpp"
910
#include "openvic-simulation/economy/production/ProductionType.hpp"
1011
#include "openvic-simulation/history/CountryHistory.hpp"
1112
#include "openvic-simulation/InstanceManager.hpp"
@@ -32,18 +33,18 @@ static constexpr colour_t ERROR_COLOUR = colour_t::from_integer(0xFF0000);
3233
CountryInstance::CountryInstance(
3334
CountryDefinition const* new_country_definition,
3435
index_t new_index,
35-
decltype(building_type_unlock_levels)::keys_type const& building_type_keys,
36-
decltype(technology_unlock_levels)::keys_type const& technology_keys,
37-
decltype(invention_unlock_levels)::keys_type const& invention_keys,
38-
decltype(upper_house)::keys_type const& ideology_keys,
39-
decltype(reforms)::keys_type const& reform_keys,
40-
decltype(government_flag_overrides)::keys_type const& government_type_keys,
41-
decltype(crime_unlock_levels)::keys_type const& crime_keys,
42-
decltype(pop_type_distribution)::keys_type const& pop_type_keys,
43-
decltype(goods_data)::keys_type const& good_instances_keys,
44-
decltype(regiment_type_unlock_levels)::keys_type const& regiment_type_unlock_levels_keys,
45-
decltype(ship_type_unlock_levels)::keys_type const& ship_type_unlock_levels_keys,
46-
decltype(tax_rate_slider_value_by_strata)::keys_type const& strata_keys,
36+
decltype(building_type_unlock_levels)::keys_span_type building_type_keys,
37+
decltype(technology_unlock_levels)::keys_span_type technology_keys,
38+
decltype(invention_unlock_levels)::keys_span_type invention_keys,
39+
decltype(upper_house)::keys_span_type ideology_keys,
40+
decltype(reforms)::keys_span_type reform_keys,
41+
decltype(government_flag_overrides)::keys_span_type government_type_keys,
42+
decltype(crime_unlock_levels)::keys_span_type crime_keys,
43+
decltype(pop_type_distribution)::keys_span_type pop_type_keys,
44+
decltype(goods_data)::keys_span_type good_instances_keys,
45+
decltype(regiment_type_unlock_levels)::keys_span_type regiment_type_unlock_levels_keys,
46+
decltype(ship_type_unlock_levels)::keys_span_type ship_type_unlock_levels_keys,
47+
decltype(tax_rate_slider_value_by_strata)::keys_span_type strata_keys,
4748
GameRulesManager const& new_game_rules_manager,
4849
SharedCountryValues const& new_shared_country_values,
4950
GoodInstanceManager& new_good_instance_manager,
@@ -59,44 +60,43 @@ CountryInstance::CountryInstance(
5960
colour { ERROR_COLOUR },
6061

6162
/* Production */
62-
building_type_unlock_levels { &building_type_keys },
63+
building_type_unlock_levels { building_type_keys },
6364

6465
/* Budget */
6566
taxable_income_mutex { std::make_unique<std::mutex>() },
66-
taxable_income_by_pop_type { &pop_type_keys },
67-
effective_tax_rate_by_strata { &strata_keys },
68-
tax_rate_slider_value_by_strata { &strata_keys },
67+
taxable_income_by_pop_type { pop_type_keys },
68+
effective_tax_rate_by_strata { strata_keys },
69+
tax_rate_slider_value_by_strata { strata_keys },
6970
actual_net_tariffs_mutex { std::make_unique<std::mutex>() },
7071

7172
/* Technology */
72-
technology_unlock_levels { &technology_keys },
73-
invention_unlock_levels { &invention_keys },
73+
technology_unlock_levels { technology_keys },
74+
invention_unlock_levels { invention_keys },
7475

7576
/* Politics */
76-
upper_house { &ideology_keys },
77-
reforms { &reform_keys },
78-
government_flag_overrides { &government_type_keys },
79-
crime_unlock_levels { &crime_keys },
77+
upper_house { ideology_keys },
78+
reforms { reform_keys },
79+
government_flag_overrides { government_type_keys },
80+
crime_unlock_levels { crime_keys },
8081

8182
/* Population */
82-
population_by_strata { &strata_keys },
83-
militancy_by_strata { &strata_keys },
84-
life_needs_fulfilled_by_strata { &strata_keys },
85-
everyday_needs_fulfilled_by_strata { &strata_keys },
86-
luxury_needs_fulfilled_by_strata { &strata_keys },
87-
pop_type_distribution { &pop_type_keys },
88-
pop_type_unemployed_count { &pop_type_keys },
89-
ideology_distribution { &ideology_keys },
90-
vote_distribution { nullptr },
83+
population_by_strata { strata_keys },
84+
militancy_by_strata { strata_keys },
85+
life_needs_fulfilled_by_strata { strata_keys },
86+
everyday_needs_fulfilled_by_strata { strata_keys },
87+
luxury_needs_fulfilled_by_strata { strata_keys },
88+
pop_type_distribution { pop_type_keys },
89+
pop_type_unemployed_count { pop_type_keys },
90+
ideology_distribution { ideology_keys },
9191

9292
/* Trade */
93-
goods_data { &good_instances_keys },
93+
goods_data { good_instances_keys },
9494

9595
/* Diplomacy */
9696

9797
/* Military */
98-
regiment_type_unlock_levels { &regiment_type_unlock_levels_keys },
99-
ship_type_unlock_levels { &ship_type_unlock_levels_keys } {
98+
regiment_type_unlock_levels { regiment_type_unlock_levels_keys },
99+
ship_type_unlock_levels { ship_type_unlock_levels_keys } {
100100

101101
// Exclude PROVINCE (local) modifier effects from the country's modifier sum
102102
modifier_sum.set_this_excluded_targets(ModifierEffect::target_t::PROVINCE);
@@ -137,25 +137,25 @@ CountryInstance::CountryInstance(
137137

138138
update_country_definition_based_attributes();
139139

140-
for (BuildingType const& building_type : *building_type_unlock_levels.get_keys()) {
140+
for (BuildingType const& building_type : building_type_unlock_levels.get_keys()) {
141141
if (building_type.is_default_enabled()) {
142142
unlock_building_type(building_type, new_good_instance_manager);
143143
}
144144
}
145145

146-
for (Crime const& crime : *crime_unlock_levels.get_keys()) {
146+
for (Crime const& crime : crime_unlock_levels.get_keys()) {
147147
if (crime.is_default_active()) {
148148
unlock_crime(crime);
149149
}
150150
}
151151

152-
for (RegimentType const& regiment_type : *regiment_type_unlock_levels.get_keys()) {
152+
for (RegimentType const& regiment_type : regiment_type_unlock_levels.get_keys()) {
153153
if (regiment_type.is_active()) {
154154
unlock_unit_type(regiment_type);
155155
}
156156
}
157157

158-
for (ShipType const& ship_type : *ship_type_unlock_levels.get_keys()) {
158+
for (ShipType const& ship_type : ship_type_unlock_levels.get_keys()) {
159159
if (ship_type.is_active()) {
160160
unlock_unit_type(ship_type);
161161
}
@@ -167,7 +167,7 @@ std::string_view CountryInstance::get_identifier() const {
167167
}
168168

169169
void CountryInstance::update_country_definition_based_attributes() {
170-
vote_distribution.set_keys(&country_definition->get_parties());
170+
vote_distribution.set_keys(country_definition->get_parties());
171171
}
172172

173173
bool CountryInstance::exists() const {
@@ -1464,13 +1464,13 @@ void CountryInstance::update_modifier_sum(Date today, StaticModifierCache const&
14641464
modifier_sum.add_modifier(*tech_school);
14651465
}
14661466

1467-
for (Technology const& technology : *technology_unlock_levels.get_keys()) {
1467+
for (Technology const& technology : technology_unlock_levels.get_keys()) {
14681468
if (is_technology_unlocked(technology)) {
14691469
modifier_sum.add_modifier(technology);
14701470
}
14711471
}
14721472

1473-
for (Invention const& invention : *invention_unlock_levels.get_keys()) {
1473+
for (Invention const& invention : invention_unlock_levels.get_keys()) {
14741474
if (is_invention_unlocked(invention)) {
14751475
modifier_sum.add_modifier(invention);
14761476
}
@@ -2097,10 +2097,10 @@ CountryInstanceManager::CountryInstanceManager(
20972097
ModifierEffectCache const& new_modifier_effect_cache,
20982098
CountryDefines const& new_country_defines,
20992099
PopsDefines const& new_pop_defines,
2100-
std::vector<PopType> const& pop_type_keys
2100+
std::span<const PopType> pop_type_keys
21012101
)
21022102
: country_definition_manager { new_country_definition_manager },
2103-
country_definition_to_instance_map { &new_country_definition_manager.get_country_definitions() },
2103+
country_definition_to_instance_map { new_country_definition_manager.get_country_definitions() },
21042104
shared_country_values {
21052105
new_modifier_effect_cache,
21062106
new_country_defines,
@@ -2121,18 +2121,18 @@ CountryInstance const& CountryInstanceManager::get_country_instance_from_definit
21212121
}
21222122

21232123
bool CountryInstanceManager::generate_country_instances(
2124-
decltype(CountryInstance::building_type_unlock_levels)::keys_type const& building_type_keys,
2125-
decltype(CountryInstance::technology_unlock_levels)::keys_type const& technology_keys,
2126-
decltype(CountryInstance::invention_unlock_levels)::keys_type const& invention_keys,
2127-
decltype(CountryInstance::upper_house)::keys_type const& ideology_keys,
2128-
decltype(CountryInstance::reforms)::keys_type const& reform_keys,
2129-
decltype(CountryInstance::government_flag_overrides)::keys_type const& government_type_keys,
2130-
decltype(CountryInstance::crime_unlock_levels)::keys_type const& crime_keys,
2131-
decltype(CountryInstance::pop_type_distribution)::keys_type const& pop_type_keys,
2132-
decltype(CountryInstance::goods_data)::keys_type const& good_instances_keys,
2133-
decltype(CountryInstance::regiment_type_unlock_levels)::keys_type const& regiment_type_unlock_levels_keys,
2134-
decltype(CountryInstance::ship_type_unlock_levels)::keys_type const& ship_type_unlock_levels_keys,
2135-
decltype(CountryInstance::tax_rate_slider_value_by_strata):: keys_type const& strata_keys,
2124+
decltype(CountryInstance::building_type_unlock_levels)::keys_span_type building_type_keys,
2125+
decltype(CountryInstance::technology_unlock_levels)::keys_span_type technology_keys,
2126+
decltype(CountryInstance::invention_unlock_levels)::keys_span_type invention_keys,
2127+
decltype(CountryInstance::upper_house)::keys_span_type ideology_keys,
2128+
decltype(CountryInstance::reforms)::keys_span_type reform_keys,
2129+
decltype(CountryInstance::government_flag_overrides)::keys_span_type government_type_keys,
2130+
decltype(CountryInstance::crime_unlock_levels)::keys_span_type crime_keys,
2131+
decltype(CountryInstance::pop_type_distribution)::keys_span_type pop_type_keys,
2132+
decltype(CountryInstance::goods_data)::keys_span_type good_instances_keys,
2133+
decltype(CountryInstance::regiment_type_unlock_levels)::keys_span_type regiment_type_unlock_levels_keys,
2134+
decltype(CountryInstance::ship_type_unlock_levels)::keys_span_type ship_type_unlock_levels_keys,
2135+
decltype(CountryInstance::tax_rate_slider_value_by_strata):: keys_span_type strata_keys,
21362136
GameRulesManager const& game_rules_manager,
21372137
GoodInstanceManager& good_instance_manager,
21382138
CountryDefines const& country_defines,

src/openvic-simulation/country/CountryInstance.hpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -340,18 +340,18 @@ namespace OpenVic {
340340
CountryInstance(
341341
CountryDefinition const* new_country_definition,
342342
index_t new_index,
343-
decltype(building_type_unlock_levels)::keys_type const& building_type_keys,
344-
decltype(technology_unlock_levels)::keys_type const& technology_keys,
345-
decltype(invention_unlock_levels)::keys_type const& invention_keys,
346-
decltype(upper_house)::keys_type const& ideology_keys,
347-
decltype(reforms)::keys_type const& reform_keys,
348-
decltype(government_flag_overrides)::keys_type const& government_type_keys,
349-
decltype(crime_unlock_levels)::keys_type const& crime_keys,
350-
decltype(pop_type_distribution)::keys_type const& pop_type_keys,
351-
decltype(goods_data)::keys_type const& good_instances_keys,
352-
decltype(regiment_type_unlock_levels)::keys_type const& regiment_type_unlock_levels_keys,
353-
decltype(ship_type_unlock_levels)::keys_type const& ship_type_unlock_levels_keys,
354-
decltype(tax_rate_slider_value_by_strata)::keys_type const& strata_keys,
343+
decltype(building_type_unlock_levels)::keys_span_type building_type_keys,
344+
decltype(technology_unlock_levels)::keys_span_type technology_keys,
345+
decltype(invention_unlock_levels)::keys_span_type invention_keys,
346+
decltype(upper_house)::keys_span_type ideology_keys,
347+
decltype(reforms)::keys_span_type reform_keys,
348+
decltype(government_flag_overrides)::keys_span_type government_type_keys,
349+
decltype(crime_unlock_levels)::keys_span_type crime_keys,
350+
decltype(pop_type_distribution)::keys_span_type pop_type_keys,
351+
decltype(goods_data)::keys_span_type good_instances_keys,
352+
decltype(regiment_type_unlock_levels)::keys_span_type regiment_type_unlock_levels_keys,
353+
decltype(ship_type_unlock_levels)::keys_span_type ship_type_unlock_levels_keys,
354+
decltype(tax_rate_slider_value_by_strata)::keys_span_type strata_keys,
355355
GameRulesManager const& new_game_rules_manager,
356356
SharedCountryValues const& new_shared_country_values,
357357
GoodInstanceManager& new_good_instance_manager,
@@ -673,7 +673,7 @@ namespace OpenVic {
673673
ModifierEffectCache const& new_modifier_effect_cache,
674674
CountryDefines const& new_country_defines,
675675
PopsDefines const& new_pop_defines,
676-
std::vector<PopType> const& pop_type_keys
676+
std::span<const PopType> pop_type_keys
677677
);
678678

679679
IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS(country_instance);
@@ -682,18 +682,18 @@ namespace OpenVic {
682682
CountryInstance const& get_country_instance_from_definition(CountryDefinition const& country) const;
683683

684684
bool generate_country_instances(
685-
decltype(CountryInstance::building_type_unlock_levels)::keys_type const& building_type_keys,
686-
decltype(CountryInstance::technology_unlock_levels)::keys_type const& technology_keys,
687-
decltype(CountryInstance::invention_unlock_levels)::keys_type const& invention_keys,
688-
decltype(CountryInstance::upper_house)::keys_type const& ideology_keys,
689-
decltype(CountryInstance::reforms)::keys_type const& reform_keys,
690-
decltype(CountryInstance::government_flag_overrides)::keys_type const& government_type_keys,
691-
decltype(CountryInstance::crime_unlock_levels)::keys_type const& crime_keys,
692-
decltype(CountryInstance::pop_type_distribution)::keys_type const& pop_type_keys,
693-
decltype(CountryInstance::goods_data)::keys_type const& good_instances_keys,
694-
decltype(CountryInstance::regiment_type_unlock_levels)::keys_type const& regiment_type_unlock_levels_keys,
695-
decltype(CountryInstance::ship_type_unlock_levels)::keys_type const& ship_type_unlock_levels_keys,
696-
decltype(CountryInstance::tax_rate_slider_value_by_strata):: keys_type const& strata_keys,
685+
decltype(CountryInstance::building_type_unlock_levels)::keys_span_type building_type_keys,
686+
decltype(CountryInstance::technology_unlock_levels)::keys_span_type technology_keys,
687+
decltype(CountryInstance::invention_unlock_levels)::keys_span_type invention_keys,
688+
decltype(CountryInstance::upper_house)::keys_span_type ideology_keys,
689+
decltype(CountryInstance::reforms)::keys_span_type reform_keys,
690+
decltype(CountryInstance::government_flag_overrides)::keys_span_type government_type_keys,
691+
decltype(CountryInstance::crime_unlock_levels)::keys_span_type crime_keys,
692+
decltype(CountryInstance::pop_type_distribution)::keys_span_type pop_type_keys,
693+
decltype(CountryInstance::goods_data)::keys_span_type good_instances_keys,
694+
decltype(CountryInstance::regiment_type_unlock_levels)::keys_span_type regiment_type_unlock_levels_keys,
695+
decltype(CountryInstance::ship_type_unlock_levels)::keys_span_type ship_type_unlock_levels_keys,
696+
decltype(CountryInstance::tax_rate_slider_value_by_strata):: keys_span_type strata_keys,
697697
GameRulesManager const& game_rules_manager,
698698
GoodInstanceManager& good_instance_manager,
699699
CountryDefines const& country_defines,

src/openvic-simulation/country/SharedCountryValues.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ SharedCountryValues::SharedCountryValues(
1212
ModifierEffectCache const& new_modifier_effect_cache,
1313
CountryDefines const& new_country_defines,
1414
PopsDefines const& new_pop_defines,
15-
decltype(shared_pop_type_values)::keys_type const& pop_type_keys
15+
decltype(shared_pop_type_values)::keys_span_type pop_type_keys
1616
) : modifier_effect_cache { new_modifier_effect_cache },
1717
country_defines { new_country_defines },
1818
pop_defines { new_pop_defines },
19-
shared_pop_type_values { &pop_type_keys }
19+
shared_pop_type_values { pop_type_keys }
2020
{}
2121

2222
void SharedCountryValues::update_costs(GoodInstanceManager const& good_instance_manager) {

src/openvic-simulation/country/SharedCountryValues.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace OpenVic {
4242
ModifierEffectCache const& new_modifier_effect_cache,
4343
CountryDefines const& new_country_defines,
4444
PopsDefines const& new_pop_defines,
45-
decltype(shared_pop_type_values)::keys_type const& pop_type_keys
45+
decltype(shared_pop_type_values)::keys_span_type pop_type_keys
4646
);
4747
SharedCountryValues(SharedCountryValues&&) = default;
4848

src/openvic-simulation/dataloader/Dataloader.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static fs::path ensure_forward_slash_path(std::string_view path) {
3535
#endif
3636
}
3737

38-
bool Dataloader::set_roots(path_vector_t const& new_roots, path_vector_t const& new_replace_paths) {
38+
bool Dataloader::set_roots(path_span_t new_roots, path_span_t new_replace_paths) {
3939
if (!roots.empty()) {
4040
Logger::warning("Overriding existing dataloader roots!");
4141
roots.clear();
@@ -46,7 +46,7 @@ bool Dataloader::set_roots(path_vector_t const& new_roots, path_vector_t const&
4646
Logger::info("Adding replace path: ", replace_path);
4747
replace_paths.push_back(replace_path);
4848
}
49-
for (std::reverse_iterator<path_vector_t::const_iterator> it = new_roots.crbegin(); it != new_roots.crend(); ++it) {
49+
for (decltype(new_roots)::reverse_iterator it = new_roots.rbegin(); it != new_roots.rend(); ++it) {
5050
if (std::find(roots.begin(), roots.end(), *it) == roots.end()) {
5151
if (fs::is_directory(*it)) {
5252
Logger::info("Adding dataloader root: ", *it);
@@ -130,7 +130,7 @@ fs::path Dataloader::lookup_image_file(std::string_view path) const {
130130
return lookup_file(path);
131131
}
132132

133-
bool Dataloader::should_ignore_path(fs::path const& path, path_vector_t const& replace_paths) const {
133+
bool Dataloader::should_ignore_path(fs::path const& path, path_span_t replace_paths) const {
134134
bool ignore = false;
135135
for (fs::path const& replace_path : replace_paths) {
136136
if (path.string().starts_with(replace_path.string())) {
@@ -210,7 +210,7 @@ Dataloader::path_vector_t Dataloader::lookup_basic_identifier_prefixed_files_in_
210210
return _lookup_files_in_dir<fs::recursive_directory_iterator>(path, extension, _extract_basic_identifier_prefix_from_path);
211211
}
212212

213-
bool Dataloader::apply_to_files(path_vector_t const& files, apply_files_callback_t callback) const {
213+
bool Dataloader::apply_to_files(path_span_t files, apply_files_callback_t callback) const {
214214
bool ret = true;
215215
for (fs::path const& file : files) {
216216
if (!callback(file)) {

0 commit comments

Comments
 (0)