aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader/NodeTools.hpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-01-18 23:52:14 +0100
committer GitHub <noreply@github.com>2024-01-18 23:52:14 +0100
commitc1bac9acee88a7ce1123aed3a748712fb2441762 (patch)
tree346cd26d4a74c92cb78c674242703283895aa5f4 /src/openvic-simulation/dataloader/NodeTools.hpp
parent75878b11821d8fd78ebdd7b0a11a82970a531616 (diff)
parente33a330129364b4bd632b2fd531a996b8c57cefb (diff)
Merge pull request #131 from OpenVicProject/misc-changes
Parse missing variables, Logger counting, misc cleanup
Diffstat (limited to 'src/openvic-simulation/dataloader/NodeTools.hpp')
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp43
1 files changed, 28 insertions, 15 deletions
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<typename... Args>
+ bool warn_or_error(bool warn, Args... args) {
+ if (warn) {
+ Logger::warning(args...);
+ return true;
+ } else {
+ Logger::error(args...);
+ return false;
+ }
+ }
+
template<typename T, typename U, typename...SetArgs>
- Callback<T> auto set_callback(tsl::ordered_set<U, SetArgs...>& set) {
- return [&set](T val) -> bool {
- if (!set.emplace(std::move(val)).second) {
- Logger::warning("Duplicate set entry: \"", val, "\"");
+ Callback<T> auto set_callback(tsl::ordered_set<U, SetArgs...>& 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<std::derived_from<HasIdentifier> T, typename...SetArgs>
- Callback<T const&> auto set_callback_pointer(tsl::ordered_set<T const*, SetArgs...>& set) {
- return [&set](T const& val) -> bool {
- if (!set.emplace(&val).second) {
- Logger::warning("Duplicate set entry: \"", &val, "\"");
+ Callback<T const&> auto set_callback_pointer(tsl::ordered_set<T const*, SetArgs...>& 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<std::derived_from<HasIdentifier> Key, typename Value, typename... MapArgs>
- Callback<Value> auto map_callback(tsl::ordered_map<Key const*, Value, MapArgs...>& 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<Value> auto map_callback(
+ tsl::ordered_map<Key const*, Value, MapArgs...>& 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, "\"");
};
}
}