aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/dataloader
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-10-29 21:14:55 +0100
committer GitHub <noreply@github.com>2023-10-29 21:14:55 +0100
commit06cc0606156d009026930c785c62434276fbe782 (patch)
treed37fcb69766ec029ea4e3e2816c419f9d7e05f7c /src/openvic-simulation/dataloader
parentd8ec90f07342876e9331819bd3cc372050f78248 (diff)
parent1b5e43fa7750cc4025d32f18390593cbce3ba842 (diff)
Merge pull request #67 from OpenVicProject/format
Formating
Diffstat (limited to 'src/openvic-simulation/dataloader')
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.cpp266
-rw-r--r--src/openvic-simulation/dataloader/Dataloader.hpp31
-rw-r--r--src/openvic-simulation/dataloader/Dataloader_Windows.hpp54
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.cpp169
-rw-r--r--src/openvic-simulation/dataloader/NodeTools.hpp59
5 files changed, 322 insertions, 257 deletions
diff --git a/src/openvic-simulation/dataloader/Dataloader.cpp b/src/openvic-simulation/dataloader/Dataloader.cpp
index ad35056..5301aa1 100644
--- a/src/openvic-simulation/dataloader/Dataloader.cpp
+++ b/src/openvic-simulation/dataloader/Dataloader.cpp
@@ -51,16 +51,18 @@ concept is_filename = std::same_as<T, std::filesystem::path> || std::convertible
static bool filename_equals(const is_filename auto& lhs, const is_filename auto& rhs) {
auto left = [&lhs] {
- if constexpr (std::same_as<std::decay_t<decltype(lhs)>, std::filesystem::path>)
+ if constexpr (std::same_as<std::decay_t<decltype(lhs)>, std::filesystem::path>) {
return lhs.filename().string();
- else
+ } else {
return lhs;
+ }
}();
auto right = [&rhs] {
- if constexpr (std::same_as<std::decay_t<decltype(rhs)>, std::filesystem::path>)
+ if constexpr (std::same_as<std::decay_t<decltype(rhs)>, std::filesystem::path>) {
return rhs.filename().string();
- else
+ } else {
return rhs;
+ }
}();
return path_equals(left, right);
}
@@ -79,17 +81,20 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
// Don't waste time trying to search for Victoria 2 when supplied a valid looking Victoria 2 game directory
if (filename_equals(Victoria_2_folder, hint_path)) {
- if (fs::is_regular_file(hint_path / v2_game_exe, error_code))
+ if (fs::is_regular_file(hint_path / v2_game_exe, error_code)) {
return 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())
+ if (!registry_path.empty()) {
return registry_path;
+ }
#pragma warning(push)
#pragma warning(disable : 4996)
@@ -104,14 +109,14 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
}
}
#pragma warning(pop)
-// Cannot support Android
-// Only FreeBSD currently unofficially supports emulating Linux
+ // Cannot support Android
+ // Only FreeBSD currently unofficially supports emulating Linux
#elif (defined(__linux__) && !defined(__ANDROID__)) || defined(__FreeBSD__)
static const fs::path home = std::getenv("HOME");
hint_path = home / ".steam" / "steam";
- if (fs::is_symlink(hint_path, error_code))
+ if (fs::is_symlink(hint_path, error_code)) {
hint_path = fs::read_symlink(hint_path, error_code);
- else if (!fs::is_directory(hint_path, error_code)) {
+ } else if (!fs::is_directory(hint_path, error_code)) {
hint_path = home / ".local" / "share" / "Steam";
if (!fs::is_directory(hint_path, error_code)) {
#ifdef __FreeBSD__
@@ -122,7 +127,7 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
return "";
}
}
-// Support only Mac, cannot support iOS
+ // Support only Mac, cannot support iOS
#elif (defined(__APPLE__) && defined(__MACH__)) && TARGET_OS_MAC == 1
static const fs::path home = std::getenv("HOME");
hint_path = home / "Library" / "Application Support" / "Steam";
@@ -130,18 +135,21 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
Logger::warning("Could not find path for Steam installation on Mac.");
return "";
}
-// All platforms that reach this point do not seem to even have unofficial Steam support
+ // All platforms that reach this point do not seem to even have unofficial Steam support
#else
Logger::warning("Could not find path for Steam installation on unsupported platform.");
#endif
}
// Could not determine Steam install on platform
- if (hint_path.empty()) return "";
+ if (hint_path.empty()) {
+ return "";
+ }
// Supplied path was useless, ignore hint_path
- if (!hint_path_was_empty && !fs::exists(hint_path, error_code))
+ if (!hint_path_was_empty && !fs::exists(hint_path, error_code)) {
return _search_for_game_path();
+ }
// Steam Library's directory that will contain Victoria 2
fs::path vic2_steam_lib_directory;
@@ -163,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;
@@ -184,8 +193,9 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
parser.load_from_file(current_path);
if (!parser.parse()) {
// Could not find or load libraryfolders.vdf, report error as warning
- if (!buffer.empty())
+ if (!buffer.empty()) {
Logger::warning _(buffer);
+ }
return "";
}
std::optional current_node = *(parser.get_key_values());
@@ -305,8 +315,9 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
}
// Hail Mary check ignoring the hint_path
- if (!hint_path_was_empty)
+ if (!hint_path_was_empty) {
return _search_for_game_path();
+ }
Logger::warning("Could not find Victoria 2 game path, this requires manually supplying one.");
return ""; // The supplied path fits literally none of the criteria
@@ -314,8 +325,9 @@ static fs::path _search_for_game_path(fs::path hint_path = {}) {
fs::path Dataloader::search_for_game_path(fs::path hint_path) {
auto it = _cached_paths.find(hint_path);
- if (it != _cached_paths.end())
+ if (it != _cached_paths.end()) {
return it->second;
+ }
return _cached_paths[hint_path] = _search_for_game_path(hint_path);
}
@@ -360,7 +372,9 @@ fs::path Dataloader::lookup_file(fs::path const& path) const {
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;
+ if (path.filename() == name) {
+ return true;
+ }
}
return false;
}
@@ -384,7 +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)) {
@@ -458,18 +473,27 @@ csv::Windows1252Parser Dataloader::parse_csv(fs::path const& path) {
return _run_ovdl_parser<csv::Windows1252Parser, &_csv_parse>(path);
}
-bool Dataloader::_load_pop_types(PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager, fs::path const& pop_type_directory) const {
- 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());
- });
+bool Dataloader::_load_pop_types(
+ PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager
+) const {
+ 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()
+ );
+ }
+ );
pop_manager.lock_pop_types();
return ret;
}
-bool Dataloader::_load_units(UnitManager& unit_manager, GoodManager const& good_manager, fs::path const& units_directory) const {
- 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());
- });
+bool Dataloader::_load_units(UnitManager& unit_manager, GoodManager const& good_manager) const {
+ static const fs::path units_directory = "units";
+ 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;
}
@@ -478,11 +502,17 @@ bool Dataloader::_load_oobs(GameManager& game_manager) const {
static const fs::path oob_directory = "history/units";
/* 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>());
+ game_manager.get_military_manager().get_deployment_manager().add_deployment(
+ "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 */
@@ -492,7 +522,9 @@ bool Dataloader::_load_oobs(GameManager& game_manager) const {
for (fs::directory_entry const& entry : fs::directory_iterator { path, ec }) {
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());
+ 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()
+ );
});
}
}
@@ -507,21 +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;
@@ -530,7 +562,7 @@ bool Dataloader::_load_countries(GameManager& game_manager) const {
bool Dataloader::_load_history(GameManager& game_manager) const {
static const fs::path country_history_directory = "history/countries";
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);
@@ -539,8 +571,10 @@ bool Dataloader::_load_history(GameManager& game_manager) const {
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());
+
+ 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();
@@ -559,7 +593,9 @@ bool Dataloader::_load_history(GameManager& game_manager) const {
return false;
}
- 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());
+ 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()
+ );
});
}
}
@@ -569,7 +605,8 @@ bool Dataloader::_load_history(GameManager& game_manager) const {
return ret;
}
-bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_directory) const {
+bool Dataloader::_load_map_dir(GameManager& game_manager) const {
+ static const fs::path map_directory = "map";
Map& map = game_manager.get_map();
static const fs::path defaults_filename = "default.map";
@@ -610,29 +647,27 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di
bool ret = expect_dictionary_keys(
"max_provinces", ONE_EXACTLY,
- expect_uint<Province::index_t>(
- std::bind(&Map::set_max_provinces, &map, std::placeholders::_1)
- ),
+ expect_uint<Province::index_t>(
+ std::bind(&Map::set_max_provinces, &map, std::placeholders::_1)
+ ),
"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)),
+#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
#undef APPLY_TO_MAP_PATHS
- "border_heights",
- ZERO_OR_ONE, success_callback,
+ "border_heights", ZERO_OR_ONE, success_callback,
"terrain_sheet_heights", ZERO_OR_ONE, success_callback,
"tree", ZERO_OR_ONE, success_callback,
"border_cutoff", ZERO_OR_ONE, success_callback
@@ -642,23 +677,20 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di
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;
}
@@ -669,24 +701,18 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di
}
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;
}
@@ -695,10 +721,6 @@ bool Dataloader::_load_map_dir(GameManager& game_manager, fs::path const& map_di
}
bool Dataloader::load_defines(GameManager& game_manager) const {
- static const fs::path map_directory = "map";
- static const fs::path pop_type_directory = "poptypes";
- static const fs::path units_directory = "units";
-
static const fs::path defines_file = "common/defines.lua";
static const fs::path buildings_file = "common/buildings.txt";
static const fs::path bookmark_file = "common/bookmarks.txt";
@@ -724,82 +746,85 @@ bool Dataloader::load_defines(GameManager& game_manager) const {
ret = false;
}
if (!game_manager.get_economy_manager().get_good_manager().load_goods_file(
- parse_defines(lookup_file(goods_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(goods_file)).get_file_node()
+ )) {
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(), units_directory)) {
+ 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(), game_manager.get_economy_manager().get_good_manager(), pop_type_directory)) {
+ 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!");
ret = false;
}
if (!game_manager.get_pop_manager().get_culture_manager().load_graphical_culture_type_file(
- parse_defines(lookup_file(graphical_culture_type_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(graphical_culture_type_file)).get_file_node()
+ )) {
Logger::error("Failed to load graphical culture types!");
ret = false;
}
if (!game_manager.get_pop_manager().get_culture_manager().load_culture_file(
- parse_defines(lookup_file(culture_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(culture_file)).get_file_node()
+ )) {
Logger::error("Failed to load cultures!");
ret = false;
}
if (!game_manager.get_pop_manager().get_religion_manager().load_religion_file(
- parse_defines(lookup_file(religion_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(religion_file)).get_file_node()
+ )) {
Logger::error("Failed to load religions!");
ret = false;
}
if (!game_manager.get_politics_manager().get_ideology_manager().load_ideology_file(
- parse_defines(lookup_file(ideology_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(ideology_file)).get_file_node()
+ )) {
Logger::error("Failed to load ideologies!");
ret = false;
}
if (!game_manager.get_politics_manager().load_government_types_file(
- parse_defines(lookup_file(governments_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(governments_file)).get_file_node()
+ )) {
Logger::error("Failed to load government types!");
ret = false;
}
if (!game_manager.get_politics_manager().get_issue_manager().load_issues_file(
- parse_defines(lookup_file(issues_file)).get_file_node()
- )) {
+ parse_defines(lookup_file(issues_file)).get_file_node()
+ )) {
Logger::error("Failed to load issues!");
ret = false;
}
if (!game_manager.get_politics_manager().get_national_value_manager().load_national_values_file(
- game_manager.get_modifier_manager(), parse_defines(lookup_file(national_values_file)).get_file_node()
- )) {
+ game_manager.get_modifier_manager(), parse_defines(lookup_file(national_values_file)).get_file_node()
+ )) {
Logger::error("Failed to load national values!");
ret = false;
}
- if (!game_manager.get_economy_manager().load_production_types_file(
- game_manager.get_pop_manager(),
- parse_defines(lookup_file(production_types_file)).get_file_node()
- )) {
+ if (!game_manager.get_economy_manager().load_production_types_file(game_manager.get_pop_manager(),
+ parse_defines(lookup_file(production_types_file)).get_file_node()
+ )) {
Logger::error("Failed to load production types!");
ret = false;
}
- if (!game_manager.get_economy_manager().load_buildings_file(
- game_manager.get_modifier_manager(),
- parse_defines(lookup_file(buildings_file)).get_file_node()
- )) {
+ if (!game_manager.get_economy_manager().load_buildings_file(game_manager.get_modifier_manager(),
+ parse_defines(lookup_file(buildings_file)).get_file_node()
+ )) {
Logger::error("Failed to load buildings!");
ret = false;
}
- if (!_load_map_dir(game_manager, map_directory)) {
+ if (!_load_map_dir(game_manager)) {
Logger::error("Failed to load map!");
ret = false;
}
if (!game_manager.get_military_manager().get_leader_trait_manager().load_leader_traits_file(
- game_manager.get_modifier_manager(), parse_defines(lookup_file(leader_traits_file)).get_file_node()
- )) {
+ game_manager.get_modifier_manager(), parse_defines(lookup_file(leader_traits_file)).get_file_node()
+ )) {
Logger::error("Failed to load leader traits!");
ret = false;
}
@@ -825,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 4a8b111..0bf3086 100644
--- a/src/openvic-simulation/dataloader/Dataloader.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader.hpp
@@ -23,9 +23,11 @@ namespace OpenVic {
private:
path_vector_t roots;
- bool _load_pop_types(PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager, fs::path const& pop_type_directory) const;
- bool _load_units(UnitManager& unit_manager, GoodManager const& good_manager, fs::path const& units_directory) const;
- bool _load_map_dir(GameManager& game_manager, fs::path const& map_directory) const;
+ bool _load_pop_types(
+ PopManager& pop_manager, UnitManager const& unit_manager, GoodManager const& good_manager
+ ) const;
+ bool _load_units(UnitManager& unit_manager, GoodManager const& good_manager) const;
+ bool _load_map_dir(GameManager& game_manager) const;
bool _load_oobs(GameManager& game_manager) const;
bool _load_countries(GameManager& game_manager) const;
bool _load_history(GameManager& game_manager) const;
@@ -43,15 +45,18 @@ namespace OpenVic {
/// Supports being supplied:
/// 1. A valid Victoria 2 game directory (Victoria 2 directory that contains a v2game.exe file)
/// 2. An Empty path: assumes a common Steam install structure per platform.
- /// 2b. If Windows, returns "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Paradox Interactive\Victoria 2" "path" registry value
+ /// 2b. If Windows, returns "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Paradox Interactive\Victoria 2"
+ /// "path" registry value
/// 2c. If registry value returns an empty string, performs Steam checks below
/// 3. A path to a root Steam install. (eg: C:\Program Files(x86)\Steam, ~/.steam/steam)
- /// 4. A path to a root Steam steamapps directory. (eg: C:\Program Files(x86)\Steam\steamapps, ~/.steam/steam/steamapps)
+ /// 4. A path to a root Steam steamapps directory. (eg: C:\Program Files(x86)\Steam\steamapps,
+ /// ~/.steam/steam/steamapps)
/// 5. A path to the root Steam libraryfolders.vdf, commonly in the root Steam steamapps directory.
/// 6. A path to the Steam library directory that contains Victoria 2.
/// 7. A path to a Steam library's steamapps directory that contains Victoria 2.
/// 8. A path to a Steam library's steamapps/common directory that contains Victoria 2.
- /// 9. If any of these checks don't resolve to a valid Victoria 2 game directory when supplied a non-empty hint_path, performs empty path behavior.
+ /// 9. If any of these checks don't resolve to a valid Victoria 2 game directory when supplied
+ /// a non-empty hint_path, performs empty path behavior.
/// @return fs::path The root directory of a valid Victoria 2 install, or an empty path.
///
static fs::path search_for_game_path(fs::path hint_path = {});
@@ -64,7 +69,9 @@ namespace OpenVic {
*/
fs::path lookup_file(fs::path const& path) const;
path_vector_t lookup_files_in_dir(fs::path const& path, fs::path const& extension) const;
- bool apply_to_files_in_dir(fs::path const& path, fs::path const& extension, NodeTools::callback_t<fs::path const&> callback) const;
+ bool apply_to_files_in_dir(
+ fs::path const& path, fs::path const& extension, NodeTools::callback_t<fs::path const&> callback
+ ) const;
bool load_defines(GameManager& game_manager) const;
bool load_pop_history(GameManager& game_manager, fs::path const& path) const;
@@ -85,13 +92,15 @@ 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>;
- bool load_localisation_files(localisation_callback_t callback, fs::path const& localisation_dir = "localisation") const;
+ bool load_localisation_files(
+ localisation_callback_t callback, fs::path const& localisation_dir = "localisation"
+ ) const;
private:
struct fshash {
diff --git a/src/openvic-simulation/dataloader/Dataloader_Windows.hpp b/src/openvic-simulation/dataloader/Dataloader_Windows.hpp
index f4abbb6..37991b6 100644
--- a/src/openvic-simulation/dataloader/Dataloader_Windows.hpp
+++ b/src/openvic-simulation/dataloader/Dataloader_Windows.hpp
@@ -11,7 +11,9 @@
namespace OpenVic::Windows {
inline std::wstring convert(std::string_view as) {
// deal with trivial case of empty string
- if (as.empty()) return std::wstring();
+ if (as.empty()) {
+ return std::wstring();
+ }
// determine required length of new string
size_t length = ::MultiByteToWideChar(CP_UTF8, 0, as.data(), (int)as.length(), 0, 0);
@@ -28,7 +30,9 @@ namespace OpenVic::Windows {
inline std::string convert(std::wstring_view as) {
// deal with trivial case of empty string
- if (as.empty()) return std::string();
+ if (as.empty()) {
+ return std::string();
+ }
// determine required length of new string
size_t length = ::WideCharToMultiByte(CP_UTF8, 0, as.data(), (int)as.length(), 0, 0, NULL, NULL);
@@ -56,12 +60,12 @@ namespace OpenVic::Windows {
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);
}
@@ -80,29 +84,28 @@ namespace OpenVic::Windows {
template<either_char_type CHAR_T>
LSTATUS open_key(HKEY parent_key_handle, std::basic_string_view<CHAR_T> key_path) {
- if (is_open())
+ if (is_open()) {
close_key();
- if constexpr (std::is_same_v<CHAR_T, char>)
+ }
+ if constexpr (std::is_same_v<CHAR_T, char>) {
return RegOpenKeyExW(parent_key_handle, convert(key_path).data(), REG_NONE, KEY_READ, &_key_handle);
- else
+ } else {
return RegOpenKeyExW(parent_key_handle, key_path.data(), REG_NONE, KEY_READ, &_key_handle);
+ }
}
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) ||
- (_key_handle == HKEY_USERS);
+ 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);
}
LSTATUS close_key() {
- if (!is_open() || is_predefined())
+ if (!is_open() || is_predefined()) {
return ERROR_SUCCESS;
+ }
auto result = RegCloseKey(_key_handle);
_key_handle = nullptr;
return result;
@@ -127,12 +130,15 @@ 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');
- if (first_null != std::string::npos)
+ if (first_null != std::string::npos) {
_value.resize(first_null);
+ }
return result;
}
@@ -143,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());
@@ -159,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 92080c4..2f93bc2 100644
--- a/src/openvic-simulation/dataloader/NodeTools.cpp
+++ b/src/openvic-simulation/dataloader/NodeTools.cpp
@@ -53,54 +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) {
@@ -123,18 +120,22 @@ node_callback_t NodeTools::expect_colour(callback_t<colour_t> callback) {
return [callback](ast::NodeCPtr node) -> bool {
colour_t col = NULL_COLOUR;
uint32_t components = 0;
- bool ret = expect_list_of_length(3, expect_fixed_point([&col, &components](fixed_point_t val) -> bool {
- components++;
- col <<= 8;
- if (val < 0 || val > 255) {
- Logger::error("Invalid colour component: ", val);
- return false;
- } else {
- if (val <= 1) val *= 255;
- col |= val.to_int32_t();
- return true;
- }
- }))(node);
+ bool ret = expect_list_of_length(3, expect_fixed_point(
+ [&col, &components](fixed_point_t val) -> bool {
+ components++;
+ col <<= 8;
+ if (val < 0 || val > 255) {
+ Logger::error("Invalid colour component: ", val);
+ return false;
+ } else {
+ if (val <= 1) {
+ val *= 255;
+ }
+ col |= val.to_int32_t();
+ return true;
+ }
+ }
+ ))(node);
ret &= callback(col << 8 * (3 - components));
return ret;
};
@@ -196,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) {
@@ -230,7 +227,9 @@ node_callback_t NodeTools::expect_list_of_length(size_t length, node_callback_t
if (size != length) {
Logger::error("List length ", size, " does not match expected length ", length);
ret = false;
- if (length < size) return length;
+ if (length < size) {
+ return length;
+ }
}
return size;
},
@@ -259,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) {
@@ -289,7 +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;
@@ -336,11 +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;
};
@@ -355,7 +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 6469100..798976f 100644
--- a/src/openvic-simulation/dataloader/NodeTools.hpp
+++ b/src/openvic-simulation/dataloader/NodeTools.hpp
@@ -52,10 +52,14 @@ namespace OpenVic {
using callback_t = std::function<bool(Args...)>;
using node_callback_t = callback_t<ast::NodeCPtr>;
- constexpr bool success_callback(ast::NodeCPtr) { return true; }
+ constexpr bool success_callback(ast::NodeCPtr) {
+ return true;
+ }
using key_value_callback_t = callback_t<std::string_view, ast::NodeCPtr>;
- constexpr bool key_value_success_callback(std::string_view, ast::NodeCPtr) { return true; }
+ constexpr bool key_value_success_callback(std::string_view, ast::NodeCPtr) {
+ return true;
+ }
inline bool key_value_invalid_callback(std::string_view key, ast::NodeCPtr) {
Logger::error("Invalid dictionary key: ", key);
return false;
@@ -78,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;
});
}
@@ -89,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;
});
}
@@ -109,7 +118,9 @@ namespace OpenVic {
node_callback_t expect_assign(key_value_callback_t callback);
using length_callback_t = std::function<size_t(size_t)>;
- constexpr size_t default_length_callback(size_t size) { return size; };
+ constexpr size_t default_length_callback(size_t size) {
+ return size;
+ };
node_callback_t expect_list_and_length(length_callback_t length_callback, node_callback_t callback);
node_callback_t expect_list_of_length(size_t length, node_callback_t callback);
@@ -147,33 +158,47 @@ 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);
- constexpr bool add_key_map_entries(key_map_t& key_map) { return true; }
+ constexpr bool add_key_map_entries(key_map_t& key_map) {
+ 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...);
}
@@ -189,7 +214,9 @@ 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>
@@ -266,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;
@@ -277,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++;