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.cpp124
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.hpp6
-rw-r--r--src/openvic-simulation/dataloader/Dataloader_Windows.hpp37
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp141
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp67
5 files changed, 178 insertions, 197 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index 7a904ed..5301aa1 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -89,8 +89,8 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
const bool hint_path_was_empty = hint_path.empty();
if (hint_path_was_empty) {
#if defined(_WIN32)
- static const fs::path registry_path = Windows::ReadRegValue<char>(HKEY_LOCAL_MACHINE,
- "SOFTWARE\\WOW6432Node\\Paradox Interactive\\Victoria 2", "path");
+ static const fs::path registry_path =
+ Windows::ReadRegValue<char>(HKEY_LOCAL_MACHINE, "SOFTWARE\\WOW6432Node\\Paradox Interactive\\Victoria 2", "path");
if (!registry_path.empty()) {
return registry_path;
@@ -171,7 +171,8 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
bool vic2_install_confirmed = false;
// if current_path is not a regular file, this is a non-default Steam Library, skip this parser evaluation
- if (fs::is_regular_file(current_path, error_code) && (is_libraryfolders_vdf || filename_equals(libraryfolders, current_path))) {
+ if (fs::is_regular_file(current_path, error_code) &&
+ (is_libraryfolders_vdf || filename_equals(libraryfolders, current_path))) {
lexy_vdf::Parser parser;
std::string buffer;
@@ -397,8 +398,8 @@ 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, fs::path const& extension,
- callback_t<fs::path const&> callback) const {
+bool Dataloader::apply_to_files_in_dir(fs::path const& path, fs::path const& extension, callback_t<fs::path const&> callback)
+ const {
bool ret = true;
for (fs::path const& file : lookup_files_in_dir(path, extension)) {
if (!callback(file)) {
@@ -478,8 +479,9 @@ bool Dataloader::_load_pop_types(
static const fs::path pop_type_directory = "poptypes";
const bool ret = apply_to_files_in_dir(pop_type_directory, ".txt",
[&pop_manager, &unit_manager, &good_manager](fs::path const& file) -> bool {
- return pop_manager.load_pop_type_file(file.stem().string(), unit_manager,
- good_manager, parse_defines(file).get_file_node());
+ return pop_manager.load_pop_type_file(
+ file.stem().string(), unit_manager, good_manager, parse_defines(file).get_file_node()
+ );
}
);
pop_manager.lock_pop_types();
@@ -491,8 +493,7 @@ bool Dataloader::_load_units(UnitManager& unit_manager, GoodManager const& good_
const bool ret = apply_to_files_in_dir(units_directory, ".txt",
[&unit_manager, &good_manager](fs::path const& file) -> bool {
return unit_manager.load_unit_file(good_manager, parse_defines(file).get_file_node());
- }
- );
+ });
unit_manager.lock_units();
return ret;
}
@@ -502,12 +503,16 @@ bool Dataloader::_load_oobs(GameManager& game_manager) const {
/* used for countries with no defined initial OOB */
game_manager.get_military_manager().get_deployment_manager().add_deployment(
- "NULL", std::vector<Army>(), std::vector<Navy>(), std::vector<Leader>());
+ "NULL", std::vector<Army>(), std::vector<Navy>(), std::vector<Leader>()
+ );
bool ret = apply_to_files_in_dir(oob_directory, ".txt", [&game_manager](fs::path const& file) -> bool {
- if (file.filename() == "v2dd2.txt") return true; /* dev diary just stuck in there for no reason whatsoever */
- return game_manager.get_military_manager().get_deployment_manager().load_oob_file(game_manager,
- file.filename().string(), parse_defines(file).get_file_node());
+ if (file.filename() == "v2dd2.txt") {
+ return true; /* dev diary just stuck in there for no reason whatsoever */
+ }
+ return game_manager.get_military_manager().get_deployment_manager().load_oob_file(
+ game_manager, file.filename().string(), parse_defines(file).get_file_node()
+ );
});
/* we also load OOBs in top level subdirectories, for other start dates etc */
@@ -518,8 +523,8 @@ bool Dataloader::_load_oobs(GameManager& game_manager) const {
if (entry.is_directory()) {
ret &= apply_to_files_in_dir(entry, ".txt", [&entry, &game_manager](fs::path const& file) -> bool {
return game_manager.get_military_manager().get_deployment_manager().load_oob_file(
- game_manager, (entry.path().filename() / file.filename()).string(),
- parse_defines(file).get_file_node());
+ game_manager, (entry.path().filename() / file.filename()).string(), parse_defines(file).get_file_node()
+ );
});
}
}
@@ -534,22 +539,21 @@ bool Dataloader::_load_countries(GameManager& game_manager) const {
bool is_dynamic = false;
- bool ret = expect_dictionary(
- [this, &game_manager, &is_dynamic](std::string_view key, ast::NodeCPtr value) -> bool {
- if (key == "dynamic_tags") {
- return expect_bool(assign_variable_callback(is_dynamic))(value);
- }
-
- std::string_view data_path;
+ bool ret = expect_dictionary([this, &game_manager, &is_dynamic](std::string_view key, ast::NodeCPtr value) -> bool {
+ if (key == "dynamic_tags") {
+ return expect_bool(assign_variable_callback(is_dynamic))(value);
+ }
- if (!expect_string(assign_variable_callback(data_path))(value)) {
- return false;
- }
+ std::string_view data_path;
- return game_manager.get_country_manager().load_country_data_file(game_manager, key, is_dynamic,
- parse_defines(lookup_file(countries_file.parent_path() / data_path)).get_file_node());
+ if (!expect_string(assign_variable_callback(data_path))(value)) {
+ return false;
}
- )(parse_defines(lookup_file(countries_file)).get_file_node());
+
+ return game_manager.get_country_manager().load_country_data_file(
+ game_manager, key, is_dynamic, parse_defines(lookup_file(countries_file.parent_path() / data_path)).get_file_node()
+ );
+ })(parse_defines(lookup_file(countries_file)).get_file_node());
game_manager.get_country_manager().lock_countries();
return ret;
@@ -560,19 +564,18 @@ bool Dataloader::_load_history(GameManager& game_manager) const {
static const fs::path province_history_directory = "history/provinces";
/* Country History */
- bool ret = apply_to_files_in_dir(country_history_directory, ".txt",
- [this, &game_manager](fs::path const& file) -> bool {
- std::string tag = file.filename().string().substr(0, 3);
-
- if (!game_manager.get_country_manager().has_country_identifier(tag)) {
- Logger::error("Error loading history for country ", tag, ": tag not defined!");
- return false;
- }
+ bool ret = apply_to_files_in_dir(country_history_directory, ".txt", [this, &game_manager](fs::path const& file) -> bool {
+ std::string tag = file.filename().string().substr(0, 3);
- return game_manager.get_history_manager().get_country_manager().load_country_history_file(
- game_manager, tag, parse_defines(lookup_file(file)).get_file_node());
+ if (!game_manager.get_country_manager().has_country_identifier(tag)) {
+ Logger::error("Error loading history for country ", tag, ": tag not defined!");
+ return false;
}
- );
+
+ return game_manager.get_history_manager().get_country_manager().load_country_history_file(
+ game_manager, tag, parse_defines(lookup_file(file)).get_file_node()
+ );
+ });
game_manager.get_history_manager().get_country_manager().lock_country_histories();
/* Province History */
@@ -591,7 +594,8 @@ bool Dataloader::_load_history(GameManager& game_manager) const {
}
return game_manager.get_history_manager().get_province_manager().load_province_history_file(
- game_manager, province_id, parse_defines(lookup_file(file)).get_file_node());
+ game_manager, province_id, parse_defines(lookup_file(file)).get_file_node()
+ );
});
}
}
@@ -657,8 +661,7 @@ bool Dataloader::_load_map_dir(GameManager& game_manager) const {
)
),
-#define MAP_PATH_DICT_ENTRY(X) \
- #X, ONE_EXACTLY, expect_string(assign_variable_callback(X)),
+#define MAP_PATH_DICT_ENTRY(X) #X, ONE_EXACTLY, expect_string(assign_variable_callback(X)),
APPLY_TO_MAP_PATHS(MAP_PATH_DICT_ENTRY)
#undef MAP_PATH_DICT_ENTRY
@@ -674,23 +677,20 @@ bool Dataloader::_load_map_dir(GameManager& game_manager) const {
Logger::error("Failed to load map default file!");
}
- if (!map.load_province_definitions(
- parse_csv(lookup_file(map_directory / definitions)).get_lines()
- )) {
+ if (!map.load_province_definitions(parse_csv(lookup_file(map_directory / definitions)).get_lines())) {
Logger::error("Failed to load province definitions file!");
ret = false;
}
if (!map.load_province_positions(
- game_manager.get_economy_manager().get_building_manager(), parse_defines(lookup_file(map_directory / positions)).get_file_node()
+ game_manager.get_economy_manager().get_building_manager(),
+ parse_defines(lookup_file(map_directory / positions)).get_file_node()
)) {
Logger::error("Failed to load province positions file!");
ret = false;
}
- if (!map.load_region_file(
- parse_defines(lookup_file(map_directory / region)).get_file_node()
- )) {
+ if (!map.load_region_file(parse_defines(lookup_file(map_directory / region)).get_file_node())) {
Logger::error("Failed to load region file!");
ret = false;
}
@@ -701,24 +701,18 @@ bool Dataloader::_load_map_dir(GameManager& game_manager) const {
}
if (!map.get_terrain_type_manager().load_terrain_types(
- game_manager.get_modifier_manager(),
- parse_defines(lookup_file(map_directory / terrain_definition)).get_file_node()
+ game_manager.get_modifier_manager(), parse_defines(lookup_file(map_directory / terrain_definition)).get_file_node()
)) {
Logger::error("Failed to load terrain types!");
ret = false;
}
- if (!map.load_map_images(
- lookup_file(map_directory / provinces),
- lookup_file(map_directory / terrain), false
- )) {
+ if (!map.load_map_images(lookup_file(map_directory / provinces), lookup_file(map_directory / terrain), false)) {
Logger::error("Failed to load map images!");
ret = false;
}
- if (!map.generate_and_load_province_adjacencies(
- parse_csv(lookup_file(map_directory / adjacencies)).get_lines()
- )) {
+ if (!map.generate_and_load_province_adjacencies(parse_csv(lookup_file(map_directory / adjacencies)).get_lines())) {
Logger::error("Failed to generate and load province adjacencies!");
ret = false;
}
@@ -757,13 +751,14 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
Logger::error("Failed to load goods!");
ret = false;
}
- if (!_load_units(game_manager.get_military_manager().get_unit_manager(),
- game_manager.get_economy_manager().get_good_manager()
+ if (!_load_units(
+ game_manager.get_military_manager().get_unit_manager(), game_manager.get_economy_manager().get_good_manager()
)) {
Logger::error("Failed to load units!");
ret = false;
}
- if (!_load_pop_types(game_manager.get_pop_manager(), game_manager.get_military_manager().get_unit_manager(),
+ if (!_load_pop_types(
+ game_manager.get_pop_manager(), game_manager.get_military_manager().get_unit_manager(),
game_manager.get_economy_manager().get_good_manager()
)) {
Logger::error("Failed to load pop types!");
@@ -855,11 +850,10 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
bool Dataloader::load_pop_history(GameManager& game_manager, fs::path const& path) const {
return apply_to_files_in_dir(path, ".txt", [&game_manager](fs::path const& file) -> bool {
- return game_manager.get_map().expect_province_dictionary(
- [&game_manager](Province& province, ast::NodeCPtr value) -> bool {
+ return game_manager.get_map()
+ .expect_province_dictionary([&game_manager](Province& province, ast::NodeCPtr value) -> bool {
return province.load_pop_list(game_manager.get_pop_manager(), value);
- }
- )(parse_defines(file).get_file_node());
+ })(parse_defines(file).get_file_node());
});
}
diff --git a/src/openvic-simulation/dataloader/Dataloader.hpp b/src/openvic-simulation/dataloader/Dataloader.hpp
index 1a8e9ab..0bf3086 100644
--- a/src/openvic-simulation/dataloader/Dataloader.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader.hpp
@@ -92,9 +92,9 @@ namespace OpenVic {
Finnish,
_LocaleCount
};
- static constexpr char const* locale_names[_LocaleCount] = {
- "en_GB", "fr_FR", "de_DE", "pl_PL", "es_ES", "it_IT", "sv_SE", "cs_CZ", "hu_HU", "nl_NL", "pt_PT", "ru_RU", "fi_FI"
- };
+ static constexpr char const* locale_names[_LocaleCount] = { "en_GB", "fr_FR", "de_DE", "pl_PL", "es_ES",
+ "it_IT", "sv_SE", "cs_CZ", "hu_HU", "nl_NL",
+ "pt_PT", "ru_RU", "fi_FI" };
/* Args: key, locale, localisation */
using localisation_callback_t = NodeTools::callback_t<std::string_view, locale_t, std::string_view>;
diff --git a/src/openvic-simulation/dataloader/Dataloader_Windows.hpp b/src/openvic-simulation/dataloader/Dataloader_Windows.hpp
index 6b6fce3..37991b6 100644
--- a/src/openvic-simulation/dataloader/Dataloader_Windows.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader_Windows.hpp
@@ -55,22 +55,17 @@ namespace OpenVic::Windows {
template<typename T>
concept has_data = requires(T t) {
- {
- t.data()
- }
- -> std::convertible_to<const typename T::value_type*>;
+ { t.data() } -> std::convertible_to<const typename T::value_type*>;
};
class RegistryKey {
public:
- RegistryKey(HKEY key_handle)
- : _key_handle(key_handle) {
- }
+ RegistryKey(HKEY key_handle) : _key_handle(key_handle) {}
template<either_char_type CHAR_T, either_char_type CHAR_T2>
- RegistryKey(HKEY parent_key_handle,
- std::basic_string_view<CHAR_T> child_key_name,
- std::basic_string_view<CHAR_T2> value_name) {
+ RegistryKey(
+ HKEY parent_key_handle, std::basic_string_view<CHAR_T> child_key_name, std::basic_string_view<CHAR_T2> value_name
+ ) {
open_key(parent_key_handle, child_key_name);
query_key(value_name);
}
@@ -100,14 +95,10 @@ namespace OpenVic::Windows {
}
bool is_predefined() const {
- return (_key_handle == HKEY_CURRENT_USER) ||
- (_key_handle == HKEY_LOCAL_MACHINE) ||
- (_key_handle == HKEY_CLASSES_ROOT) ||
- (_key_handle == HKEY_CURRENT_CONFIG) ||
- (_key_handle == HKEY_CURRENT_USER_LOCAL_SETTINGS) ||
- (_key_handle == HKEY_PERFORMANCE_DATA) ||
- (_key_handle == HKEY_PERFORMANCE_NLSTEXT) ||
- (_key_handle == HKEY_PERFORMANCE_TEXT) ||
+ return (_key_handle == HKEY_CURRENT_USER) || (_key_handle == HKEY_LOCAL_MACHINE) ||
+ (_key_handle == HKEY_CLASSES_ROOT) || (_key_handle == HKEY_CURRENT_CONFIG) ||
+ (_key_handle == HKEY_CURRENT_USER_LOCAL_SETTINGS) || (_key_handle == HKEY_PERFORMANCE_DATA) ||
+ (_key_handle == HKEY_PERFORMANCE_NLSTEXT) || (_key_handle == HKEY_PERFORMANCE_TEXT) ||
(_key_handle == HKEY_USERS);
}
@@ -139,7 +130,9 @@ namespace OpenVic::Windows {
return result;
}
_value = std::wstring(data_size / sizeof(wchar_t), L'\0');
- result = RegQueryValueExW(_key_handle, wide_value.data(), NULL, NULL, reinterpret_cast<LPBYTE>(_value.data()), &data_size);
+ result = RegQueryValueExW(
+ _key_handle, wide_value.data(), NULL, NULL, reinterpret_cast<LPBYTE>(_value.data()), &data_size
+ );
close_key();
std::size_t first_null = _value.find_first_of(L'\0');
@@ -156,7 +149,9 @@ namespace OpenVic::Windows {
};
template<either_char_type RCHAR_T, either_char_type CHAR_T, either_char_type CHAR_T2>
- std::basic_string<RCHAR_T> ReadRegValue(HKEY root, std::basic_string_view<CHAR_T> key, std::basic_string_view<CHAR_T2> name) {
+ std::basic_string<RCHAR_T> ReadRegValue(
+ HKEY root, std::basic_string_view<CHAR_T> key, std::basic_string_view<CHAR_T2> name
+ ) {
RegistryKey registry_key(root, key, name);
if constexpr (std::is_same_v<RCHAR_T, char>) {
return convert(registry_key.value());
@@ -172,4 +167,4 @@ namespace OpenVic::Windows {
return ReadRegValue<RCHAR_T>(root, key_sv, name_sv);
}
-} \ No newline at end of file
+}
diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp
index 69aebc9..2f93bc2 100644
--- a/src/openvic-simulation/dataloader/NodeTools.cpp
+++ b/src/openvic-simulation/dataloader/NodeTools.cpp
@@ -53,55 +53,51 @@ node_callback_t NodeTools::expect_identifier_or_string(callback_t<std::string_vi
if (cast_node != nullptr) {
return _abstract_string_node_callback<ast::AbstractStringNode>(callback, allow_empty)(*cast_node);
}
- Logger::error("Invalid node type ", node->get_type(), " when expecting ",
- ast::IdentifierNode::get_type_static(), " or ", ast::StringNode::get_type_static());
+ Logger::error(
+ "Invalid node type ", node->get_type(), " when expecting ", ast::IdentifierNode::get_type_static(), " or ",
+ ast::StringNode::get_type_static()
+ );
} else {
- Logger::error("Null node when expecting ", ast::IdentifierNode::get_type_static(), " or ", ast::StringNode::get_type_static());
+ Logger::error(
+ "Null node when expecting ", ast::IdentifierNode::get_type_static(), " or ", ast::StringNode::get_type_static()
+ );
}
return false;
};
}
node_callback_t NodeTools::expect_bool(callback_t<bool> callback) {
- static const string_map_t<bool> bool_map = {
- { "yes", true }, { "no", false }
- };
+ static const string_map_t<bool> bool_map = { { "yes", true }, { "no", false } };
return expect_identifier(expect_mapped_string(bool_map, callback));
}
node_callback_t NodeTools::expect_int_bool(callback_t<bool> callback) {
- static const string_map_t<bool> bool_map = {
- { "1", true }, { "0", false }
- };
+ static const string_map_t<bool> bool_map = { { "1", true }, { "0", false } };
return expect_identifier(expect_mapped_string(bool_map, callback));
}
node_callback_t NodeTools::expect_int64(callback_t<int64_t> callback) {
- return expect_identifier(
- [callback](std::string_view identifier) -> bool {
- bool successful = false;
- const int64_t val = StringUtils::string_to_int64(identifier, &successful, 10);
- if (successful) {
- return callback(val);
- }
- Logger::error("Invalid int identifier text: ", identifier);
- return false;
+ return expect_identifier([callback](std::string_view identifier) -> bool {
+ bool successful = false;
+ const int64_t val = StringUtils::string_to_int64(identifier, &successful, 10);
+ if (successful) {
+ return callback(val);
}
- );
+ Logger::error("Invalid int identifier text: ", identifier);
+ return false;
+ });
}
node_callback_t NodeTools::expect_uint64(callback_t<uint64_t> callback) {
- return expect_identifier(
- [callback](std::string_view identifier) -> bool {
- bool successful = false;
- const uint64_t val = StringUtils::string_to_uint64(identifier, &successful, 10);
- if (successful) {
- return callback(val);
- }
- Logger::error("Invalid uint identifier text: ", identifier);
- return false;
+ return expect_identifier([callback](std::string_view identifier) -> bool {
+ bool successful = false;
+ const uint64_t val = StringUtils::string_to_uint64(identifier, &successful, 10);
+ if (successful) {
+ return callback(val);
}
- );
+ Logger::error("Invalid uint identifier text: ", identifier);
+ return false;
+ });
}
callback_t<std::string_view> NodeTools::expect_fixed_point_str(callback_t<fixed_point_t> callback) {
@@ -201,30 +197,26 @@ node_callback_t NodeTools::expect_fvec2(callback_t<fvec2_t> callback) {
}
node_callback_t NodeTools::expect_assign(key_value_callback_t callback) {
- return _expect_type<ast::AssignNode>(
- [callback](ast::AssignNode const& assign_node) -> bool {
- return callback(assign_node._name, assign_node._initializer.get());
- }
- );
+ return _expect_type<ast::AssignNode>([callback](ast::AssignNode const& assign_node) -> bool {
+ return callback(assign_node._name, assign_node._initializer.get());
+ });
}
node_callback_t NodeTools::expect_list_and_length(length_callback_t length_callback, node_callback_t callback) {
- return _expect_type<ast::AbstractListNode>(
- [length_callback, callback](ast::AbstractListNode const& list_node) -> bool {
- std::vector<ast::NodeUPtr> const& list = list_node._statements;
- bool ret = true;
- size_t size = length_callback(list.size());
- if (size > list.size()) {
- Logger::error("Trying to read more values than the list contains: ", size, " > ", list.size());
- size = list.size();
- ret = false;
- }
- std::for_each(list.begin(), list.begin() + size, [callback, &ret](ast::NodeUPtr const& sub_node) -> void {
- ret &= callback(sub_node.get());
- });
- return ret;
+ return _expect_type<ast::AbstractListNode>([length_callback, callback](ast::AbstractListNode const& list_node) -> bool {
+ std::vector<ast::NodeUPtr> const& list = list_node._statements;
+ bool ret = true;
+ size_t size = length_callback(list.size());
+ if (size > list.size()) {
+ Logger::error("Trying to read more values than the list contains: ", size, " > ", list.size());
+ size = list.size();
+ ret = false;
}
- );
+ std::for_each(list.begin(), list.begin() + size, [callback, &ret](ast::NodeUPtr const& sub_node) -> void {
+ ret &= callback(sub_node.get());
+ });
+ return ret;
+ });
}
node_callback_t NodeTools::expect_list_of_length(size_t length, node_callback_t callback) {
@@ -266,26 +258,24 @@ node_callback_t NodeTools::expect_length(callback_t<size_t> callback) {
}
node_callback_t NodeTools::expect_key(std::string_view key, node_callback_t callback, bool* key_found) {
- return _expect_type<ast::AbstractListNode>(
- [key, callback, key_found](ast::AbstractListNode const& list_node) -> bool {
- std::vector<ast::NodeUPtr> const& list = list_node._statements;
- for (ast::NodeUPtr const& sub_node : list_node._statements) {
- ast::AssignNode const* assign_node = sub_node->cast_to<ast::AssignNode>();
- if (assign_node != nullptr && assign_node->_name == key) {
- if (key_found != nullptr) {
- *key_found = true;
- }
- return callback(&*assign_node->_initializer);
+ return _expect_type<ast::AbstractListNode>([key, callback, key_found](ast::AbstractListNode const& list_node) -> bool {
+ std::vector<ast::NodeUPtr> const& list = list_node._statements;
+ for (ast::NodeUPtr const& sub_node : list_node._statements) {
+ ast::AssignNode const* assign_node = sub_node->cast_to<ast::AssignNode>();
+ if (assign_node != nullptr && assign_node->_name == key) {
+ if (key_found != nullptr) {
+ *key_found = true;
}
+ return callback(&*assign_node->_initializer);
}
- if (key_found != nullptr) {
- *key_found = false;
- } else {
- Logger::error("Failed to find expected key: ", key);
- }
- return false;
}
- );
+ if (key_found != nullptr) {
+ *key_found = false;
+ } else {
+ Logger::error("Failed to find expected key: ", key);
+ }
+ return false;
+ });
}
node_callback_t NodeTools::expect_dictionary_and_length(length_callback_t length_callback, key_value_callback_t callback) {
@@ -296,8 +286,9 @@ node_callback_t NodeTools::expect_dictionary(key_value_callback_t callback) {
return expect_dictionary_and_length(default_length_callback, callback);
}
-bool NodeTools::add_key_map_entry(key_map_t& key_map, std::string_view key,
- dictionary_entry_t::expected_count_t expected_count, node_callback_t callback) {
+bool NodeTools::add_key_map_entry(
+ key_map_t& key_map, std::string_view key, dictionary_entry_t::expected_count_t expected_count, node_callback_t callback
+) {
if (key_map.find(key) == key_map.end()) {
key_map.emplace(key, dictionary_entry_t { expected_count, callback });
return true;
@@ -344,12 +335,11 @@ bool NodeTools::check_key_map_counts(key_map_t& key_map) {
return ret;
}
-node_callback_t NodeTools::expect_dictionary_key_map_and_length_and_default(key_map_t key_map,
- length_callback_t length_callback, key_value_callback_t default_callback) {
+node_callback_t NodeTools::expect_dictionary_key_map_and_length_and_default(
+ key_map_t key_map, length_callback_t length_callback, key_value_callback_t default_callback
+) {
return [length_callback, default_callback, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> bool {
- bool ret = expect_dictionary_and_length(
- length_callback, dictionary_keys_callback(key_map, default_callback)
- )(node);
+ bool ret = expect_dictionary_and_length(length_callback, dictionary_keys_callback(key_map, default_callback))(node);
ret &= check_key_map_counts(key_map);
return ret;
};
@@ -364,8 +354,9 @@ node_callback_t NodeTools::expect_dictionary_key_map_and_default(key_map_t key_m
}
node_callback_t NodeTools::expect_dictionary_key_map(key_map_t key_map) {
- return expect_dictionary_key_map_and_length_and_default(std::move(key_map),
- default_length_callback, key_value_invalid_callback);
+ return expect_dictionary_key_map_and_length_and_default(
+ std::move(key_map), default_length_callback, key_value_invalid_callback
+ );
}
node_callback_t NodeTools::name_list_callback(callback_t<std::vector<std::string>&&> callback) {
diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp
index 7ad5412..798976f 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -27,19 +27,13 @@ namespace OpenVic {
namespace NodeTools {
template<typename Fn, typename Return = void, typename... Args>
- concept Functor = requires(Fn&& fn, Args&& ... args) {
- {
- std::invoke(std::forward<Fn>(fn), std::forward<Args>(args)...)
- }
- -> std::same_as<Return>;
+ concept Functor = requires(Fn&& fn, Args&&... args) {
+ { std::invoke(std::forward<Fn>(fn), std::forward<Args>(args)...) } -> std::same_as<Return>;
};
template<typename Fn, typename Return = void, typename... Args>
- concept FunctorConvertible = requires(Fn&& fn, Args&& ... args) {
- {
- std::invoke(std::forward<Fn>(fn), std::forward<Args>(args)...)
- }
- -> std::convertible_to<Return>;
+ concept FunctorConvertible = requires(Fn&& fn, Args&&... args) {
+ { std::invoke(std::forward<Fn>(fn), std::forward<Args>(args)...) } -> std::convertible_to<Return>;
};
template<typename Fn, typename... Args>
@@ -88,7 +82,10 @@ namespace OpenVic {
val <= static_cast<int64_t>(std::numeric_limits<T>::max())) {
return callback(val);
}
- Logger::error("Invalid int: ", val, " (valid range: [", static_cast<int64_t>(std::numeric_limits<T>::lowest()), ", ", static_cast<int64_t>(std::numeric_limits<T>::max()), "])");
+ Logger::error(
+ "Invalid int: ", val, " (valid range: [", static_cast<int64_t>(std::numeric_limits<T>::lowest()), ", ",
+ static_cast<int64_t>(std::numeric_limits<T>::max()), "])"
+ );
return false;
});
}
@@ -99,7 +96,9 @@ namespace OpenVic {
if (val <= static_cast<uint64_t>(std::numeric_limits<T>::max())) {
return callback(val);
}
- Logger::error("Invalid uint: ", val, " (valid range: [0, ", static_cast<uint64_t>(std::numeric_limits<T>::max()), "])");
+ Logger::error(
+ "Invalid uint: ", val, " (valid range: [0, ", static_cast<uint64_t>(std::numeric_limits<T>::max()), "])"
+ );
return false;
});
}
@@ -159,8 +158,10 @@ namespace OpenVic {
using enum dictionary_entry_t::expected_count_t;
using key_map_t = string_map_t<dictionary_entry_t>;
- bool add_key_map_entry(key_map_t& key_map, std::string_view key,
- dictionary_entry_t::expected_count_t expected_count, node_callback_t callback);
+ bool add_key_map_entry(
+ key_map_t& key_map, std::string_view key, dictionary_entry_t::expected_count_t expected_count,
+ node_callback_t callback
+ );
bool remove_key_map_entry(key_map_t& key_map, std::string_view key);
key_value_callback_t dictionary_keys_callback(key_map_t& key_map, key_value_callback_t default_callback);
bool check_key_map_counts(key_map_t& key_map);
@@ -169,30 +170,35 @@ namespace OpenVic {
return true;
}
template<typename... Args>
- bool add_key_map_entries(key_map_t& key_map, std::string_view key,
- dictionary_entry_t::expected_count_t expected_count, NodeCallback auto callback, Args... args) {
+ bool add_key_map_entries(
+ key_map_t& key_map, std::string_view key, dictionary_entry_t::expected_count_t expected_count,
+ NodeCallback auto callback, Args... args
+ ) {
bool ret = add_key_map_entry(key_map, key, expected_count, callback);
ret &= add_key_map_entries(key_map, args...);
return ret;
}
- node_callback_t expect_dictionary_key_map_and_length_and_default(key_map_t key_map,
- length_callback_t length_callback, key_value_callback_t default_callback);
+ node_callback_t expect_dictionary_key_map_and_length_and_default(
+ key_map_t key_map, length_callback_t length_callback, key_value_callback_t default_callback
+ );
node_callback_t expect_dictionary_key_map_and_length(key_map_t key_map, length_callback_t length_callback);
node_callback_t expect_dictionary_key_map_and_default(key_map_t key_map, key_value_callback_t default_callback);
node_callback_t expect_dictionary_key_map(key_map_t key_map);
template<typename... Args>
- NodeCallback auto expect_dictionary_key_map_and_length_and_default(key_map_t key_map,
- length_callback_t length_callback, key_value_callback_t default_callback, Args... args) {
+ NodeCallback auto expect_dictionary_key_map_and_length_and_default(
+ key_map_t key_map, length_callback_t length_callback, key_value_callback_t default_callback, Args... args
+ ) {
// TODO - pass return value back up (part of big key_map_t rewrite?)
add_key_map_entries(key_map, args...);
return expect_dictionary_key_map_and_length_and_default(std::move(key_map), length_callback, default_callback);
}
template<typename... Args>
- NodeCallback auto expect_dictionary_keys_and_length_and_default(LengthCallback auto length_callback,
- KeyValueCallback auto default_callback, Args... args) {
+ NodeCallback auto expect_dictionary_keys_and_length_and_default(
+ LengthCallback auto length_callback, KeyValueCallback auto default_callback, Args... args
+ ) {
return expect_dictionary_key_map_and_length_and_default({}, length_callback, default_callback, args...);
}
@@ -208,15 +214,14 @@ namespace OpenVic {
template<typename... Args>
NodeCallback auto expect_dictionary_keys(Args... args) {
- return expect_dictionary_key_map_and_length_and_default({}, default_length_callback, key_value_invalid_callback, args...);
+ return expect_dictionary_key_map_and_length_and_default(
+ {}, default_length_callback, key_value_invalid_callback, args...
+ );
}
template<typename T>
concept Reservable = requires(T& t) {
- {
- t.size()
- }
- -> std::same_as<size_t>;
+ { t.size() } -> std::same_as<size_t>;
t.reserve(size_t {});
};
template<Reservable T>
@@ -288,9 +293,7 @@ namespace OpenVic {
}
template<typename T>
- requires requires(T& t) {
- t += T {};
- }
+ requires requires(T& t) { t += T {}; }
Callback<T> auto add_variable_callback(T& var) {
return [&var](T val) -> bool {
var += val;
@@ -299,9 +302,7 @@ namespace OpenVic {
}
template<typename T>
- requires requires(T& t) {
- t++;
- }
+ requires requires(T& t) { t++; }
KeyValueCallback auto increment_callback(T& var) {
return [&var](std::string_view, ast::NodeCPtr) -> bool {
var++;