aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp17
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp15
-rw-r--r--src/openvic-simulation/dataloader/Vic2PathSearch.cpp3
3 files changed, 19 insertions, 16 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);
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index c3eaf65..f3224aa 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -10,8 +10,11 @@
#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
+#include <tsl/ordered_set.h>
+
#include "openvic-simulation/types/Colour.hpp"
#include "openvic-simulation/types/Date.hpp"
+#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/types/Vector.hpp"
namespace OpenVic {
@@ -20,10 +23,10 @@ namespace OpenVic {
/* Template for map from strings to Ts, in which string_views can be
* searched for without needing to be copied into a string */
template<typename T>
- using string_map_t = std::map<std::string, T, std::less<void>>;
+ using string_map_t = ordered_map<std::string, T>;
/* String set type supporting heterogeneous key lookup */
- using string_set_t = std::set<std::string, std::less<void>>;
+ using string_set_t = ordered_set<std::string>;
namespace NodeTools {
@@ -137,7 +140,7 @@ namespace OpenVic {
node_callback_t expect_dictionary(key_value_callback_t callback);
struct dictionary_entry_t {
- const enum class expected_count_t : uint8_t {
+ enum class expected_count_t : uint8_t {
_MUST_APPEAR = 0b01,
_CAN_REPEAT = 0b10,
@@ -146,7 +149,7 @@ namespace OpenVic {
ZERO_OR_MORE = _CAN_REPEAT,
ONE_OR_MORE = _MUST_APPEAR | _CAN_REPEAT
} expected_count;
- const node_callback_t callback;
+ node_callback_t callback;
size_t count;
dictionary_entry_t(expected_count_t new_expected_count, node_callback_t new_callback)
@@ -344,8 +347,8 @@ namespace OpenVic {
};
}
- template<typename T>
- Callback<T const&> auto set_callback_pointer(std::set<T const*>& set) {
+ template<typename T, typename...SetArgs>
+ Callback<T const&> auto set_callback_pointer(tsl::ordered_set<T const*, SetArgs...>& set) {
return [&set](T const& val) -> bool {
set.insert(&val);
return true;
diff --git a/src/openvic-simulation/dataloader/Vic2PathSearch.cpp b/src/openvic-simulation/dataloader/Vic2PathSearch.cpp
index 10bd08d..d3468e4 100644
--- a/src/openvic-simulation/dataloader/Vic2PathSearch.cpp
+++ b/src/openvic-simulation/dataloader/Vic2PathSearch.cpp
@@ -3,6 +3,7 @@
#include <lexy-vdf/KeyValues.hpp>
#include <lexy-vdf/Parser.hpp>
+#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/utility/ConstexprIntToStr.hpp"
#include "openvic-simulation/utility/Logger.hpp"
@@ -331,7 +332,7 @@ fs::path Dataloader::search_for_game_path(fs::path hint_path) {
};
using hint_path_t = fs::path;
using game_path_t = fs::path;
- static std::unordered_map<hint_path_t, game_path_t, fshash> _cached_paths;
+ static ordered_map<hint_path_t, game_path_t, fshash> _cached_paths;
auto it = _cached_paths.find(hint_path);
if (it != _cached_paths.end()) {