diff options
author | hop311 <hop3114@gmail.com> | 2024-09-11 01:21:03 +0200 |
---|---|---|
committer | hop311 <hop3114@gmail.com> | 2024-09-12 23:08:34 +0200 |
commit | 237e42fd1cdff02862c6a2279c7cad9786ab0e65 (patch) | |
tree | e822fe7d6c31e0fec639290d7faaa739ce7638b9 /src/openvic-simulation/dataloader | |
parent | 7a9206e3869fbb659d296b854c90f5c81755a5ca (diff) |
CountryInstance unlock tech, invention, crime, building, unit, gas etc.
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.hpp | 18 |
1 files changed, 17 insertions, 1 deletions
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<T, T>(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<typename T> + Callback<T> auto assign_variable_callback_opt( + std::optional<T>& 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<std::string_view> assign_variable_callback_string(std::string& var); template<typename T> @@ -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; |