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/Dataloader.cpp56
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.hpp7
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp2
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp8
4 files changed, 34 insertions, 39 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 25641e2..82957fc 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -1,12 +1,12 @@
#include "Dataloader.hpp"
-#include "openvic-simulation/GameManager.hpp"
-#include "openvic-simulation/utility/Logger.hpp"
-
#include <openvic-dataloader/csv/Parser.hpp>
#include <openvic-dataloader/detail/CallbackOStream.hpp>
#include <openvic-dataloader/v2script/Parser.hpp>
+#include "openvic-simulation/GameManager.hpp"
+#include "openvic-simulation/utility/Logger.hpp"
+
using namespace OpenVic;
using namespace OpenVic::NodeTools;
using namespace ovdl;
@@ -51,8 +51,7 @@ fs::path Dataloader::lookup_file(fs::path const& path) const {
const fs::path Dataloader::TXT = ".txt";
-static bool contains_file_with_name(Dataloader::path_vector_t const& paths,
- fs::path const& name) {
+static bool contains_file_with_name(Dataloader::path_vector_t const& paths, fs::path const& name) {
for (fs::path const& path : paths) {
if (path.filename() == name) return true;
@@ -60,8 +59,7 @@ static bool contains_file_with_name(Dataloader::path_vector_t const& paths,
return false;
}
-Dataloader::path_vector_t Dataloader::lookup_files_in_dir(fs::path const& path,
- fs::path const* extension) const {
+Dataloader::path_vector_t Dataloader::lookup_files_in_dir(fs::path const& path, fs::path const* extension) const {
path_vector_t ret;
for (fs::path const& root : roots) {
@@ -81,9 +79,7 @@ Dataloader::path_vector_t Dataloader::lookup_files_in_dir(fs::path const& path,
return ret;
}
-bool Dataloader::apply_to_files_in_dir(fs::path const& path,
- std::function<bool(fs::path const&)> callback,
- fs::path const* extension) const {
+bool Dataloader::apply_to_files_in_dir(fs::path const& path, std::function<bool(fs::path const&)> callback, fs::path const* extension) const {
bool ret = true;
for (fs::path const& file : lookup_files_in_dir(path, extension)) {
@@ -92,7 +88,7 @@ bool Dataloader::apply_to_files_in_dir(fs::path const& path,
return ret;
}
-template<std::derived_from<detail::BasicParser> Parser, bool(Parser::*parse_func)()>
+template<std::derived_from<detail::BasicParser> Parser, bool (Parser::*parse_func)()>
static Parser _run_ovdl_parser(fs::path const& path) {
Parser parser;
std::string buffer;
@@ -105,7 +101,8 @@ static Parser _run_ovdl_parser(fs::path const& path) {
Logger::error("Invalid input to parser error log callback: ", s, " / ", n, " / ", user_data);
return 0;
}
- }, &buffer
+ },
+ &buffer
};
parser.set_error_log_to(error_log_stream);
parser.load_from_file(path);
@@ -181,25 +178,26 @@ bool Dataloader::_load_map_dir(Map& map, fs::path const& map_directory) const {
bool ret = expect_dictionary_keys(
"max_provinces", ONE_EXACTLY,
- expect_uint(
- [&map](uint64_t val) -> bool {
- if (Province::NULL_INDEX < val && val <= Province::MAX_INDEX) {
- return map.set_max_provinces(val);
- }
- Logger::error("Invalid max province count ", val, " (out of valid range ", Province::NULL_INDEX, " < max_provinces <= ", Province::MAX_INDEX, ")");
- return false;
+ expect_uint(
+ [&map](uint64_t val) -> bool {
+ if (Province::NULL_INDEX < val && val <= Province::MAX_INDEX) {
+ return map.set_max_provinces(val);
}
- ),
+ Logger::error("Invalid max province count ", val, " (out of valid range ",
+ Province::NULL_INDEX, " < max_provinces <= ", Province::MAX_INDEX, ")");
+ return false;
+ }
+ ),
"sea_starts", ONE_EXACTLY,
- expect_list_reserve_length(
- water_province_identifiers,
- expect_identifier(
- [&water_province_identifiers](std::string_view identifier) -> bool {
- water_province_identifiers.push_back(identifier);
- return true;
- }
- )
- ),
+ expect_list_reserve_length(
+ water_province_identifiers,
+ expect_identifier(
+ [&water_province_identifiers](std::string_view identifier) -> bool {
+ water_province_identifiers.push_back(identifier);
+ return true;
+ }
+ )
+ ),
#define MAP_PATH_DICT_ENTRY(X) \
#X, ONE_EXACTLY, expect_string(assign_variable_callback(X)),
diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp
index 20538a6..efada89 100644
--- a/src/openvic-simulation/dataloader/Dataloader.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader.hpp
@@ -14,6 +14,7 @@ namespace OpenVic {
class Dataloader {
public:
using path_vector_t = std::vector<fs::path>;
+
private:
path_vector_t roots;
@@ -28,10 +29,8 @@ namespace OpenVic {
fs::path lookup_file(fs::path const& path) const;
static const fs::path TXT;
- path_vector_t lookup_files_in_dir(fs::path const& path,
- fs::path const* extension = &TXT) const;
- bool apply_to_files_in_dir(fs::path const& path,
- std::function<bool(fs::path const&)> callback,
+ path_vector_t lookup_files_in_dir(fs::path const& path, fs::path const* extension = &TXT) const;
+ bool apply_to_files_in_dir(fs::path const& path, std::function<bool(fs::path const&)> callback,
fs::path const* extension = &TXT) const;
bool load_defines(GameManager& game_manager) const;
diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp
index 3b05d04..63a97ad 100644
--- a/src/openvic-simulation/dataloader/NodeTools.cpp
+++ b/src/openvic-simulation/dataloader/NodeTools.cpp
@@ -1,7 +1,5 @@
#include "NodeTools.hpp"
-#include <charconv>
-
using namespace OpenVic;
using namespace OpenVic::NodeTools;
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 805de94..a68e922 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -2,12 +2,12 @@
#include <map>
+#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
+
#include "openvic-simulation/types/Colour.hpp"
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
-#include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp>
-
namespace OpenVic {
namespace ast = ovdl::v2script::ast;
@@ -56,7 +56,7 @@ namespace OpenVic {
size_t count;
dictionary_entry_t(expected_count_t new_expected_count, node_callback_t new_callback)
- : expected_count { new_expected_count }, callback { new_callback }, count { 0 } {}
+ : expected_count { new_expected_count }, callback { new_callback }, count { 0 } {}
constexpr bool must_appear() const {
return static_cast<uint8_t>(expected_count) & static_cast<uint8_t>(expected_count_t::_MUST_APPEAR);
@@ -106,7 +106,7 @@ namespace OpenVic {
template<typename T>
concept Reservable = requires(T& t) {
{ t.size() } -> std::same_as<size_t>;
- t.reserve( size_t {} );
+ t.reserve(size_t {});
};
template<Reservable T>
node_callback_t expect_list_reserve_length(T& t, node_callback_t callback) {