aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/utility
diff options
context:
space:
mode:
author George L. Albany <Megacake1234@gmail.com>2023-12-24 23:00:36 +0100
committer GitHub <noreply@github.com>2023-12-24 23:00:36 +0100
commitbf4e7368600bb425b6612231fbb84de34ec99a27 (patch)
treed3b29714d3286b9edbe380f877bbce541344a635 /src/openvic-simulation/utility
parentf036506b88af02508242f279ca29b743ef713976 (diff)
parent3770de7a03879a8ff6b8cf22b402217c19fa2b53 (diff)
Merge pull request #100 from OpenVicProject/change/colour_t_to_struct
Diffstat (limited to 'src/openvic-simulation/utility')
-rw-r--r--src/openvic-simulation/utility/BMP.cpp4
-rw-r--r--src/openvic-simulation/utility/Getters.hpp5
-rw-r--r--src/openvic-simulation/utility/Utility.hpp14
3 files changed, 20 insertions, 3 deletions
diff --git a/src/openvic-simulation/utility/BMP.cpp b/src/openvic-simulation/utility/BMP.cpp
index d4e7cf7..83d26c4 100644
--- a/src/openvic-simulation/utility/BMP.cpp
+++ b/src/openvic-simulation/utility/BMP.cpp
@@ -102,7 +102,7 @@ bool BMP::read_header() {
if (header.num_colours != 0 && header.bits_per_pixel > PALETTE_BITS_PER_PIXEL_LIMIT) {
Logger::error(
"Invalid BMP palette size: ", header.num_colours, " (should be 0 as bits per pixel is ", header.bits_per_pixel,
- " > 8)"
+ " > ", PALETTE_BITS_PER_PIXEL_LIMIT, ")"
);
header_validated = false;
}
@@ -207,7 +207,7 @@ bool BMP::read_pixel_data() {
Logger::error("Failed to move to the pixel data in the BMP file!");
return false;
}
- const size_t pixel_data_size = get_width() * get_height() * header.bits_per_pixel / 8;
+ const size_t pixel_data_size = get_width() * get_height() * header.bits_per_pixel / CHAR_BIT;
pixel_data.resize(pixel_data_size);
file.read(reinterpret_cast<char*>(pixel_data.data()), pixel_data_size);
if (file.fail()) {
diff --git a/src/openvic-simulation/utility/Getters.hpp b/src/openvic-simulation/utility/Getters.hpp
index a722071..1fb82b1 100644
--- a/src/openvic-simulation/utility/Getters.hpp
+++ b/src/openvic-simulation/utility/Getters.hpp
@@ -49,7 +49,10 @@ public: \
ACCESS:
namespace OpenVic {
- struct ReturnByValueProperty {};
+ struct ReturnByValueProperty {
+ constexpr bool operator==(ReturnByValueProperty const&) const = default;
+ constexpr std::strong_ordering operator<=>(ReturnByValueProperty const&) const = default;
+ };
/*
* Template function used to choose the return type and provide the implementation
diff --git a/src/openvic-simulation/utility/Utility.hpp b/src/openvic-simulation/utility/Utility.hpp
new file mode 100644
index 0000000..e8d7205
--- /dev/null
+++ b/src/openvic-simulation/utility/Utility.hpp
@@ -0,0 +1,14 @@
+#pragma once
+
+namespace OpenVic::utility {
+ [[noreturn]] inline void unreachable() {
+ // Uses compiler specific extensions if possible.
+ // Even if no extension is used, undefined behavior is still raised by
+ // an empty function body and the noreturn attribute.
+#ifdef __GNUC__ // GCC, Clang, ICC
+ __builtin_unreachable();
+#elif defined(_MSC_VER) // MSVC
+ __assume(false);
+#endif
+ }
+}