Skip to content

Commit 54c0336

Browse files
authored
Merge pull request #513 from OpenVicProject/construct_via_emplace
Construct via emplace
2 parents 6f89e7a + d9f2216 commit 54c0336

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+425
-432
lines changed

src/openvic-simulation/country/CountryDefinition.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ bool CountryDefinitionManager::add_country(
7676

7777
static constexpr colour_t default_colour = colour_t::fill_as(colour_t::max_value);
7878

79-
return country_definitions.add_item({
79+
return country_definitions.emplace_item(
80+
identifier,
8081
identifier, colour, get_country_definition_count(), *graphical_culture, std::move(parties), std::move(unit_names),
8182
dynamic_tag, std::move(alternative_colours),
8283
/* Default to country colour for the chest and grey for the others. Update later if necessary. */
8384
colour, default_colour, default_colour
84-
});
85+
);
8586
}
8687

8788
bool CountryDefinitionManager::load_countries(
@@ -199,8 +200,10 @@ node_callback_t CountryDefinitionManager::load_country_party(
199200
Logger::warning("Country party ", party_name, " has no ideology, defaulting to nullptr / no ideology");
200201
}
201202

202-
ret &= country_parties.add_item(
203-
{ party_name, start_date, end_date, ideology, std::move(policies) }, duplicate_warning_callback
203+
ret &= country_parties.emplace_item(
204+
party_name,
205+
duplicate_warning_callback,
206+
party_name, start_date, end_date, ideology, std::move(policies)
204207
);
205208

206209
return ret;

src/openvic-simulation/country/CountryDefinition.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ namespace OpenVic {
2222
struct CountryDefinitionManager;
2323

2424
struct CountryParty : HasIdentifierAndColour {
25-
friend struct CountryDefinitionManager;
26-
2725
using policy_map_t = IndexedMap<IssueGroup, Issue const*>;
2826

2927
private:
@@ -32,19 +30,18 @@ namespace OpenVic {
3230
Ideology const* PROPERTY(ideology); // Can be nullptr, shows up as "No Ideology" in game
3331
policy_map_t PROPERTY(policies);
3432

33+
public:
3534
CountryParty(
3635
std::string_view new_identifier, Date new_start_date, Date new_end_date, Ideology const* new_ideology,
3736
policy_map_t&& new_policies
3837
);
39-
40-
public:
4138
CountryParty(CountryParty&&) = default;
4239
};
4340

4441
/* Generic information about a TAG */
4542
struct CountryDefinition : HasIdentifierAndColour, HasIndex<CountryDefinition> {
4643
friend struct CountryDefinitionManager;
47-
44+
4845
using unit_names_map_t = ordered_map<UnitType const*, name_list_t>;
4946
using government_colour_map_t = ordered_map<GovernmentType const*, colour_t>;
5047

@@ -61,14 +58,14 @@ namespace OpenVic {
6158
colour_t PROPERTY(tertiary_unit_colour);
6259
// Unit colours not const due to being added after construction
6360

61+
62+
public:
6463
CountryDefinition(
6564
std::string_view new_identifier, colour_t new_colour, index_t new_index,
6665
GraphicalCultureType const& new_graphical_culture, IdentifierRegistry<CountryParty>&& new_parties,
6766
unit_names_map_t&& new_unit_names, bool new_dynamic_tag, government_colour_map_t&& new_alternative_colours,
6867
colour_t new_primary_unit_colour, colour_t new_secondary_unit_colour, colour_t new_tertiary_unit_colour
6968
);
70-
71-
public:
7269
CountryDefinition(CountryDefinition&&) = default;
7370

7471
// TODO - get_colour including alternative colours

src/openvic-simulation/country/CountryInstance.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,7 +2323,8 @@ bool CountryInstanceManager::generate_country_instances(
23232323
bool ret = true;
23242324

23252325
for (CountryDefinition const& country_definition : country_definition_manager.get_country_definitions()) {
2326-
if (country_instances.add_item({
2326+
if (country_instances.emplace_item(
2327+
country_definition.get_identifier(),
23272328
&country_definition,
23282329
get_country_instance_count(),
23292330
building_type_keys,
@@ -2344,7 +2345,7 @@ bool CountryInstanceManager::generate_country_instances(
23442345
good_instance_manager,
23452346
country_defines,
23462347
economy_defines
2347-
})) {
2348+
)) {
23482349
// We need to update the country's ModifierSum's source here as the country's address is finally stable
23492350
// after changing between its constructor call and now due to being std::move'd into the registry.
23502351
CountryInstance& country_instance = get_back_country_instance();

src/openvic-simulation/country/CountryInstance.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ namespace OpenVic {
345345
unlock_level_t PROPERTY(gas_defence_unlock_level, 0);
346346
memory::vector<unlock_level_t> PROPERTY(unit_variant_unlock_levels);
347347

348+
public:
348349
CountryInstance(
349350
CountryDefinition const* new_country_definition,
350351
index_t new_index,
@@ -368,7 +369,6 @@ namespace OpenVic {
368369
EconomyDefines const& new_economy_defines
369370
);
370371

371-
public:
372372
UNIT_BRANCHED_GETTER(get_unit_instance_groups, armies, navies);
373373
UNIT_BRANCHED_GETTER(get_unit_type_unlock_levels, regiment_type_unlock_levels, ship_type_unlock_levels);
374374
UNIT_BRANCHED_GETTER(get_leaders, generals, admirals);

src/openvic-simulation/dataloader/ModManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ bool ModManager::load_mod_file(ast::NodeCPtr root) {
3838
}
3939

4040
if (ret) {
41-
ret &= mods.add_item(
42-
{ identifier, path, user_dir, std::move(replace_paths), std::move(dependencies) }
41+
ret &= mods.emplace_item(
42+
identifier, identifier, path, user_dir, std::move(replace_paths), std::move(dependencies)
4343
);
4444
}
4545

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

33
#include <string_view>
4-
#include <vector>
54

65
#include "openvic-simulation/types/HasIdentifier.hpp"
76
#include "openvic-simulation/types/IdentifierRegistry.hpp"
87
#include "openvic-simulation/dataloader/NodeTools.hpp"
98

109
namespace OpenVic {
11-
1210
struct Mod : HasIdentifier {
13-
friend struct ModManager;
14-
1511
private:
1612
const memory::string PROPERTY(dataloader_root_path);
1713
const std::optional<memory::string> PROPERTY(user_dir);
1814
const memory::vector<memory::string> PROPERTY(replace_paths);
1915
const memory::vector<memory::string> PROPERTY(dependencies);
2016

21-
Mod(std::string_view new_identifier, std::string_view new_path, std::optional<std::string_view> new_user_dir, memory::vector<memory::string> new_replace_paths, memory::vector<memory::string> new_dependencies);
22-
2317
public:
18+
Mod(std::string_view new_identifier, std::string_view new_path, std::optional<std::string_view> new_user_dir, memory::vector<memory::string> new_replace_paths, memory::vector<memory::string> new_dependencies);
2419
Mod(Mod&&) = default;
2520
};
2621

@@ -34,4 +29,4 @@ namespace OpenVic {
3429

3530
bool load_mod_file(ast::NodeCPtr root);
3631
};
37-
} // namespace OpenVic
32+
}

src/openvic-simulation/diplomacy/DiplomaticAction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bool DiplomaticActionManager::add_diplomatic_action(
2626
Logger::error("Invalid diplomatic action identifier - empty!");
2727
return false;
2828
}
29-
return diplomatic_action_types.add_item({ identifier, DiplomaticActionType { std::move(initializer) } });
29+
return diplomatic_action_types.emplace_item( identifier, identifier, DiplomaticActionType { std::move(initializer) } );
3030
}
3131

3232
bool DiplomaticActionManager::add_cancelable_diplomatic_action(
@@ -36,7 +36,7 @@ bool DiplomaticActionManager::add_cancelable_diplomatic_action(
3636
Logger::error("Invalid cancelable diplomatic action identifier - empty!");
3737
return false;
3838
}
39-
return diplomatic_action_types.add_item({ identifier, CancelableDiplomaticActionType { std::move(initializer) } });
39+
return diplomatic_action_types.emplace_item( identifier, identifier, CancelableDiplomaticActionType { std::move(initializer) } );
4040
}
4141

4242
DiplomaticActionTickCache DiplomaticActionManager::create_diplomatic_action_tick(

src/openvic-simulation/economy/BuildingInstance.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
55

66
namespace OpenVic {
7-
87
struct BuildingInstance : HasIdentifier { // used in the actual game
98
using level_t = BuildingType::level_t;
109

src/openvic-simulation/economy/BuildingType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool BuildingTypeManager::add_building_type(
4444
return false;
4545
}
4646

47-
const bool ret = building_types.add_item({ identifier, building_type_args });
47+
const bool ret = building_types.emplace_item( identifier, identifier, building_type_args );
4848

4949
if (ret) {
5050
building_type_types.emplace(building_type_args.type);

src/openvic-simulation/economy/BuildingType.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@
99
#include "openvic-simulation/utility/Containers.hpp"
1010

1111
namespace OpenVic {
12-
13-
struct BuildingTypeManager;
14-
1512
/* REQUIREMENTS:
1613
* MAP-11, MAP-72, MAP-73
1714
* MAP-12, MAP-75, MAP-76
1815
* MAP-13, MAP-78, MAP-79
1916
*/
2017
struct BuildingType : Modifier {
21-
friend struct BuildingTypeManager;
22-
2318
using level_t = int16_t;
2419
using naval_capacity_t = uint64_t;
2520

@@ -73,9 +68,8 @@ namespace OpenVic {
7368
bool PROPERTY(capital); // only in naval base
7469
bool PROPERTY_CUSTOM_PREFIX(port, is); // only in naval base
7570

76-
BuildingType(std::string_view identifier, building_type_args_t& building_type_args);
77-
7871
public:
72+
BuildingType(std::string_view identifier, building_type_args_t& building_type_args);
7973
BuildingType(BuildingType&&) = default;
8074
};
8175

0 commit comments

Comments
 (0)