aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader/NodeTools.hpp
diff options
context:
space:
mode:
author CptAlanSmith <123112708+CptAlanSmith@users.noreply.github.com>2023-09-23 20:25:15 +0200
committer GitHub <noreply@github.com>2023-09-23 20:25:15 +0200
commit005a8026bb424779a146e00cc48621ff1d72b807 (patch)
treedde15211e31d861b61711bf6aebdeb8713393d53 /src/openvic-simulation/dataloader/NodeTools.hpp
parentebea2e473eefa3945508b0bf622a472b62d70d3b (diff)
Testing (#23)
* Fixes for building scons * Initial proof of concept auto-testing Shows how we can pull loaded data and display it back * Re-did headless Because hubert insisted it be done like this ;) * Auto-Testing Framework Basics * Requirements Calculations * Fix for messy merge (teach me to use merge tools) * Fixing up misc merge issues to fully reconcile with master changes * Re-added missing getters * Move of testing files due to folder reorgs * Use new accessors + int reading fix --------- Co-authored-by: Hop311 <hop3114@gmail.com>
Diffstat (limited to 'src/openvic-simulation/dataloader/NodeTools.hpp')
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 5c22e11..e49cab6 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -138,6 +138,14 @@ namespace OpenVic {
}
template<typename T>
+ callback_t<T&&> move_variable_callback(T& var) {
+ return [&var](T&& val) -> bool {
+ var = std::move(val);
+ return true;
+ };
+ }
+
+ template<typename T>
requires requires(T& t) {
t += T {};
}
@@ -159,31 +167,33 @@ namespace OpenVic {
};
}
- template<typename I, typename T>
- requires(std::integral<I>, std::integral<T>)
- callback_t<I> _assign_variable_callback_int(const std::string_view name, T& var) {
- return [&var, name](I val) -> bool {
- if (std::numeric_limits<T>::lowest() <= val && val <= std::numeric_limits<T>::max()) {
+ template<typename T>
+ requires(std::integral<T>)
+ callback_t<uint64_t> assign_variable_callback_uint(const std::string_view name, T& var) {
+ return [&var, name](uint64_t val) -> bool {
+ if (val <= static_cast<uint64_t>(std::numeric_limits<T>::max())) {
var = val;
return true;
}
- Logger::error("Invalid ", name, ": ", val, " (valid range: [",
- static_cast<int64_t>(std::numeric_limits<T>::lowest()), ", ",
+ Logger::error("Invalid ", name, ": ", val, " (valid range: [0, ",
static_cast<uint64_t>(std::numeric_limits<T>::max()), "])");
return false;
};
}
template<typename T>
- requires(std::integral<T>)
- callback_t<uint64_t> assign_variable_callback_uint(const std::string_view name, T& var) {
- return _assign_variable_callback_int<uint64_t>(name, var);
- }
-
- template<typename T>
- requires(std::integral<T>)
+ requires(std::signed_integral<T>)
callback_t<int64_t> assign_variable_callback_int(const std::string_view name, T& var) {
- return _assign_variable_callback_int<int64_t>(name, var);
+ return [&var, name](int64_t val) -> bool {
+ if (static_cast<int64_t>(std::numeric_limits<T>::lowest()) <= val && val <= static_cast<int64_t>(std::numeric_limits<T>::max())) {
+ var = val;
+ return true;
+ }
+ Logger::error("Invalid ", name, ": ", val, " (valid range: [",
+ static_cast<int64_t>(std::numeric_limits<T>::lowest()), ", ",
+ static_cast<int64_t>(std::numeric_limits<T>::max()), "])");
+ return false;
+ };
}
template<typename T>