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/HasIdentifier.hpp17
-rw-r--r--src/openvic-simulation/types/IdentifierRegistry.hpp6
-rw-r--r--src/openvic-simulation/types/IndexedMap.hpp6
3 files changed, 22 insertions, 7 deletions
diff --git a/src/openvic-simulation/types/HasIdentifier.hpp b/src/openvic-simulation/types/HasIdentifier.hpp
index 925d58b..74961e3 100644
--- a/src/openvic-simulation/types/HasIdentifier.hpp
+++ b/src/openvic-simulation/types/HasIdentifier.hpp
@@ -2,6 +2,8 @@
#include <algorithm>
#include <cassert>
+#include <string>
+#include <string_view>
#include <ostream>
#include "openvic-simulation/types/Colour.hpp"
@@ -49,6 +51,11 @@ namespace OpenVic {
return obj != nullptr ? stream << *obj : stream << "<NULL>";
}
+ template<typename T>
+ concept HasGetIdentifier = requires(T const& t) {
+ { t.get_identifier() } -> std::same_as<std::string_view>;
+ };
+
/*
* Base class for objects with associated colour information.
*/
@@ -71,6 +78,11 @@ namespace OpenVic {
using HasColour = _HasColour<colour_t>;
using HasAlphaColour = _HasColour<colour_argb_t>;
+ template<typename T>
+ concept HasGetColour = requires(T const& t) {
+ { t.get_colour() } -> IsColour;
+ };
+
/*
* Base class for objects with a unique string identifier and associated colour information.
*/
@@ -107,4 +119,9 @@ namespace OpenVic {
HasIndex& operator=(HasIndex const&) = delete;
HasIndex& operator=(HasIndex&&) = delete;
};
+
+ template<typename T>
+ concept HasGetIndex = requires(T const& t) {
+ { t.get_index() } -> std::unsigned_integral;
+ };
}
diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp
index a73ebcc..03cdbb1 100644
--- a/src/openvic-simulation/types/IdentifierRegistry.hpp
+++ b/src/openvic-simulation/types/IdentifierRegistry.hpp
@@ -4,6 +4,7 @@
#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp"
+#include "openvic-simulation/types/HasIdentifier.hpp"
#include "openvic-simulation/utility/Getters.hpp"
#include "openvic-simulation/utility/Logger.hpp"
@@ -27,11 +28,6 @@ namespace OpenVic {
return true;
}
- template<typename T>
- concept HasGetIdentifier = requires(T const& t) {
- { t.get_identifier() } -> std::same_as<std::string_view>;
- };
-
/* Registry Value Info - the type that is being registered, and a unique identifier string getter. */
template<typename ValueInfo>
concept RegistryValueInfo = requires(
diff --git a/src/openvic-simulation/types/IndexedMap.hpp b/src/openvic-simulation/types/IndexedMap.hpp
index 68effb9..30cf5cd 100644
--- a/src/openvic-simulation/types/IndexedMap.hpp
+++ b/src/openvic-simulation/types/IndexedMap.hpp
@@ -14,6 +14,8 @@ namespace OpenVic {
using container_t = std::vector<Value>;
using key_t = Key;
using value_t = Value;
+ using value_ref_t = container_t::reference;
+ using value_const_ref_t = container_t::const_reference;
using keys_t = std::vector<key_t>;
using container_t::operator[];
@@ -91,11 +93,11 @@ namespace OpenVic {
}
}
- constexpr value_t& operator[](key_t const& key) {
+ constexpr value_ref_t operator[](key_t const& key) {
return container_t::operator[](get_index_from_item(key));
}
- constexpr value_t const& operator[](key_t const& key) const {
+ constexpr value_const_ref_t operator[](key_t const& key) const {
return container_t::operator[](get_index_from_item(key));
}