31 #ifndef DW_FRAMEWORK_ENUMDESCRIPTOR_HPP_ 32 #define DW_FRAMEWORK_ENUMDESCRIPTOR_HPP_ 34 #include <dw/core/base/Status.h> 35 #include <dw/core/container/StringView.hpp> 41 #include <type_traits> 43 #define _DW_ENUMERATOR_NAME_STRING_VIEW(NAME_STR) NAME_STR##_sv 55 #define DW_DESCRIBE_ENUMERATOR(NAME) describeEnumerator(_DW_ENUMERATOR_NAME_STRING_VIEW(#NAME), EnumT::NAME) 63 #define DW_DESCRIBE_C_ENUMERATOR(NAME) describeEnumerator(_DW_ENUMERATOR_NAME_STRING_VIEW(#NAME), (NAME)) 72 template <
typename EnumT>
83 static constexpr
auto get()
85 static_assert(
sizeof(EnumT) == 0,
"Needs specialization for specific enum type");
86 constexpr
const size_t numberOfEnumerators = 0;
87 std::array<std::pair<dw::core::StringView, EnumT>, numberOfEnumerators> ret;
104 template <
typename EnumT,
typename... Args>
107 return std::array<std::pair<dw::core::StringView, EnumT>,
sizeof...(Args)>{std::forward<const Args>(args)...};
122 template <
typename EnumT>
125 return std::make_pair(std::move(name), value);
135 template <
typename EnumT>
139 for (
const auto& pair : pairs)
141 if (pair.first == name)
146 FixedString<4096> validNames{};
147 for (
const auto& pair : pairs)
149 validNames <<
" " << pair.first;
151 throw Exception(DW_INVALID_ARGUMENT,
"Invalid enumerator name '", name,
"' for enum type ",
typeid(EnumT).name(),
", valid names:", validNames);
161 template <
typename EnumT>
165 for (
const auto& pair : pairs)
167 if (pair.second == value)
172 throw Exception(DW_INVALID_ARGUMENT,
"The enumerator value is invalid: ",
typeid(EnumT).name(),
" ", value);
178 #endif // DW_FRAMEWORK_ENUMDESCRIPTOR_HPP_ static constexpr auto get()
Describe the enumerators.
constexpr auto describeEnumerator(dw::core::StringView const &&name, EnumT value)
Describe an enumerator.
constexpr auto describeEnumeratorCollection(Args const &&... args)
Describe the enumerators.
auto mapEnumNameToValue(dw::core::StringView const &name) -> EnumT
Get the enumerator value based on the name.
dw::core::StringView mapEnumValueToName(EnumT value)
Get the enumerator name based on the value.