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/NodeTools.hpp | |
parent | 3cd1d62ec00690a1b29070dd4903754e8f089a21 (diff) |
Remove return_t, use & instead of if(x != SUCCESS)
Diffstat (limited to 'src/openvic/dataloader/NodeTools.hpp')
-rw-r--r-- | src/openvic/dataloader/NodeTools.hpp | 47 |
1 files changed, 23 insertions, 24 deletions
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; }; } } |