aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/types
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-09-07 00:54:09 +0200
committer Hop311 <hop3114@gmail.com>2023-09-07 20:37:24 +0200
commit3cd1d62ec00690a1b29070dd4903754e8f089a21 (patch)
tree61d630aa130f8411cc0d539dbfb3705154740631 /src/openvic/types
parent8e12540771f1fcc670481aa6299fd73cb10aad00 (diff)
NodeTools cleanup+province definition csv loading
Diffstat (limited to 'src/openvic/types')
-rw-r--r--src/openvic/types/Colour.hpp9
-rw-r--r--src/openvic/types/IdentifierRegistry.cpp10
-rw-r--r--src/openvic/types/IdentifierRegistry.hpp5
3 files changed, 12 insertions, 12 deletions
diff --git a/src/openvic/types/Colour.hpp b/src/openvic/types/Colour.hpp
index fdac40e..01f3852 100644
--- a/src/openvic/types/Colour.hpp
+++ b/src/openvic/types/Colour.hpp
@@ -2,6 +2,9 @@
#include <algorithm>
#include <cstdint>
+#include <iomanip>
+#include <sstream>
+#include <string>
namespace OpenVic {
// Represents a 24-bit RGB integer OR a 32-bit ARGB integer
@@ -24,4 +27,10 @@ namespace OpenVic {
constexpr float colour_byte_to_float(colour_t colour) {
return std::clamp(static_cast<float>(colour) / 255.0f, 0.0f, 1.0f);
}
+
+ inline std::string colour_to_hex_string(colour_t colour) {
+ std::ostringstream stream;
+ stream << std::hex << std::setfill('0') << std::setw(6) << colour;
+ return stream.str();
+ }
}
diff --git a/src/openvic/types/IdentifierRegistry.cpp b/src/openvic/types/IdentifierRegistry.cpp
index 3710387..6d5221b 100644
--- a/src/openvic/types/IdentifierRegistry.cpp
+++ b/src/openvic/types/IdentifierRegistry.cpp
@@ -1,8 +1,6 @@
#include "IdentifierRegistry.hpp"
#include <cassert>
-#include <iomanip>
-#include <sstream>
using namespace OpenVic;
@@ -21,14 +19,8 @@ HasColour::HasColour(colour_t const new_colour, bool can_be_null) : colour(new_c
colour_t HasColour::get_colour() const { return colour; }
-std::string HasColour::colour_to_hex_string(colour_t const colour) {
- std::ostringstream stream;
- stream << std::hex << std::setfill('0') << std::setw(6) << colour;
- return stream.str();
-}
-
std::string HasColour::colour_to_hex_string() const {
- return colour_to_hex_string(colour);
+ return OpenVic::colour_to_hex_string(colour);
}
HasIdentifierAndColour::HasIdentifierAndColour(const std::string_view new_identifier,
diff --git a/src/openvic/types/IdentifierRegistry.hpp b/src/openvic/types/IdentifierRegistry.hpp
index 989db01..54b466e 100644
--- a/src/openvic/types/IdentifierRegistry.hpp
+++ b/src/openvic/types/IdentifierRegistry.hpp
@@ -1,7 +1,6 @@
#pragma once
#include <map>
-#include <unordered_map>
#include <vector>
#include "openvic/types/Colour.hpp"
@@ -46,7 +45,6 @@ namespace OpenVic {
colour_t get_colour() const;
std::string colour_to_hex_string() const;
- static std::string colour_to_hex_string(colour_t const colour);
};
/*
@@ -74,7 +72,8 @@ namespace OpenVic {
* the type of object that the registry will store, and the second part ensures
* that HasIdentifier is a base class of T.
*/
- template<class T, typename std::enable_if<std::is_base_of<HasIdentifier, T>::value>::type* = nullptr>
+ template<typename T>
+ requires(std::derived_from<T, HasIdentifier>)
class IdentifierRegistry {
using identifier_index_map_t = std::map<std::string, size_t, std::less<void>>;