From e33a330129364b4bd632b2fd531a996b8c57cefb Mon Sep 17 00:00:00 2001 From: hop311 Date: Wed, 17 Jan 2024 22:24:39 +0000 Subject: Parse missing variables, Logger counting, misc cleanup --- src/openvic-simulation/types/Colour.hpp | 33 ++++++++++++++++------ src/openvic-simulation/types/FunctionRef.hpp | 17 ++++++----- .../types/IdentifierRegistry.hpp | 10 ++----- 3 files changed, 34 insertions(+), 26 deletions(-) (limited to 'src/openvic-simulation/types') diff --git a/src/openvic-simulation/types/Colour.hpp b/src/openvic-simulation/types/Colour.hpp index 38c7b1e..06a6b36 100644 --- a/src/openvic-simulation/types/Colour.hpp +++ b/src/openvic-simulation/types/Colour.hpp @@ -147,15 +147,19 @@ namespace OpenVic { static constexpr basic_colour_t from_integer(integer_type integer) { if constexpr (colour_traits::has_alpha) { - return { colour_traits::red_from_integer(integer), colour_traits::green_from_integer(integer), - colour_traits::blue_from_integer(integer), colour_traits::alpha_from_integer(integer) }; + return { + colour_traits::red_from_integer(integer), colour_traits::green_from_integer(integer), + colour_traits::blue_from_integer(integer), colour_traits::alpha_from_integer(integer) + }; } else { assert( colour_traits::alpha_from_integer(integer) == colour_traits::null || colour_traits::alpha_from_integer(integer) == max_value ); - return { colour_traits::red_from_integer(integer), colour_traits::green_from_integer(integer), - colour_traits::blue_from_integer(integer) }; + return { + colour_traits::red_from_integer(integer), colour_traits::green_from_integer(integer), + colour_traits::blue_from_integer(integer) + }; } } @@ -163,8 +167,10 @@ namespace OpenVic { from_floats(float r, float g, float b, float a = colour_traits::alpha_to_float(max_value)) requires(colour_traits::has_alpha) { - return { colour_traits::red_from_float(r), colour_traits::green_from_float(g), colour_traits::blue_from_float(b), - colour_traits::alpha_from_float(a) }; + return { + colour_traits::red_from_float(r), colour_traits::green_from_float(g), colour_traits::blue_from_float(b), + colour_traits::alpha_from_float(a) + }; } static constexpr basic_colour_t from_floats(float r, float g, float b) @@ -192,13 +198,19 @@ namespace OpenVic { : red(r), green(g), blue(b) {} template - requires(_ColourTraits::has_alpha && std::same_as && std::same_as) + requires( + _ColourTraits::has_alpha && std::same_as && + std::same_as + ) explicit constexpr basic_colour_t(basic_colour_t const& colour) requires(colour_traits::has_alpha) : basic_colour_t { colour.red, colour.green, colour.blue, colour.alpha } {} template - requires(!_ColourTraits::has_alpha && std::same_as && std::same_as) + requires( + !_ColourTraits::has_alpha && std::same_as && + std::same_as + ) explicit constexpr basic_colour_t( basic_colour_t const& colour, value_type a = max_value ) @@ -206,7 +218,10 @@ namespace OpenVic { : basic_colour_t { colour.red, colour.green, colour.blue, a } {} template - requires(std::same_as && std::same_as) + requires( + std::same_as && + std::same_as + ) explicit constexpr basic_colour_t(basic_colour_t const& colour) requires(!colour_traits::has_alpha) : basic_colour_t { colour.red, colour.green, colour.blue } {} diff --git a/src/openvic-simulation/types/FunctionRef.hpp b/src/openvic-simulation/types/FunctionRef.hpp index 1ca5bb7..88f6284 100644 --- a/src/openvic-simulation/types/FunctionRef.hpp +++ b/src/openvic-simulation/types/FunctionRef.hpp @@ -39,8 +39,8 @@ namespace OpenVic { template struct make_type_erased_function_ptr final { type_erased_function_ptr operator()() const& noexcept { - return [](AnyRef anyref, - Args2... args) noexcept(bNoExcept2) -> Ret2 { // implicit cast of stateless lambda to function pointer + // implicit cast of stateless lambda to function pointer + return [](AnyRef anyref, Args2... args) noexcept(bNoExcept2) -> Ret2 { return std::invoke( anyref.template get_ref(), std::forward(args)... ); // MAYTHROW unless bNoExcept @@ -51,8 +51,8 @@ namespace OpenVic { template struct make_type_erased_function_ptr final { type_erased_function_ptr operator()() const& noexcept { - return [](AnyRef anyref, - Args2... args) noexcept(bNoExcept2) { // implicit cast of stateless lambda to function pointer + // implicit cast of stateless lambda to function pointer + return [](AnyRef anyref, Args2... args) noexcept(bNoExcept2) { std::invoke(anyref.template get_ref(), std::forward(args)...); // MAYTHROW unless bNoExcept }; } @@ -69,7 +69,6 @@ namespace OpenVic { return m_pfuncTypeErased(m_anyref, std::forward(args)...); // MAYTHROW unless bNoExcept } - template struct decayed_derived_from : std::bool_constant::type, Base>> { static_assert(std::same_as, Base>); @@ -77,10 +76,10 @@ namespace OpenVic { template requires(!decayed_derived_from::value) && - std::invocable&, Args...> && - (std::convertible_to< - decltype(std::invoke(std::declval&>(), std::declval()...)), Ret> || - std::is_void::value) + std::invocable&, Args...> && + (std::convertible_to< + decltype(std::invoke(std::declval&>(), std::declval()...)), Ret + > || std::is_void::value) FunctionRefBase(Func&& func) noexcept : m_pfuncTypeErased(make_type_erased_function_ptr, Ret, Args...> {}()), m_anyref(as_lvalue(func)) { diff --git a/src/openvic-simulation/types/IdentifierRegistry.hpp b/src/openvic-simulation/types/IdentifierRegistry.hpp index bbaf52c..251632b 100644 --- a/src/openvic-simulation/types/IdentifierRegistry.hpp +++ b/src/openvic-simulation/types/IdentifierRegistry.hpp @@ -232,7 +232,7 @@ namespace OpenVic { } } - constexpr static NodeTools::KeyValueCallback auto key_value_invalid_callback(std::string_view name) { + static constexpr NodeTools::KeyValueCallback auto key_value_invalid_callback(std::string_view name) { return [name](std::string_view key, ast::NodeCPtr) { Logger::error("Invalid ", name, ": ", key); return false; @@ -258,13 +258,7 @@ namespace OpenVic { if (item != nullptr) { \ return callback(*item); \ } \ - if (!warn) { \ - Logger::error("Invalid ", name, ": ", identifier); \ - return false; \ - } else { \ - Logger::warning("Invalid ", name, ": ", identifier); \ - return true; \ - } \ + return NodeTools::warn_or_error(warn, "Invalid ", name, ": ", identifier); \ }; \ } \ constexpr NodeTools::NodeCallback auto expect_item_identifier( \ -- cgit v1.2.3-56-ga3b1