diff options
Diffstat (limited to 'src/openvic-simulation/dataloader/NodeTools.hpp')
-rw-r--r-- | src/openvic-simulation/dataloader/NodeTools.hpp | 59 |
1 files changed, 41 insertions, 18 deletions
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++; |