From e33a330129364b4bd632b2fd531a996b8c57cefb Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 17 Jan 2024 22:24:39 +0000 Subject: Parse missing variables, Logger counting, misc cleanup --- src/openvic-simulation/dataloader/NodeTools.hpp | 43 ++++++++++++++++--------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'src/openvic-simulation/dataloader/NodeTools.hpp') diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index b3fce16..4b33c6d 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -356,33 +356,46 @@ namespace OpenVic { }; } + template + bool warn_or_error(bool warn, Args... args) { + if (warn) { + Logger::warning(args...); + return true; + } else { + Logger::error(args...); + return false; + } + } + template - Callback auto set_callback(tsl::ordered_set& set) { - return [&set](T val) -> bool { - if (!set.emplace(std::move(val)).second) { - Logger::warning("Duplicate set entry: \"", val, "\""); + Callback auto set_callback(tsl::ordered_set& set, bool warn = false) { + return [&set, warn](T val) -> bool { + if (set.emplace(std::move(val)).second) { + return true; } - return true; + return warn_or_error(warn, "Duplicate set entry: \"", val, "\""); }; } template T, typename...SetArgs> - Callback auto set_callback_pointer(tsl::ordered_set& set) { - return [&set](T const& val) -> bool { - if (!set.emplace(&val).second) { - Logger::warning("Duplicate set entry: \"", &val, "\""); + Callback auto set_callback_pointer(tsl::ordered_set& set, bool warn = false) { + return [&set, warn](T const& val) -> bool { + if (set.emplace(&val).second) { + return true; } - return true; + return warn_or_error(warn, "Duplicate set entry: \"", &val, "\""); }; } template Key, typename Value, typename... MapArgs> - Callback auto map_callback(tsl::ordered_map& map, Key const* key) { - return [&map, key](Value value) -> bool { - if (!map.emplace(key, std::move(value)).second) { - Logger::warning("Duplicate map entry with key: \"", key, "\""); + Callback auto map_callback( + tsl::ordered_map& map, Key const* key, bool warn = false + ) { + return [&map, key, warn](Value value) -> bool { + if (map.emplace(key, std::move(value)).second) { + return true; } - return true; + return warn_or_error(warn, "Duplicate map entry with key: \"", key, "\""); }; } } -- cgit v1.2.3-56-ga3b1