aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/pop
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-08-12 15:10:40 +0200
committer Hop311 <hop3114@gmail.com>2023-08-12 15:10:40 +0200
commitafc16e76ba699b24ba1ef1cb1b658ef421c84430 (patch)
treee4bf26ecfef160e7df7670e73af7f154f1550308 /src/openvic/pop
parent538e7dc4ec44c4d09a6a654f10229e6392653a50 (diff)
std::string const& --> const std::string_view
Diffstat (limited to 'src/openvic/pop')
-rw-r--r--src/openvic/pop/Culture.cpp26
-rw-r--r--src/openvic/pop/Culture.hpp18
-rw-r--r--src/openvic/pop/Pop.cpp41
-rw-r--r--src/openvic/pop/Pop.hpp6
-rw-r--r--src/openvic/pop/Religion.cpp20
-rw-r--r--src/openvic/pop/Religion.hpp12
6 files changed, 66 insertions, 57 deletions
diff --git a/src/openvic/pop/Culture.cpp b/src/openvic/pop/Culture.cpp
index b683804..f50bb23 100644
--- a/src/openvic/pop/Culture.cpp
+++ b/src/openvic/pop/Culture.cpp
@@ -4,9 +4,9 @@
using namespace OpenVic;
-GraphicalCultureType::GraphicalCultureType(std::string const& new_identifier) : HasIdentifier { new_identifier } {}
+GraphicalCultureType::GraphicalCultureType(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
-CultureGroup::CultureGroup(std::string const& new_identifier,
+CultureGroup::CultureGroup(const std::string_view new_identifier,
GraphicalCultureType const& new_unit_graphical_culture_type)
: HasIdentifier { new_identifier },
unit_graphical_culture_type { new_unit_graphical_culture_type } {}
@@ -15,10 +15,10 @@ GraphicalCultureType const& CultureGroup::get_unit_graphical_culture_type() cons
return unit_graphical_culture_type;
}
-Culture::Culture(CultureGroup const& new_group, std::string const& new_identifier,
- colour_t new_colour, name_list_t const& new_first_names, name_list_t const& new_last_names)
- : group { new_group },
- HasIdentifierAndColour { new_identifier, new_colour, true },
+Culture::Culture(const std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group,
+ name_list_t const& new_first_names, name_list_t const& new_last_names)
+ : HasIdentifierAndColour { new_identifier, new_colour, true },
+ group { new_group },
first_names { new_first_names },
last_names { new_last_names } {
}
@@ -32,7 +32,7 @@ CultureManager::CultureManager()
culture_groups { "culture groups" },
cultures { "cultures" } {}
-return_t CultureManager::add_graphical_culture_type(std::string const& identifier) {
+return_t CultureManager::add_graphical_culture_type(const std::string_view identifier) {
if (identifier.empty()) {
Logger::error("Invalid culture group identifier - empty!");
return FAILURE;
@@ -44,11 +44,11 @@ void CultureManager::lock_graphical_culture_types() {
graphical_culture_types.lock();
}
-GraphicalCultureType const* CultureManager::get_graphical_culture_type_by_identifier(std::string const& identifier) const {
+GraphicalCultureType const* CultureManager::get_graphical_culture_type_by_identifier(const std::string_view identifier) const {
return graphical_culture_types.get_item_by_identifier(identifier);
}
-return_t CultureManager::add_culture_group(std::string const& identifier, GraphicalCultureType const* graphical_culture_type) {
+return_t CultureManager::add_culture_group(const std::string_view identifier, GraphicalCultureType const* graphical_culture_type) {
if (!graphical_culture_types.is_locked()) {
Logger::error("Cannot register culture groups until graphical culture types are locked!");
return FAILURE;
@@ -68,11 +68,11 @@ void CultureManager::lock_culture_groups() {
culture_groups.lock();
}
-CultureGroup const* CultureManager::get_culture_group_by_identifier(std::string const& identifier) const {
+CultureGroup const* CultureManager::get_culture_group_by_identifier(const std::string_view identifier) const {
return culture_groups.get_item_by_identifier(identifier);
}
-return_t CultureManager::add_culture(std::string const& identifier, colour_t colour, CultureGroup const* group, Culture::name_list_t const& first_names, Culture::name_list_t const& last_names) {
+return_t CultureManager::add_culture(const std::string_view identifier, colour_t colour, CultureGroup const* group, Culture::name_list_t const& first_names, Culture::name_list_t const& last_names) {
if (!culture_groups.is_locked()) {
Logger::error("Cannot register cultures until culture groups are locked!");
return FAILURE;
@@ -90,13 +90,13 @@ return_t CultureManager::add_culture(std::string const& identifier, colour_t col
return FAILURE;
}
// TODO - name list sanatisation?
- return cultures.add_item({ *group, identifier, colour, first_names, last_names });
+ return cultures.add_item({ identifier, colour, *group, first_names, last_names });
}
void CultureManager::lock_cultures() {
cultures.lock();
}
-Culture const* CultureManager::get_culture_by_identifier(std::string const& identifier) const {
+Culture const* CultureManager::get_culture_by_identifier(const std::string_view identifier) const {
return cultures.get_item_by_identifier(identifier);
}
diff --git a/src/openvic/pop/Culture.hpp b/src/openvic/pop/Culture.hpp
index 657a531..645e226 100644
--- a/src/openvic/pop/Culture.hpp
+++ b/src/openvic/pop/Culture.hpp
@@ -10,7 +10,7 @@ namespace OpenVic {
friend struct CultureManager;
private:
- GraphicalCultureType(std::string const& new_identifier);
+ GraphicalCultureType(const std::string_view new_identifier);
public:
GraphicalCultureType(GraphicalCultureType&&) = default;
@@ -24,7 +24,7 @@ namespace OpenVic {
// TODO - leader type, union tag
- CultureGroup(std::string const& new_identifier, GraphicalCultureType const& new_unit_graphical_culture_type);
+ CultureGroup(const std::string_view new_identifier, GraphicalCultureType const& new_unit_graphical_culture_type);
public:
CultureGroup(CultureGroup&&) = default;
@@ -43,7 +43,7 @@ namespace OpenVic {
// TODO - radicalism, primary tag
- Culture(CultureGroup const& new_group, std::string const& new_identifier, colour_t new_colour, name_list_t const& new_first_names, name_list_t const& new_last_names);
+ Culture(const std::string_view new_identifier, colour_t new_colour, CultureGroup const& new_group, name_list_t const& new_first_names, name_list_t const& new_last_names);
public:
Culture(Culture&&) = default;
@@ -60,14 +60,14 @@ namespace OpenVic {
public:
CultureManager();
- return_t add_graphical_culture_type(std::string const& identifier);
+ return_t add_graphical_culture_type(const std::string_view identifier);
void lock_graphical_culture_types();
- GraphicalCultureType const* get_graphical_culture_type_by_identifier(std::string const& identifier) const;
- return_t add_culture_group(std::string const& identifier, GraphicalCultureType const* new_graphical_culture_type);
+ GraphicalCultureType const* get_graphical_culture_type_by_identifier(const std::string_view identifier) const;
+ return_t add_culture_group(const std::string_view identifier, GraphicalCultureType const* new_graphical_culture_type);
void lock_culture_groups();
- CultureGroup const* get_culture_group_by_identifier(std::string const& identifier) const;
- return_t add_culture(std::string const& identifier, colour_t colour, CultureGroup const* group, Culture::name_list_t const& first_names, Culture::name_list_t const& last_names);
+ CultureGroup const* get_culture_group_by_identifier(const std::string_view identifier) const;
+ return_t add_culture(const std::string_view identifier, colour_t colour, CultureGroup const* group, Culture::name_list_t const& first_names, Culture::name_list_t const& last_names);
void lock_cultures();
- Culture const* get_culture_by_identifier(std::string const& identifier) const;
+ Culture const* get_culture_by_identifier(const std::string_view identifier) const;
};
}
diff --git a/src/openvic/pop/Pop.cpp b/src/openvic/pop/Pop.cpp
index 913d31f..c4b11b8 100644
--- a/src/openvic/pop/Pop.cpp
+++ b/src/openvic/pop/Pop.cpp
@@ -31,7 +31,7 @@ Pop::pop_size_t Pop::get_size() const {
return size;
}
-PopType::PopType(std::string const& new_identifier, colour_t new_colour,
+PopType::PopType(const std::string_view new_identifier, colour_t new_colour,
strata_t new_strata, sprite_t new_sprite,
Pop::pop_size_t new_max_size, Pop::pop_size_t new_merge_max_size,
bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan, bool new_is_slave)
@@ -77,30 +77,39 @@ bool PopType::get_is_slave() const {
return is_slave;
}
+static const std::string test_graphical_culture_type = "test_graphical_culture_type";
+static const std::string test_culture_group = "test_culture_group";
+static const std::string test_culture = "test_culture";
+static const std::string test_religion_group = "test_religion_group";
+static const std::string test_religion = "test_religion";
+static const std::string test_pop_type_poor = "test_pop_type_poor";
+static const std::string test_pop_type_middle = "test_pop_type_middle";
+static const std::string test_pop_type_rich = "test_pop_type_rich";
+
PopManager::PopManager() : pop_types { "pop types" } {
- culture_manager.add_graphical_culture_type("test_graphical_culture_type");
+ culture_manager.add_graphical_culture_type(test_graphical_culture_type);
culture_manager.lock_graphical_culture_types();
- culture_manager.add_culture_group("test_culture_group", culture_manager.get_graphical_culture_type_by_identifier("test_graphical_culture_type"));
+ culture_manager.add_culture_group(test_culture_group, culture_manager.get_graphical_culture_type_by_identifier(test_graphical_culture_type));
culture_manager.lock_culture_groups();
- culture_manager.add_culture("test_culture", 0x0000FF, culture_manager.get_culture_group_by_identifier("test_culture_group"),
+ culture_manager.add_culture(test_culture, 0x0000FF, culture_manager.get_culture_group_by_identifier(test_culture_group),
{ "john" }, { "smith" });
culture_manager.lock_cultures();
- religion_manager.add_religion_group("test_religion_group");
+ religion_manager.add_religion_group(test_religion_group);
religion_manager.lock_religion_groups();
- religion_manager.add_religion("test_religion", 0xFF0000, religion_manager.get_religion_group_by_identifier("test_religion_group"), 1, false);
+ religion_manager.add_religion(test_religion, 0xFF0000, religion_manager.get_religion_group_by_identifier(test_religion_group), 1, false);
religion_manager.lock_religions();
- add_pop_type("test_pop_type_poor", 0xFF0000, PopType::strata_t::POOR, 1, 1, 1, false, false, false, false);
- add_pop_type("test_pop_type_middle", 0x00FF00, PopType::strata_t::MIDDLE, 1, 1, 1, false, false, false, false);
- add_pop_type("test_pop_type_rich", 0x0000FF, PopType::strata_t::RICH, 1, 1, 1, false, false, false, false);
+ add_pop_type(test_pop_type_poor, 0xFF0000, PopType::strata_t::POOR, 1, 1, 1, false, false, false, false);
+ add_pop_type(test_pop_type_middle, 0x00FF00, PopType::strata_t::MIDDLE, 1, 1, 1, false, false, false, false);
+ add_pop_type(test_pop_type_rich, 0x0000FF, PopType::strata_t::RICH, 1, 1, 1, false, false, false, false);
lock_pop_types();
}
-return_t PopManager::add_pop_type(std::string const& identifier, colour_t colour, PopType::strata_t strata, PopType::sprite_t sprite,
+return_t PopManager::add_pop_type(const std::string_view identifier, colour_t colour, PopType::strata_t strata, PopType::sprite_t sprite,
Pop::pop_size_t max_size, Pop::pop_size_t merge_max_size, bool state_capital_only, bool demote_migrant, bool is_artisan, bool is_slave) {
if (identifier.empty()) {
Logger::error("Invalid pop type identifier - empty!");
@@ -129,17 +138,17 @@ void PopManager::lock_pop_types() {
pop_types.lock();
}
-PopType const* PopManager::get_pop_type_by_identifier(std::string const& identifier) const {
+PopType const* PopManager::get_pop_type_by_identifier(const std::string_view identifier) const {
return pop_types.get_item_by_identifier(identifier);
}
void PopManager::generate_test_pops(Province& province) const {
if (pop_types.is_locked()) {
- static PopType const& type_poor = *get_pop_type_by_identifier("test_pop_type_poor");
- static PopType const& type_middle = *get_pop_type_by_identifier("test_pop_type_middle");
- static PopType const& type_rich = *get_pop_type_by_identifier("test_pop_type_rich");
- static Culture const& culture = *culture_manager.get_culture_by_identifier("test_culture");
- static Religion const& religion = *religion_manager.get_religion_by_identifier("test_religion");
+ static PopType const& type_poor = *get_pop_type_by_identifier(test_pop_type_poor);
+ static PopType const& type_middle = *get_pop_type_by_identifier(test_pop_type_middle);
+ static PopType const& type_rich = *get_pop_type_by_identifier(test_pop_type_rich);
+ static Culture const& culture = *culture_manager.get_culture_by_identifier(test_culture);
+ static Religion const& religion = *religion_manager.get_religion_by_identifier(test_religion);
province.add_pop({ type_poor, culture, religion, static_cast<Pop::pop_size_t>(province.get_index() * province.get_index()) * 100 });
province.add_pop({ type_middle, culture, religion, static_cast<Pop::pop_size_t>(province.get_index() * province.get_index()) * 50 });
province.add_pop({ type_rich, culture, religion, static_cast<Pop::pop_size_t>(province.get_index()) * 1000 });
diff --git a/src/openvic/pop/Pop.hpp b/src/openvic/pop/Pop.hpp
index 628194d..5bd1b90 100644
--- a/src/openvic/pop/Pop.hpp
+++ b/src/openvic/pop/Pop.hpp
@@ -57,7 +57,7 @@ namespace OpenVic {
// TODO - rebel composition, life/everyday/luxury needs, country and province migration targets, promote_to targets, ideologies and issues
- PopType(std::string const& new_identifier, colour_t new_colour, strata_t new_strata, sprite_t new_sprite, Pop::pop_size_t new_max_size, Pop::pop_size_t new_merge_max_size,
+ PopType(const std::string_view new_identifier, colour_t new_colour, strata_t new_strata, sprite_t new_sprite, Pop::pop_size_t new_max_size, Pop::pop_size_t new_merge_max_size,
bool new_state_capital_only, bool new_demote_migrant, bool new_is_artisan, bool new_is_slave);
public:
@@ -83,11 +83,11 @@ namespace OpenVic {
public:
PopManager();
- return_t add_pop_type(std::string const& identifier, colour_t new_colour, PopType::strata_t strata, PopType::sprite_t sprite,
+ return_t add_pop_type(const std::string_view identifier, colour_t new_colour, PopType::strata_t strata, PopType::sprite_t sprite,
Pop::pop_size_t max_size, Pop::pop_size_t merge_max_size, bool state_capital_only, bool demote_migrant,
bool is_artisan, bool is_slave);
void lock_pop_types();
- PopType const* get_pop_type_by_identifier(std::string const& identifier) const;
+ PopType const* get_pop_type_by_identifier(const std::string_view identifier) const;
void generate_test_pops(Province& province) const;
};
diff --git a/src/openvic/pop/Religion.cpp b/src/openvic/pop/Religion.cpp
index f3d3341..0cfc7a6 100644
--- a/src/openvic/pop/Religion.cpp
+++ b/src/openvic/pop/Religion.cpp
@@ -4,12 +4,12 @@
using namespace OpenVic;
-ReligionGroup::ReligionGroup(std::string const& new_identifier) : HasIdentifier { new_identifier } {}
+ReligionGroup::ReligionGroup(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
-Religion::Religion(ReligionGroup const& new_group, std::string const& new_identifier,
- colour_t new_colour, icon_t new_icon, bool new_pagan)
- : group { new_group },
- HasIdentifierAndColour { new_identifier, new_colour, true },
+Religion::Religion(const std::string_view new_identifier, colour_t new_colour,
+ ReligionGroup const& new_group, icon_t new_icon, bool new_pagan)
+ : HasIdentifierAndColour { new_identifier, new_colour, true },
+ group { new_group },
icon { new_icon },
pagan { new_pagan } {
assert(icon > 0);
@@ -31,7 +31,7 @@ ReligionManager::ReligionManager()
: religion_groups { "religion groups" },
religions { "religions" } {}
-return_t ReligionManager::add_religion_group(std::string const& identifier) {
+return_t ReligionManager::add_religion_group(const std::string_view identifier) {
if (identifier.empty()) {
Logger::error("Invalid religion group identifier - empty!");
return FAILURE;
@@ -43,11 +43,11 @@ void ReligionManager::lock_religion_groups() {
religion_groups.lock();
}
-ReligionGroup const* ReligionManager::get_religion_group_by_identifier(std::string const& identifier) const {
+ReligionGroup const* ReligionManager::get_religion_group_by_identifier(const std::string_view identifier) const {
return religion_groups.get_item_by_identifier(identifier);
}
-return_t ReligionManager::add_religion(std::string const& identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan) {
+return_t ReligionManager::add_religion(const std::string_view identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan) {
if (!religion_groups.is_locked()) {
Logger::error("Cannot register religions until religion groups are locked!");
return FAILURE;
@@ -68,13 +68,13 @@ return_t ReligionManager::add_religion(std::string const& identifier, colour_t c
Logger::error("Invalid religion icon for ", identifier, ": ", icon);
return FAILURE;
}
- return religions.add_item({ *group, identifier, colour, icon, pagan });
+ return religions.add_item({ identifier, colour, *group, icon, pagan });
}
void ReligionManager::lock_religions() {
religions.lock();
}
-Religion const* ReligionManager::get_religion_by_identifier(std::string const& identifier) const {
+Religion const* ReligionManager::get_religion_by_identifier(const std::string_view identifier) const {
return religions.get_item_by_identifier(identifier);
}
diff --git a/src/openvic/pop/Religion.hpp b/src/openvic/pop/Religion.hpp
index e781cf9..4eb3e4c 100644
--- a/src/openvic/pop/Religion.hpp
+++ b/src/openvic/pop/Religion.hpp
@@ -10,7 +10,7 @@ namespace OpenVic {
friend struct ReligionManager;
private:
- ReligionGroup(std::string const& new_identifier);
+ ReligionGroup(const std::string_view new_identifier);
public:
ReligionGroup(ReligionGroup&&) = default;
@@ -26,7 +26,7 @@ namespace OpenVic {
const icon_t icon;
const bool pagan;
- Religion(ReligionGroup const& new_group, std::string const& new_identifier, colour_t new_colour, icon_t new_icon, bool new_pagan);
+ Religion(const std::string_view new_identifier, colour_t new_colour, ReligionGroup const& new_group, icon_t new_icon, bool new_pagan);
public:
Religion(Religion&&) = default;
@@ -44,11 +44,11 @@ namespace OpenVic {
public:
ReligionManager();
- return_t add_religion_group(std::string const& identifier);
+ return_t add_religion_group(const std::string_view identifier);
void lock_religion_groups();
- ReligionGroup const* get_religion_group_by_identifier(std::string const& identifier) const;
- return_t add_religion(std::string const& identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan);
+ ReligionGroup const* get_religion_group_by_identifier(const std::string_view identifier) const;
+ return_t add_religion(const std::string_view identifier, colour_t colour, ReligionGroup const* group, Religion::icon_t icon, bool pagan);
void lock_religions();
- Religion const* get_religion_by_identifier(std::string const& identifier) const;
+ Religion const* get_religion_by_identifier(const std::string_view identifier) const;
};
}