From 237e42fd1cdff02862c6a2279c7cad9786ab0e65 Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 11 Sep 2024 00:21:03 +0100 Subject: CountryInstance unlock tech, invention, crime, building, unit, gas etc. --- src/openvic-simulation/dataloader/NodeTools.hpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/openvic-simulation/dataloader') diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index 79fb0ea..51e3e82 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -443,6 +443,22 @@ namespace OpenVic { return assign_variable_callback_cast(var); } + /* 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 + Callback auto assign_variable_callback_opt( + std::optional& var, bool allow_overwrite = false + ) { + return [&var, allow_overwrite](T const& val) -> bool { + if (!allow_overwrite && var.has_value()) { + Logger::error("Cannot assign value to already-initialised optional!"); + return false; + } + var = val; + return true; + }; + } + callback_t assign_variable_callback_string(std::string& var); template @@ -487,7 +503,7 @@ namespace OpenVic { ) { return [&var, allow_overwrite](T const& val) -> bool { if (!allow_overwrite && var.has_value()) { - Logger::error("Canoot assign pointer value to already-initialised optional!"); + Logger::error("Cannot assign pointer value to already-initialised optional!"); return false; } var = &val; -- cgit v1.2.3-56-ga3b1