aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-01-03 15:30:23 +0100
committer hop311 <hop3114@gmail.com>2024-01-03 15:43:35 +0100
commitf0dd758b6c7f35ffb1f6b237805bcb8d39c20cc5 (patch)
tree21e54285c4f3927ecd3b1b621587d75b875ac3d3 /src/openvic-simulation/dataloader
parent461ec160448373f8d9492b9c586ff53a35edef18 (diff)
Added case insensitive ordered set and map and IdentifierRegistry
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp15
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp4
-rw-r--r--src/openvic-simulation/dataloader/Vic2PathSearch.cpp11
3 files changed, 8 insertions, 22 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 64d89e8..223b795 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -8,8 +8,8 @@
#include <lexy-vdf/Parser.hpp>
#include "openvic-simulation/GameManager.hpp"
-#include "openvic-simulation/utility/ConstexprIntToStr.hpp"
#include "openvic-simulation/utility/Logger.hpp"
+#include "openvic-simulation/utility/StringUtils.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -34,13 +34,6 @@ static fs::path ensure_forward_slash_path(std::string_view path) {
#endif
}
-static constexpr bool path_equals_case_insensitive(std::string_view lhs, std::string_view rhs) {
- constexpr auto ichar_equals = [](unsigned char l, unsigned char r) {
- return std::tolower(l) == std::tolower(r);
- };
- return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), ichar_equals);
-}
-
bool Dataloader::set_roots(path_vector_t const& new_roots) {
if (!roots.empty()) {
Logger::error("Overriding existing dataloader roots!");
@@ -91,7 +84,7 @@ fs::path Dataloader::lookup_file(std::string_view path, bool print_error) const
for (fs::directory_entry const& entry : fs::directory_iterator { composed.parent_path(), ec }) {
if (entry.is_regular_file()) {
const fs::path file = entry;
- if (path_equals_case_insensitive(file.filename().string(), filename)) {
+ if (StringUtils::strings_equal_case_insensitive(file.filename().string(), filename)) {
return file;
}
}
@@ -599,9 +592,9 @@ bool Dataloader::_load_events(GameManager& game_manager) {
static constexpr std::string_view events_directory = "events";
const bool ret = apply_to_files(
lookup_files_in_dir(events_directory, ".txt"),
- [&game_manager](fs::path const& file) -> bool {
+ [this, &game_manager](fs::path const& file) -> bool {
return game_manager.get_event_manager().load_event_file(
- game_manager.get_politics_manager().get_issue_manager(), parse_defines(file).get_file_node()
+ game_manager.get_politics_manager().get_issue_manager(), parse_defines_cached(file).get_file_node()
);
}
);
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index f5f960f..8ad731b 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -19,8 +19,8 @@ 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 = ordered_map<std::string, T>;
+ template<typename T, class Hash = container_hash<std::string>, class KeyEqual = std::equal_to<>>
+ using string_map_t = ordered_map<std::string, T, Hash, KeyEqual>;
/* String set type supporting heterogeneous key lookup */
using string_set_t = ordered_set<std::string>;
diff --git a/src/openvic-simulation/dataloader/Vic2PathSearch.cpp b/src/openvic-simulation/dataloader/Vic2PathSearch.cpp
index d3468e4..26facbe 100644
--- a/src/openvic-simulation/dataloader/Vic2PathSearch.cpp
+++ b/src/openvic-simulation/dataloader/Vic2PathSearch.cpp
@@ -6,6 +6,7 @@
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/utility/ConstexprIntToStr.hpp"
#include "openvic-simulation/utility/Logger.hpp"
+#include "openvic-simulation/utility/StringUtils.hpp"
#include "Dataloader.hpp"
@@ -20,7 +21,6 @@
#endif
using namespace OpenVic;
-using namespace OpenVic::NodeTools;
using namespace ovdl;
#if defined(_WIN32) || (defined(__APPLE__) && defined(__MACH__))
@@ -31,17 +31,10 @@ using namespace ovdl;
#define FILESYSTEM_NEEDS_FORWARD_SLASHES
#endif
-static constexpr bool path_equals_case_insensitive(std::string_view lhs, std::string_view rhs) {
- constexpr auto ichar_equals = [](unsigned char l, unsigned char r) {
- return std::tolower(l) == std::tolower(r);
- };
- return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), ichar_equals);
-}
-
// Windows and Mac by default act like case insensitive filesystems
static constexpr bool path_equals(std::string_view lhs, std::string_view rhs) {
#if defined(FILESYSTEM_CASE_INSENSITIVE)
- return path_equals_case_insensitive(lhs, rhs);
+ return StringUtils::strings_equal_case_insensitive(lhs, rhs);
#else
return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
#endif