aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/types
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/types')
-rw-r--r--src/openvic-simulation/types/Date.cpp2
-rw-r--r--src/openvic-simulation/types/Date.hpp2
-rw-r--r--src/openvic-simulation/types/IdentifierRegistry.cpp4
-rw-r--r--src/openvic-simulation/types/IdentifierRegistry.hpp24
-rw-r--r--src/openvic-simulation/types/fixed_point/FixedPoint.hpp2
5 files changed, 22 insertions, 12 deletions
diff --git a/src/openvic-simulation/types/Date.cpp b/src/openvic-simulation/types/Date.cpp
index 203d647..27d554c 100644
--- a/src/openvic-simulation/types/Date.cpp
+++ b/src/openvic-simulation/types/Date.cpp
@@ -257,6 +257,6 @@ Date Date::from_string(char const* str, size_t length, bool* successful) {
return from_string(str, str + length, successful);
}
-Date Date::from_string(const std::string_view str, bool* successful) {
+Date Date::from_string(std::string_view str, bool* successful) {
return from_string(str.data(), str.length(), successful);
}
diff --git a/src/openvic-simulation/types/Date.hpp b/src/openvic-simulation/types/Date.hpp
index 601f9dc..b2df666 100644
--- a/src/openvic-simulation/types/Date.hpp
+++ b/src/openvic-simulation/types/Date.hpp
@@ -90,7 +90,7 @@ namespace OpenVic {
// Parsed from string of the form YYYY.MM.DD
static Date from_string(char const* str, char const* end, bool* successful = nullptr);
static Date from_string(char const* str, size_t length, bool* successful = nullptr);
- static Date from_string(const std::string_view str, bool* successful = nullptr);
+ static Date from_string(std::string_view str, bool* successful = nullptr);
};
std::ostream& operator<<(std::ostream& out, Date const& date);
}
diff --git a/src/openvic-simulation/types/IdentifierRegistry.cpp b/src/openvic-simulation/types/IdentifierRegistry.cpp
index f284164..d6afd3a 100644
--- a/src/openvic-simulation/types/IdentifierRegistry.cpp
+++ b/src/openvic-simulation/types/IdentifierRegistry.cpp
@@ -4,7 +4,7 @@
using namespace OpenVic;
-HasIdentifier::HasIdentifier(const std::string_view new_identifier)
+HasIdentifier::HasIdentifier(std::string_view new_identifier)
: identifier { new_identifier } {
assert(!identifier.empty());
}
@@ -31,7 +31,7 @@ std::string HasColour::colour_to_hex_string() const {
return OpenVic::colour_to_hex_string(colour);
}
-HasIdentifierAndColour::HasIdentifierAndColour(const std::string_view new_identifier,
+HasIdentifierAndColour::HasIdentifierAndColour(std::string_view new_identifier,
const colour_t new_colour, bool can_be_null, bool can_have_alpha)
: HasIdentifier { new_identifier },
HasColour { new_colour, can_be_null, can_have_alpha } {}
diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp
index 41e4c6b..7fe2656 100644
--- a/src/openvic-simulation/types/IdentifierRegistry.hpp
+++ b/src/openvic-simulation/types/IdentifierRegistry.hpp
@@ -16,7 +16,7 @@ namespace OpenVic {
const std::string identifier;
protected:
- HasIdentifier(const std::string_view new_identifier);
+ HasIdentifier(std::string_view new_identifier);
public:
HasIdentifier(HasIdentifier const&) = delete;
@@ -55,7 +55,7 @@ namespace OpenVic {
*/
class HasIdentifierAndColour : public HasIdentifier, public HasColour {
protected:
- HasIdentifierAndColour(const std::string_view new_identifier, const colour_t new_colour, bool can_be_null, bool can_have_alpha);
+ HasIdentifierAndColour(std::string_view new_identifier, const colour_t new_colour, bool can_be_null, bool can_have_alpha);
public:
HasIdentifierAndColour(HasIdentifierAndColour const&) = delete;
@@ -86,7 +86,7 @@ namespace OpenVic {
identifier_index_map_t identifier_index_map;
public:
- IdentifierRegistry(const std::string_view new_name, bool new_log_lock = true)
+ IdentifierRegistry(std::string_view new_name, bool new_log_lock = true)
: name { new_name }, log_lock { new_log_lock } {}
std::string const& get_name() const {
@@ -143,18 +143,22 @@ namespace OpenVic {
}
}
- T* get_item_by_identifier(const std::string_view identifier) {
+ T* get_item_by_identifier(std::string_view identifier) {
const identifier_index_map_t::const_iterator it = identifier_index_map.find(identifier);
if (it != identifier_index_map.end()) return &items[it->second];
return nullptr;
}
- T const* get_item_by_identifier(const std::string_view identifier) const {
+ T const* get_item_by_identifier(std::string_view identifier) const {
const identifier_index_map_t::const_iterator it = identifier_index_map.find(identifier);
if (it != identifier_index_map.end()) return &items[it->second];
return nullptr;
}
+ bool has_identifier(std::string_view identifier) const {
+ return get_item_by_identifier(identifier) != nullptr;
+ }
+
T* get_item_by_index(size_t index) {
return index < items.size() ? &items[index] : nullptr;
}
@@ -163,6 +167,10 @@ namespace OpenVic {
return index < items.size() ? &items[index] : nullptr;
}
+ bool has_index(size_t index) const {
+ return get_item_by_index(index) != nullptr;
+ }
+
std::vector<T>& get_items() {
return items;
}
@@ -242,8 +250,10 @@ namespace OpenVic {
#define IDENTIFIER_REGISTRY_ACCESSORS_CUSTOM_PLURAL(type, singular, plural) \
void lock_##plural() { plural.lock(); } \
bool plural##_are_locked() const { return plural.is_locked(); } \
- type const* get_##singular##_by_identifier(const std::string_view identifier) const { \
+ type const* get_##singular##_by_identifier(std::string_view identifier) const { \
return plural.get_item_by_identifier(identifier); } \
+ bool has_##singular##_identifier(std::string_view identifier) const { \
+ return plural.has_identifier(identifier); } \
size_t get_##singular##_count() const { \
return plural.size(); } \
std::vector<type> const& get_##plural() const { \
@@ -258,7 +268,7 @@ namespace OpenVic {
return plural.expect_item_decimal_map(callback); }
#define IDENTIFIER_REGISTRY_NON_CONST_ACCESSORS_CUSTOM_PLURAL(type, singular, plural) \
- type* get_##singular##_by_identifier(const std::string_view identifier) { \
+ type* get_##singular##_by_identifier(std::string_view identifier) { \
return plural.get_item_by_identifier(identifier); } \
NodeTools::node_callback_t expect_##singular##_identifier(NodeTools::callback_t<type&> callback) { \
return plural.expect_item_identifier(callback); } \
diff --git a/src/openvic-simulation/types/fixed_point/FixedPoint.hpp b/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
index 22fdeca..459d9c4 100644
--- a/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
+++ b/src/openvic-simulation/types/fixed_point/FixedPoint.hpp
@@ -329,7 +329,7 @@ namespace OpenVic {
return parse(str, str + length, successful);
}
- static fixed_point_t parse(const std::string_view str, bool* successful = nullptr) {
+ static fixed_point_t parse(std::string_view str, bool* successful = nullptr) {
return parse(str.data(), str.length(), successful);
}