diff options
author | Hop311 <hop3114@gmail.com> | 2023-09-08 01:34:47 +0200 |
---|---|---|
committer | Hop311 <hop3114@gmail.com> | 2023-09-08 01:34:47 +0200 |
commit | 7f9a9a8241ba81be9213e6606b8be4a48f1cbaab (patch) | |
tree | 26b67f150ec1b43593343344eabdc7deca47d0d8 /src/openvic/dataloader | |
parent | 3cd1d62ec00690a1b29070dd4903754e8f089a21 (diff) |
Remove return_t, use & instead of if(x != SUCCESS)
Diffstat (limited to 'src/openvic/dataloader')
-rw-r--r-- | src/openvic/dataloader/Dataloader.cpp | 89 | ||||
-rw-r--r-- | src/openvic/dataloader/Dataloader.hpp | 16 | ||||
-rw-r--r-- | src/openvic/dataloader/NodeTools.cpp | 115 | ||||
-rw-r--r-- | src/openvic/dataloader/NodeTools.hpp | 47 |
4 files changed, 130 insertions, 137 deletions
diff --git a/src/openvic/dataloader/Dataloader.cpp b/src/openvic/dataloader/Dataloader.cpp index 685d987..55994d3 100644 --- a/src/openvic/dataloader/Dataloader.cpp +++ b/src/openvic/dataloader/Dataloader.cpp @@ -11,12 +11,12 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; using namespace ovdl; -return_t Dataloader::set_roots(std::vector<std::filesystem::path> new_roots) { +bool Dataloader::set_roots(std::vector<std::filesystem::path> new_roots) { if (!roots.empty()) { Logger::error("Overriding existing dataloader roots!"); roots.clear(); } - return_t ret = SUCCESS; + bool ret = true; for (std::reverse_iterator<std::vector<std::filesystem::path>::const_iterator> it = new_roots.crbegin(); it != new_roots.crend(); ++it) { if (std::find(roots.begin(), roots.end(), *it) == roots.end()) { if (std::filesystem::is_directory(*it)) { @@ -24,16 +24,16 @@ return_t Dataloader::set_roots(std::vector<std::filesystem::path> new_roots) { roots.push_back(*it); } else { Logger::error("Invalid dataloader root (must be an existing directory): ", *it); - ret = FAILURE; + ret = false; } } else { Logger::error("Duplicate dataloader root: ", *it); - ret = FAILURE; + ret = false; } } if (roots.empty()) { Logger::error("Dataloader has no roots after attempting to add ", new_roots.size()); - ret = FAILURE; + ret = false; } return ret; } @@ -81,15 +81,13 @@ std::vector<std::filesystem::path> Dataloader::lookup_files_in_dir(std::filesyst return ret; } -return_t Dataloader::apply_to_files_in_dir(std::filesystem::path const& path, - std::function<return_t(std::filesystem::path const&)> callback, +bool Dataloader::apply_to_files_in_dir(std::filesystem::path const& path, + std::function<bool(std::filesystem::path const&)> callback, std::filesystem::path const* extension) const { - return_t ret = SUCCESS; + bool ret = true; for (std::filesystem::path const& file : lookup_files_in_dir(path, extension)) { - if (callback(file) != SUCCESS) { - ret = FAILURE; - } + ret &= callback(file); } return ret; } @@ -140,21 +138,20 @@ static csv::Windows1252Parser _parse_csv(std::filesystem::path const& path) { return _run_ovdl_parser<csv::Windows1252Parser, &csv::Windows1252Parser::parse_csv>(path); } -return_t Dataloader::_load_pop_types(PopManager& pop_manager, std::filesystem::path const& pop_type_directory) const { - return_t ret = SUCCESS; - if (apply_to_files_in_dir(pop_type_directory, - [&pop_manager](std::filesystem::path const& file) -> return_t { +bool Dataloader::_load_pop_types(PopManager& pop_manager, std::filesystem::path const& pop_type_directory) const { + const bool ret = apply_to_files_in_dir(pop_type_directory, + [&pop_manager](std::filesystem::path const& file) -> bool { return pop_manager.load_pop_type_file(file, _parse_defines(file).get_file_node()); } - ) != SUCCESS) { + ); + if (!ret) { Logger::error("Failed to load pop types!"); - ret = FAILURE; } pop_manager.lock_pop_types(); return ret; } -return_t Dataloader::_load_map_dir(Map& map, std::filesystem::path const& map_directory) const { +bool Dataloader::_load_map_dir(Map& map, std::filesystem::path const& map_directory) const { static const std::filesystem::path defaults_filename = "default.map"; static const std::string default_definitions = "definition.csv"; static const std::string default_provinces = "provinces.bmp"; @@ -182,24 +179,24 @@ return_t Dataloader::_load_map_dir(Map& map, std::filesystem::path const& map_di APPLY_TO_MAP_PATHS(MAP_PATH_VAR) #undef MAP_PATH_VAR - return_t ret = expect_dictionary_keys( + bool ret = expect_dictionary_keys( "max_provinces", ONE_EXACTLY, expect_uint( - [&map](uint64_t val) -> return_t { + [&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 FAILURE; + return false; } ), "sea_starts", ONE_EXACTLY, expect_list_reserve_length( water_province_identifiers, expect_identifier( - [&water_province_identifiers](std::string_view identifier) -> return_t { + [&water_province_identifiers](std::string_view identifier) -> bool { water_province_identifiers.push_back(identifier); - return SUCCESS; + return true; } ) ), @@ -217,25 +214,25 @@ return_t Dataloader::_load_map_dir(Map& map, std::filesystem::path const& map_di "border_cutoff", ZERO_OR_ONE, success_callback )(parser.get_file_node()); - if (ret != SUCCESS) { + if (!ret) { Logger::error("Failed to load map default file!"); } - if (map.load_province_definitions(_parse_csv(lookup_file(map_directory / definitions)).get_lines()) != SUCCESS) { + if (!map.load_province_definitions(_parse_csv(lookup_file(map_directory / definitions)).get_lines())) { Logger::error("Failed to load province definitions file!"); - ret = FAILURE; + ret = false; } - if (map.set_water_province_list(water_province_identifiers) != SUCCESS) { + if (!map.set_water_province_list(water_province_identifiers)) { Logger::error("Failed to set water provinces!"); - ret = FAILURE; + ret = false; } map.lock_water_provinces(); return ret; } -return_t Dataloader::load_defines(GameManager& game_manager) const { +bool Dataloader::load_defines(GameManager& game_manager) const { static const std::filesystem::path good_file = "common/goods.txt"; static const std::filesystem::path pop_type_directory = "poptypes"; static const std::filesystem::path graphical_culture_type_file = "common/graphicalculturetype.txt"; @@ -243,45 +240,45 @@ return_t Dataloader::load_defines(GameManager& game_manager) const { static const std::filesystem::path religion_file = "common/religion.txt"; static const std::filesystem::path map_directory = "map"; - return_t ret = SUCCESS; + bool ret = true; - if (game_manager.good_manager.load_good_file(_parse_defines(lookup_file(good_file)).get_file_node()) != SUCCESS) { + if (!game_manager.good_manager.load_good_file(_parse_defines(lookup_file(good_file)).get_file_node())) { Logger::error("Failed to load goods!"); - ret = FAILURE; + ret = false; } - if (_load_pop_types(game_manager.pop_manager, pop_type_directory) != SUCCESS) { + if (!_load_pop_types(game_manager.pop_manager, pop_type_directory)) { Logger::error("Failed to load pop types!"); - ret = FAILURE; + ret = false; } - if (game_manager.pop_manager.culture_manager.load_graphical_culture_type_file(_parse_defines(lookup_file(graphical_culture_type_file)).get_file_node()) != SUCCESS) { + if (!game_manager.pop_manager.culture_manager.load_graphical_culture_type_file(_parse_defines(lookup_file(graphical_culture_type_file)).get_file_node())) { Logger::error("Failed to load graphical culture types!"); - ret = FAILURE; + ret = false; } - if (game_manager.pop_manager.culture_manager.load_culture_file(_parse_defines(lookup_file(culture_file)).get_file_node()) != SUCCESS) { + if (!game_manager.pop_manager.culture_manager.load_culture_file(_parse_defines(lookup_file(culture_file)).get_file_node())) { Logger::error("Failed to load cultures!"); - ret = FAILURE; + ret = false; } - if (game_manager.pop_manager.religion_manager.load_religion_file(_parse_defines(lookup_file(religion_file)).get_file_node()) != SUCCESS) { + if (!game_manager.pop_manager.religion_manager.load_religion_file(_parse_defines(lookup_file(religion_file)).get_file_node())) { Logger::error("Failed to load religions!"); - ret = FAILURE; + ret = false; } - if (_load_map_dir(game_manager.map, map_directory) != SUCCESS) { + if (!_load_map_dir(game_manager.map, map_directory)) { Logger::error("Failed to load map!"); - ret = FAILURE; + ret = false; } return ret; } -return_t Dataloader::load_pop_history(GameManager& game_manager, std::filesystem::path const& path) const { +bool Dataloader::load_pop_history(GameManager& game_manager, std::filesystem::path const& path) const { return apply_to_files_in_dir(path, - [&game_manager](std::filesystem::path const& file) -> return_t { + [&game_manager](std::filesystem::path const& file) -> bool { return expect_dictionary( - [&game_manager](std::string_view province_key, ast::NodeCPtr province_node) -> return_t { + [&game_manager](std::string_view province_key, ast::NodeCPtr province_node) -> bool { Province* province = game_manager.map.get_province_by_identifier(province_key); if (province == nullptr) { Logger::error("Invalid province id: ", province_key); - return FAILURE; + return false; } return province->load_pop_list(game_manager.pop_manager, province_node); } diff --git a/src/openvic/dataloader/Dataloader.hpp b/src/openvic/dataloader/Dataloader.hpp index 9e5c24b..f723803 100644 --- a/src/openvic/dataloader/Dataloader.hpp +++ b/src/openvic/dataloader/Dataloader.hpp @@ -4,8 +4,6 @@ #include <functional> #include <vector> -#include "openvic/types/Return.hpp" - namespace OpenVic { struct GameManager; struct PopManager; @@ -14,24 +12,24 @@ namespace OpenVic { class Dataloader { std::vector<std::filesystem::path> roots; - return_t _load_pop_types(PopManager& pop_manager, std::filesystem::path const& pop_type_directory) const; - return_t _load_map_dir(Map& map, std::filesystem::path const& map_directory) const; + bool _load_pop_types(PopManager& pop_manager, std::filesystem::path const& pop_type_directory) const; + bool _load_map_dir(Map& map, std::filesystem::path const& map_directory) const; public: Dataloader() = default; /* In reverse-load order, so base defines first and final loaded mod last */ - return_t set_roots(std::vector<std::filesystem::path> new_roots); + bool set_roots(std::vector<std::filesystem::path> new_roots); std::filesystem::path lookup_file(std::filesystem::path const& path) const; static const std::filesystem::path TXT; std::vector<std::filesystem::path> lookup_files_in_dir(std::filesystem::path const& path, std::filesystem::path const* extension = &TXT) const; - return_t apply_to_files_in_dir(std::filesystem::path const& path, - std::function<return_t(std::filesystem::path const&)> callback, + bool apply_to_files_in_dir(std::filesystem::path const& path, + std::function<bool(std::filesystem::path const&)> callback, std::filesystem::path const* extension = &TXT) const; - return_t load_defines(GameManager& game_manager) const; - return_t load_pop_history(GameManager& game_manager, std::filesystem::path const& path) const; + bool load_defines(GameManager& game_manager) const; + bool load_pop_history(GameManager& game_manager, std::filesystem::path const& path) const; }; } diff --git a/src/openvic/dataloader/NodeTools.cpp b/src/openvic/dataloader/NodeTools.cpp index 6e5f7d0..499527f 100644 --- a/src/openvic/dataloader/NodeTools.cpp +++ b/src/openvic/dataloader/NodeTools.cpp @@ -6,8 +6,8 @@ using namespace OpenVic; using namespace OpenVic::NodeTools; template<typename T> -static node_callback_t _expect_type(std::function<return_t(T const&)> callback) { - return [callback](ast::NodeCPtr node) -> return_t { +static node_callback_t _expect_type(std::function<bool(T const&)> callback) { + return [callback](ast::NodeCPtr node) -> bool { if (node != nullptr) { T const* cast_node = node->cast_to<T>(); if (cast_node != nullptr) { @@ -17,28 +17,28 @@ static node_callback_t _expect_type(std::function<return_t(T const&)> callback) } else { Logger::error("Null node when expecting ", T::get_type_static()); } - return FAILURE; + return false; }; } template<typename T = ast::AbstractStringNode> requires(std::derived_from<T, ast::AbstractStringNode>) -static std::function<return_t(T const&)> abstract_string_node_callback(std::function<return_t(std::string_view)> callback) { - return [callback](T const& node) -> return_t { +static std::function<bool(T const&)> abstract_string_node_callback(std::function<bool(std::string_view)> callback) { + return [callback](T const& node) -> bool { return callback(node._name); }; } -node_callback_t NodeTools::expect_identifier(std::function<return_t(std::string_view)> callback) { +node_callback_t NodeTools::expect_identifier(std::function<bool(std::string_view)> callback) { return _expect_type<ast::IdentifierNode>(abstract_string_node_callback<ast::IdentifierNode>(callback)); } -node_callback_t NodeTools::expect_string(std::function<return_t(std::string_view)> callback) { +node_callback_t NodeTools::expect_string(std::function<bool(std::string_view)> callback) { return _expect_type<ast::StringNode>(abstract_string_node_callback<ast::StringNode>(callback)); } -node_callback_t NodeTools::expect_identifier_or_string(std::function<return_t(std::string_view)> callback) { - return [callback](ast::NodeCPtr node) -> return_t { +node_callback_t NodeTools::expect_identifier_or_string(std::function<bool(std::string_view)> callback) { + return [callback](ast::NodeCPtr node) -> bool { if (node != nullptr) { ast::AbstractStringNode const* cast_node = node->cast_to<ast::IdentifierNode>(); if (cast_node == nullptr) { @@ -51,109 +51,108 @@ node_callback_t NodeTools::expect_identifier_or_string(std::function<return_t(st } else { Logger::error("Null node when expecting ", ast::IdentifierNode::get_type_static(), " or ", ast::StringNode::get_type_static()); } - return FAILURE; + return false; }; } -node_callback_t NodeTools::expect_bool(std::function<return_t(bool)> callback) { +node_callback_t NodeTools::expect_bool(std::function<bool(bool)> callback) { return expect_identifier( - [callback](std::string_view identifier) -> return_t { + [callback](std::string_view identifier) -> bool { if (identifier == "yes") { return callback(true); } else if (identifier == "no") { return callback(false); } Logger::error("Invalid bool identifier text: ", identifier); - return FAILURE; + return false; } ); } -node_callback_t NodeTools::expect_int(std::function<return_t(int64_t)> callback) { +node_callback_t NodeTools::expect_int(std::function<bool(int64_t)> callback) { return expect_identifier( - [callback](std::string_view identifier) -> return_t { + [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 FAILURE; + return false; } ); } -node_callback_t NodeTools::expect_uint(std::function<return_t(uint64_t)> callback) { +node_callback_t NodeTools::expect_uint(std::function<bool(uint64_t)> callback) { return expect_identifier( - [callback](std::string_view identifier) -> return_t { + [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 FAILURE; + return false; } ); } -node_callback_t NodeTools::expect_fixed_point(std::function<return_t(FP)> callback) { +node_callback_t NodeTools::expect_fixed_point(std::function<bool(FP)> callback) { return expect_identifier( - [callback](std::string_view identifier) -> return_t { + [callback](std::string_view identifier) -> bool { bool successful = false; const FP val = FP::parse(identifier.data(), identifier.length(), &successful); if (successful) { return callback(val); } Logger::error("Invalid fixed point identifier text: ", identifier); - return FAILURE; + return false; } ); } -node_callback_t NodeTools::expect_colour(std::function<return_t(colour_t)> callback) { - return [callback](ast::NodeCPtr node) -> return_t { +node_callback_t NodeTools::expect_colour(std::function<bool(colour_t)> callback) { + return [callback](ast::NodeCPtr node) -> bool { colour_t col = NULL_COLOUR; uint32_t components = 0; - return_t ret = expect_list_of_length(3, + bool ret = expect_list_of_length(3, expect_fixed_point( - [&col, &components](FP val) -> return_t { - return_t ret = SUCCESS; + [&col, &components](FP val) -> bool { + components++; + col <<= 8; if (val < 0 || val > 255) { Logger::error("Invalid colour component: ", val); - val = FP::_0(); - ret = FAILURE; + return false; + } else { + if (val <= 1) val *= 255; + col |= val.to_int32_t(); + return true; } - if (val <= 1) val *= 255; - col = (col << 8) | val.to_int32_t(); - components++; - return ret; } ) )(node); - if (components < 3) col <<= 8 * (3 - components); - if (callback(col) != SUCCESS) ret = FAILURE; + ret &= callback(col << 8 * (3 - components)); return ret; }; } -node_callback_t NodeTools::expect_date(std::function<return_t(Date)> callback) { +node_callback_t NodeTools::expect_date(std::function<bool(Date)> callback) { return expect_identifier( - [callback](std::string_view identifier) -> return_t { + [callback](std::string_view identifier) -> bool { bool successful = false; const Date date = Date::from_string(identifier, &successful); if (successful) { return callback(date); } Logger::error("Invalid date identifier text: ", identifier); - return FAILURE; + return false; } ); } node_callback_t NodeTools::expect_assign(key_value_callback_t callback) { return _expect_type<ast::AssignNode>( - [callback](ast::AssignNode const& assign_node) -> return_t { + [callback](ast::AssignNode const& assign_node) -> bool { return callback(assign_node._name, assign_node._initializer.get()); } ); @@ -161,18 +160,18 @@ node_callback_t NodeTools::expect_assign(key_value_callback_t callback) { 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) -> return_t { + [length_callback, callback](ast::AbstractListNode const& list_node) -> bool { std::vector<ast::NodeUPtr> const& list = list_node._statements; - return_t ret = SUCCESS; + 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 = FAILURE; + ret = false; } std::for_each(list.begin(), list.begin() + size, [callback, &ret](ast::NodeUPtr const& sub_node) -> void { - if (callback(sub_node.get()) != SUCCESS) ret = FAILURE; + ret &= callback(sub_node.get()); } ); return ret; @@ -181,19 +180,19 @@ node_callback_t NodeTools::expect_list_and_length(length_callback_t length_callb } node_callback_t NodeTools::expect_list_of_length(size_t length, node_callback_t callback) { - return [length, callback](ast::NodeCPtr node) -> return_t { - return_t ret = SUCCESS; - if (expect_list_and_length( + return [length, callback](ast::NodeCPtr node) -> bool { + bool ret = true; + ret &= expect_list_and_length( [length, &ret](size_t size) -> size_t { if (size != length) { Logger::error("List length ", size, " does not match expected length ", length); - ret = FAILURE; + ret = false; if (length < size) return length; } return size; }, callback - )(node) != SUCCESS) ret = FAILURE; + )(node); return ret; }; } @@ -211,20 +210,20 @@ node_callback_t NodeTools::expect_dictionary(key_value_callback_t callback) { } node_callback_t NodeTools::_expect_dictionary_keys_and_length(length_callback_t length_callback, bool allow_other_keys, key_map_t&& key_map) { - return [length_callback, allow_other_keys, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> return_t { - return_t ret = expect_dictionary_and_length( + return [length_callback, allow_other_keys, key_map = std::move(key_map)](ast::NodeCPtr node) mutable -> bool { + bool ret = expect_dictionary_and_length( length_callback, - [&key_map, allow_other_keys](std::string_view key, ast::NodeCPtr value) -> return_t { + [&key_map, allow_other_keys](std::string_view key, ast::NodeCPtr value) -> bool { const key_map_t::iterator it = key_map.find(key); if (it == key_map.end()) { - if (allow_other_keys) return SUCCESS; + if (allow_other_keys) return true; Logger::error("Invalid dictionary key: ", key); - return FAILURE; + return false; } dictionary_entry_t& entry = it->second; if (++entry.count > 1 && !entry.can_repeat()) { Logger::error("Invalid repeat of dictionary key: ", key); - return FAILURE; + return false; } return entry.callback(value); } @@ -233,7 +232,7 @@ node_callback_t NodeTools::_expect_dictionary_keys_and_length(length_callback_t dictionary_entry_t const& entry = key_entry.second; if (entry.must_appear() && entry.count < 1) { Logger::error("Mandatory dictionary key not present: ", key_entry.first); - ret = FAILURE; + ret = false; } } return ret; @@ -244,13 +243,13 @@ node_callback_t NodeTools::name_list_callback(std::vector<std::string>& list) { return expect_list_reserve_length( list, expect_identifier_or_string( - [&list](std::string_view str) -> return_t { + [&list](std::string_view str) -> bool { if (!str.empty()) { list.push_back(std::string { str }); - return SUCCESS; + return true; } Logger::error("Empty identifier or string"); - return FAILURE; + return false; } ) ); diff --git a/src/openvic/dataloader/NodeTools.hpp b/src/openvic/dataloader/NodeTools.hpp index 6dbaa1c..daea8ce 100644 --- a/src/openvic/dataloader/NodeTools.hpp +++ b/src/openvic/dataloader/NodeTools.hpp @@ -4,7 +4,6 @@ #include "openvic/types/Colour.hpp" #include "openvic/types/Date.hpp" -#include "openvic/types/Return.hpp" #include "openvic/types/fixed_point/FP.hpp" #include <openvic-dataloader/v2script/AbstractSyntaxTree.hpp> @@ -14,20 +13,20 @@ namespace OpenVic { namespace NodeTools { - using node_callback_t = std::function<return_t(ast::NodeCPtr)>; - constexpr return_t success_callback(ast::NodeCPtr) { return SUCCESS; } + using node_callback_t = std::function<bool(ast::NodeCPtr)>; + constexpr bool success_callback(ast::NodeCPtr) { return true; } - using key_value_callback_t = std::function<return_t(std::string_view, ast::NodeCPtr)>; + using key_value_callback_t = std::function<bool(std::string_view, ast::NodeCPtr)>; - node_callback_t expect_identifier(std::function<return_t(std::string_view)> callback); - node_callback_t expect_string(std::function<return_t(std::string_view)> callback); - node_callback_t expect_identifier_or_string(std::function<return_t(std::string_view)> callback); - node_callback_t expect_bool(std::function<return_t(bool)> callback); - node_callback_t expect_int(std::function<return_t(int64_t)> callback); - node_callback_t expect_uint(std::function<return_t(uint64_t)> callback); - node_callback_t expect_fixed_point(std::function<return_t(FP)> callback); - node_callback_t expect_colour(std::function<return_t(colour_t)> callback); - node_callback_t expect_date(std::function<return_t(Date)> callback); + node_callback_t expect_identifier(std::function<bool(std::string_view)> callback); + node_callback_t expect_string(std::function<bool(std::string_view)> callback); + node_callback_t expect_identifier_or_string(std::function<bool(std::string_view)> callback); + node_callback_t expect_bool(std::function<bool(bool)> callback); + node_callback_t expect_int(std::function<bool(int64_t)> callback); + node_callback_t expect_uint(std::function<bool(uint64_t)> callback); + node_callback_t expect_fixed_point(std::function<bool(FP)> callback); + node_callback_t expect_colour(std::function<bool(colour_t)> callback); + node_callback_t expect_date(std::function<bool(Date)> callback); node_callback_t expect_assign(key_value_callback_t callback); using length_callback_t = std::function<size_t(size_t)>; @@ -124,38 +123,38 @@ namespace OpenVic { node_callback_t name_list_callback(std::vector<std::string>& list); template<typename T> - std::function<return_t(T)> assign_variable_callback(T& var) { - return [&var](T val) -> return_t { + std::function<bool(T)> assign_variable_callback(T& var) { + return [&var](T val) -> bool { var = val; - return SUCCESS; + return true; }; } template<typename T> requires(std::integral<T>) - std::function<return_t(uint64_t)> assign_variable_callback_uint(const std::string_view name, T& var) { - return [&var, name](uint64_t val) -> return_t { + std::function<bool(uint64_t)> assign_variable_callback_uint(const std::string_view name, T& var) { + return [&var, name](uint64_t val) -> bool { if (val <= std::numeric_limits<T>::max()) { var = val; - return SUCCESS; + return true; } Logger::error("Invalid ", name, ": ", val, " (valid range: [0, ", static_cast<uint64_t>(std::numeric_limits<T>::max()), "])"); - return FAILURE; + return false; }; } template<typename T> requires(std::integral<T>) - std::function<return_t(int64_t)> assign_variable_callback_int(const std::string_view name, T& var) { - return [&var, name](int64_t val) -> return_t { + std::function<bool(int64_t)> assign_variable_callback_int(const std::string_view name, T& var) { + return [&var, name](int64_t val) -> bool { if (std::numeric_limits<T>::lowest() <= val && val <= std::numeric_limits<T>::max()) { var = val; - return SUCCESS; + return true; } Logger::error("Invalid ", name, ": ", val, " (valid range: [", static_cast<int64_t>(std::numeric_limits<T>::lowest()), ", ", static_cast<uint64_t>(std::numeric_limits<T>::max()), "])"); - return FAILURE; + return false; }; } } |