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>
43#define DW_ENUMERATOR_NAME_STRING_VIEW(NAME_STR) NAME_STR##_sv
53#define DW_DESCRIBE_ENUMERATOR(NAME) describeEnumerator(DW_ENUMERATOR_NAME_STRING_VIEW(#NAME), EnumT::NAME)
61#define DW_DESCRIBE_C_ENUMERATOR(NAME) describeEnumerator(DW_ENUMERATOR_NAME_STRING_VIEW(#NAME), (NAME))
70template <
typename EnumT>
73 static_assert(std::is_enum<EnumT>::value,
"EnumT must be an enumeration type");
84 static constexpr auto get()
86 static_assert(
sizeof(EnumT) == 0,
"Needs specialization for specific enum type");
87 constexpr const size_t numberOfEnumerators = 0;
88 std::array<std::pair<dw::core::StringView, EnumT>, numberOfEnumerators> ret;
105template <
typename EnumT,
typename... Args>
108 return std::array<std::pair<dw::core::StringView, EnumT>,
sizeof...(Args)>{std::forward<const Args>(args)...};
123template <
typename EnumT>
126 return std::make_pair(std::move(name), value);
136template <
typename EnumT>
140 for (
const auto& pair : pairs)
142 if (pair.first == name)
147 FixedString<4096> validNames{};
148 for (
const auto& pair : pairs)
150 validNames <<
" " << pair.first;
152 throw ExceptionWithStatus(DW_INVALID_ARGUMENT,
"Invalid enumerator name '", name,
"' for enum type ",
typeid(EnumT).name(),
", valid names:", validNames);
162template <
typename EnumT>
166 for (
const auto& pair : pairs)
168 if (pair.second == value)
173 throw ExceptionWithStatus(DW_INVALID_ARGUMENT,
"The enumerator value is invalid: ",
typeid(EnumT).name(),
" ",
static_cast<std::underlying_type_t<EnumT>
>(value));
dw::core::StringView mapEnumValueToName(EnumT value)
Get the enumerator name based on the value.
constexpr auto describeEnumeratorCollection(Args const &&... args)
Describe the enumerators.
constexpr auto describeEnumerator(dw::core::StringView const &&name, EnumT value)
Describe an enumerator.
auto mapEnumNameToValue(dw::core::StringView const &name) -> EnumT
Get the enumerator value based on the name.
static constexpr auto get()
Describe the enumerators.