aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/map/Region.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-08-12 18:54:55 +0200
committer GitHub <noreply@github.com>2023-08-12 18:54:55 +0200
commitd3c6ff1809b88b4c99163402f30b6d10c787510f (patch)
treee4bf26ecfef160e7df7670e73af7f154f1550308 /src/openvic/map/Region.cpp
parent538e7dc4ec44c4d09a6a654f10229e6392653a50 (diff)
parentafc16e76ba699b24ba1ef1cb1b658ef421c84430 (diff)
Merge pull request #11 from OpenVicProject/string_view
Changed IdentifierRegistry to use std::string_view when looking up a std::string key
Diffstat (limited to 'src/openvic/map/Region.cpp')
-rw-r--r--src/openvic/map/Region.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/openvic/map/Region.cpp b/src/openvic/map/Region.cpp
index b83f556..fc207e3 100644
--- a/src/openvic/map/Region.cpp
+++ b/src/openvic/map/Region.cpp
@@ -4,6 +4,41 @@
using namespace OpenVic;
+return_t ProvinceSet::add_province(Province* province) {
+ if (locked) {
+ Logger::error("Cannot add province to province set - locked!");
+ return FAILURE;
+ }
+ if (province == nullptr) {
+ Logger::error("Cannot add province to province set - null province!");
+ return FAILURE;
+ }
+ if (contains_province(province)) {
+ Logger::error("Cannot add province ", province->get_identifier(), " to province set - already in the set!");
+ return FAILURE;
+ }
+ provinces.push_back(province);
+ return SUCCESS;
+}
+
+void ProvinceSet::lock(bool log) {
+ if (locked) {
+ Logger::error("Failed to lock province set - already locked!");
+ } else {
+ locked = true;
+ if (log) Logger::info("Locked province set with ", get_province_count(), " provinces");
+ }
+}
+
+bool ProvinceSet::is_locked() const {
+ return locked;
+}
+
+void ProvinceSet::reset() {
+ provinces.clear();
+ locked = false;
+}
+
size_t ProvinceSet::get_province_count() const {
return provinces.size();
}
@@ -16,7 +51,7 @@ std::vector<Province*> const& ProvinceSet::get_provinces() const {
return provinces;
}
-Region::Region(std::string const& new_identifier) : HasIdentifier { new_identifier } {}
+Region::Region(const std::string_view new_identifier) : HasIdentifier { new_identifier } {}
colour_t Region::get_colour() const {
if (provinces.empty()) return FULL_COLOUR << 16;