aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index c41c09e..b99fc48 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -443,9 +443,17 @@ namespace OpenVic {
};
}
+ /* By default this will only allow an optional to be set once. Set allow_overwrite
+ * to true to allow multiple assignments, with the last taking precedence. */
template<typename T>
- Callback<T const&> auto assign_variable_callback_pointer(std::optional<T const*>& var) {
- return [&var](T const& val) -> bool {
+ Callback<T const&> auto assign_variable_callback_pointer_opt(
+ std::optional<T const*>& var, bool allow_overwrite = false
+ ) {
+ return [&var, allow_overwrite](T const& val) -> bool {
+ if (!allow_overwrite && var.has_value()) {
+ Logger::error("Canoot assign pointer value to already-initialised optional!");
+ return false;
+ }
var = &val;
return true;
};