aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader/NodeTools.cpp
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-12-25 08:42:11 +0100
committer Spartan322 <Megacake1234@gmail.com>2023-12-31 20:46:26 +0100
commite1496a87178d925277aceed0ebcbab06920e15ee (patch)
treeba081f9f4d74865ab5851a2efd560745900ca81a /src/openvic-simulation/dataloader/NodeTools.cpp
parent0a425fbe05d6138b753c0e4a7c06f06695bde8af (diff)
Add `https://github.com/Tessil/ordered-map`
Add is_specialization_of to Utility.hpp Add OpenVic::ordered_map and OpenVic::ordered_set Change `std::map` to `ordered_map` Change `std::set to use `ordered_set` Add `set_callback_pointer(tsl::ordered_set<T const*>& set)` Add mutable_iterator to enable mutable value iterator for `tsl::ordered_map` Add std::hash<OpenVic::Date> implementation Enable deps/SCsub to expose dependency includes neccessary for inclusion
Diffstat (limited to 'src/openvic-simulation/dataloader/NodeTools.cpp')
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp
index e68a185..1dbc99c 100644
--- a/src/openvic-simulation/dataloader/NodeTools.cpp
+++ b/src/openvic-simulation/dataloader/NodeTools.cpp
@@ -1,6 +1,7 @@
#include "NodeTools.hpp"
#include "openvic-simulation/types/Colour.hpp"
+#include "openvic-simulation/utility/TslHelper.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -314,22 +315,20 @@ bool NodeTools::add_key_map_entry(
}
bool NodeTools::remove_key_map_entry(key_map_t& key_map, std::string_view key) {
- const key_map_t::const_iterator it = key_map.find(key);
- if (it != key_map.end()) {
- key_map.erase(it);
- return true;
+ if(key_map.erase(key) == 0) {
+ Logger::error("Failed to find dictionary key to remove: ", key);
+ return false;
}
- Logger::error("Failed to find dictionary key to remove: ", key);
- return false;
+ return true;
}
key_value_callback_t NodeTools::dictionary_keys_callback(key_map_t& key_map, key_value_callback_t default_callback) {
return [&key_map, default_callback](std::string_view key, ast::NodeCPtr value) -> bool {
- const key_map_t::iterator it = key_map.find(key);
+ key_map_t::iterator it = key_map.find(key);
if (it == key_map.end()) {
return default_callback(key, value);
}
- dictionary_entry_t& entry = it->second;
+ dictionary_entry_t& entry = it.value();
if (++entry.count > 1 && !entry.can_repeat()) {
Logger::error("Invalid repeat of dictionary key: ", key);
return false;
@@ -345,7 +344,7 @@ key_value_callback_t NodeTools::dictionary_keys_callback(key_map_t& key_map, key
bool NodeTools::check_key_map_counts(key_map_t& key_map) {
bool ret = true;
- for (key_map_t::value_type& key_entry : key_map) {
+ for (auto key_entry : mutable_iterator(key_map)) {
dictionary_entry_t& entry = key_entry.second;
if (entry.must_appear() && entry.count < 1) {
Logger::error("Mandatory dictionary key not present: ", key_entry.first);