From 0526595e75320d6a4e0954d5ebfc240837eecf94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Tue, 15 Oct 2024 12:09:25 -0400 Subject: [PATCH] [ci] More enum reflection improvements --- cmake/avendish.cmake | 1 + include/avnd/binding/max/from_atoms.hpp | 10 ++++++---- include/avnd/binding/max/to_atoms.hpp | 2 +- include/avnd/binding/pd/inputs.hpp | 2 +- include/avnd/binding/pd/outputs.hpp | 2 +- include/avnd/common/enum_reflection.hpp | 9 +++++++++ include/halp/controls.enums.hpp | 14 +++++++++----- 7 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 include/avnd/common/enum_reflection.hpp diff --git a/cmake/avendish.cmake b/cmake/avendish.cmake index 43e7be7..a572939 100644 --- a/cmake/avendish.cmake +++ b/cmake/avendish.cmake @@ -67,6 +67,7 @@ set(AVENDISH_SOURCES "${AVND_SOURCE_DIR}/include/avnd/common/coroutines.hpp" "${AVND_SOURCE_DIR}/include/avnd/common/dummy.hpp" "${AVND_SOURCE_DIR}/include/avnd/common/errors.hpp" + "${AVND_SOURCE_DIR}/include/avnd/common/enum_reflection.hpp" "${AVND_SOURCE_DIR}/include/avnd/common/export.hpp" "${AVND_SOURCE_DIR}/include/avnd/common/for_nth.hpp" "${AVND_SOURCE_DIR}/include/avnd/common/function_reflection.hpp" diff --git a/include/avnd/binding/max/from_atoms.hpp b/include/avnd/binding/max/from_atoms.hpp index a239f72..8c7d16a 100644 --- a/include/avnd/binding/max/from_atoms.hpp +++ b/include/avnd/binding/max/from_atoms.hpp @@ -1,18 +1,20 @@ #pragma once -#include #include -#include #include +#include +#include +#include + #if !defined(__cpp_lib_to_chars) #include #else #include #endif -#include -#include #include +#include + namespace max { diff --git a/include/avnd/binding/max/to_atoms.hpp b/include/avnd/binding/max/to_atoms.hpp index fa610aa..f2fac22 100644 --- a/include/avnd/binding/max/to_atoms.hpp +++ b/include/avnd/binding/max/to_atoms.hpp @@ -1,11 +1,11 @@ #pragma once #include #include +#include #include #include #include #include -#include namespace max { diff --git a/include/avnd/binding/pd/inputs.hpp b/include/avnd/binding/pd/inputs.hpp index 2c7784d..2685f82 100644 --- a/include/avnd/binding/pd/inputs.hpp +++ b/include/avnd/binding/pd/inputs.hpp @@ -1,7 +1,7 @@ #pragma once #include #include -#include +#include #if !defined(__cpp_lib_to_chars) #include diff --git a/include/avnd/binding/pd/outputs.hpp b/include/avnd/binding/pd/outputs.hpp index cb422c5..de23e08 100644 --- a/include/avnd/binding/pd/outputs.hpp +++ b/include/avnd/binding/pd/outputs.hpp @@ -3,11 +3,11 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ #include +#include #include #include #include #include -#include #include #include diff --git a/include/avnd/common/enum_reflection.hpp b/include/avnd/common/enum_reflection.hpp new file mode 100644 index 0000000..8bb021b --- /dev/null +++ b/include/avnd/common/enum_reflection.hpp @@ -0,0 +1,9 @@ +#pragma once + +#if __has_include() +#include +#elif __has_include() +#include +#else +#error magic_enum is required +#endif diff --git a/include/halp/controls.enums.hpp b/include/halp/controls.enums.hpp index c129339..a3e4ab1 100644 --- a/include/halp/controls.enums.hpp +++ b/include/halp/controls.enums.hpp @@ -8,6 +8,10 @@ #include #if __has_include() #include +#elif __has_include() +#include +#else +#error magic_enum is required #endif namespace halp @@ -27,7 +31,7 @@ struct enum_t { struct enum_setup { -#if __has_include() +#if MAGIC_ENUM_SUPPORTED decltype(magic_enum::enum_names()) values = magic_enum::enum_names(); #endif Enum init{}; @@ -48,7 +52,7 @@ struct enum_t } auto& operator=(std::string_view t) noexcept { -#if __has_include() +#if MAGIC_ENUM_SUPPORTED if(auto res = magic_enum::enum_cast(t)) value = *res; #endif @@ -70,7 +74,7 @@ struct string_enum_t { struct enum_setup { -#if __has_include() +#if MAGIC_ENUM_SUPPORTED decltype(magic_enum::enum_names()) values = magic_enum::enum_names(); #endif Enum init{}; @@ -91,14 +95,14 @@ struct string_enum_t } auto& operator=(Enum t) noexcept { -#if __has_include() +#if MAGIC_ENUM_SUPPORTED value = magic_enum::enum_name(t); #endif return *this; } auto& operator=(std::integral auto t) noexcept { -#if __has_include() +#if MAGIC_ENUM_SUPPORTED value = magic_enum::enum_name(static_cast(t)); #endif return *this;