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>
46#define DW_ENUMERATOR_NAME_STRING_VIEW(NAME_STR) NAME_STR##_sv
61#define DW_DESCRIBE_ENUMERATOR(NAME) describeEnumerator(DW_ENUMERATOR_NAME_STRING_VIEW(#NAME), EnumT::NAME)
72#define DW_DESCRIBE_C_ENUMERATOR(NAME) describeEnumerator(DW_ENUMERATOR_NAME_STRING_VIEW(#NAME), (NAME))
81template <
typename EnumT>
84 static_assert(std::is_enum<EnumT>::value,
"EnumT must be an enumeration type");
94 static constexpr auto get()
96 static_assert(
sizeof(EnumT) == 0,
"Needs specialization for specific enum type");
97 constexpr const size_t numberOfEnumerators = 0;
98 std::array<std::pair<dw::core::StringView, EnumT>, numberOfEnumerators> ret;
117template <
typename EnumT,
typename... Args>
120 return std::array<std::pair<dw::core::StringView, EnumT>,
sizeof...(Args)>{std::forward<const Args>(args)...};
135template <
typename EnumT>
138 return std::make_pair(std::move(name), value);
148template <
typename EnumT>
152 for (
const auto& pair : pairs)
154 if (pair.first == name)
159 FixedString<4096> validNames{};
160 for (
const auto& pair : pairs)
162 validNames <<
" " << pair.first;
164 throw Exception(DW_INVALID_ARGUMENT,
"Invalid enumerator name '", name,
"' for enum type ",
typeid(EnumT).name(),
", valid names:", validNames);
174template <
typename EnumT>
178 for (
const auto& pair : pairs)
180 if (pair.second == value)
185 throw Exception(DW_INVALID_ARGUMENT,
"The enumerator value is invalid: ",
typeid(EnumT).name(),
" ", 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.