aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/types
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/types')
-rw-r--r--src/openvic-simulation/types/Colour.hpp33
-rw-r--r--src/openvic-simulation/types/FunctionRef.hpp17
-rw-r--r--src/openvic-simulation/types/IdentifierRegistry.hpp10
3 files changed, 34 insertions, 26 deletions
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<typename _ColourTraits>
- requires(_ColourTraits::has_alpha && std::same_as<typename _ColourTraits::value_type, value_type> && std::same_as<typename _ColourTraits::integer_type, integer_type>)
+ requires(
+ _ColourTraits::has_alpha && std::same_as<typename _ColourTraits::value_type, value_type> &&
+ std::same_as<typename _ColourTraits::integer_type, integer_type>
+ )
explicit constexpr basic_colour_t(basic_colour_t<value_type, integer_type, _ColourTraits> const& colour)
requires(colour_traits::has_alpha)
: basic_colour_t { colour.red, colour.green, colour.blue, colour.alpha } {}
template<typename _ColourTraits>
- requires(!_ColourTraits::has_alpha && std::same_as<typename _ColourTraits::value_type, value_type> && std::same_as<typename _ColourTraits::integer_type, integer_type>)
+ requires(
+ !_ColourTraits::has_alpha && std::same_as<typename _ColourTraits::value_type, value_type> &&
+ std::same_as<typename _ColourTraits::integer_type, integer_type>
+ )
explicit constexpr basic_colour_t(
basic_colour_t<value_type, integer_type, _ColourTraits> const& colour, value_type a = max_value
)
@@ -206,7 +218,10 @@ namespace OpenVic {
: basic_colour_t { colour.red, colour.green, colour.blue, a } {}
template<typename _ColourTraits>
- requires(std::same_as<typename _ColourTraits::value_type, value_type> && std::same_as<typename _ColourTraits::integer_type, integer_type>)
+ requires(
+ std::same_as<typename _ColourTraits::value_type, value_type> &&
+ std::same_as<typename _ColourTraits::integer_type, integer_type>
+ )
explicit constexpr basic_colour_t(basic_colour_t<value_type, integer_type, _ColourTraits> 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<bool bNoExcept2, typename Func, typename Ret2, typename... Args2>
struct make_type_erased_function_ptr final {
type_erased_function_ptr<bNoExcept2, Ret2, Args2...> 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<Func>(), std::forward<Args2>(args)...
); // MAYTHROW unless bNoExcept
@@ -51,8 +51,8 @@ namespace OpenVic {
template<bool bNoExcept2, typename Func, typename... Args2>
struct make_type_erased_function_ptr<bNoExcept2, Func, void, Args2...> final {
type_erased_function_ptr<bNoExcept2, void, Args2...> 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<Func>(), std::forward<Args2>(args)...); // MAYTHROW unless bNoExcept
};
}
@@ -69,7 +69,6 @@ namespace OpenVic {
return m_pfuncTypeErased(m_anyref, std::forward<Args>(args)...); // MAYTHROW unless bNoExcept
}
-
template<typename Derived, typename Base>
struct decayed_derived_from : std::bool_constant<std::derived_from<typename std::decay<Derived>::type, Base>> {
static_assert(std::same_as<std::decay_t<Base>, Base>);
@@ -77,10 +76,10 @@ namespace OpenVic {
template<typename Func>
requires(!decayed_derived_from<Func, FunctionRefBase>::value) &&
- std::invocable<std::remove_reference_t<Func>&, Args...> &&
- (std::convertible_to<
- decltype(std::invoke(std::declval<std::remove_reference_t<Func>&>(), std::declval<Args>()...)), Ret> ||
- std::is_void<Ret>::value)
+ std::invocable<std::remove_reference_t<Func>&, Args...> &&
+ (std::convertible_to<
+ decltype(std::invoke(std::declval<std::remove_reference_t<Func>&>(), std::declval<Args>()...)), Ret
+ > || std::is_void<Ret>::value)
FunctionRefBase(Func&& func) noexcept
: m_pfuncTypeErased(make_type_erased_function_ptr<bNoExcept, std::remove_reference_t<Func>, 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( \