18 template<
typename T,
typename Underlying = UInt32>
class StructEnum {
25 return static_cast<const T*
>(
this)->raw;
33 friend std::ostream&
operator<<(std::ostream& stream,
const T&
object) {
return stream <<
object.toString(); }
47 concept CStructEnum = std::is_base_of_v<StructEnum<T, typename T::UnderlyingType>,
T>;
49#define CE_STRUCT_ENUM_DECL(T) \
50 using RawType = decltype(raw); \
51 constexpr T() = default; \
52 CE_EXPLICIT(false) constexpr T(RawType raw) : raw(raw) {} \
53 explicit constexpr T(UnderlyingType raw) : T(RawType(raw)) {} \
57 [[nodiscard]] StringView toString() const noexcept; \
60 [[nodiscard]] static Optional<T> fromString(StringView string) noexcept;
62#define CE_STRUCT_ENUM_FOREACH(T, F) CE_STRUCT_ENUM_FOREACH_##T(F)
64#define CE_STRUCT_ENUM_TO_STRING_IMPL(T) \
67#define CE_STRUCT_ENUM_TO_STRING(T, M) \
68 StringView T::toString() const noexcept { \
69 switch(raw) { CE_STRUCT_ENUM_FOREACH(M, CE_STRUCT_ENUM_TO_STRING_IMPL) } \
73#define CE_STRUCT_ENUM_FROM_STRING_IMPL(T) \
76#define CE_STRUCT_ENUM_FROM_STRING(T, M) \
77 Optional<T> T::fromString(StringView string) noexcept { \
78 CE_STRUCT_ENUM_FOREACH(M, CE_STRUCT_ENUM_FROM_STRING_IMPL); \
82#define CE_STRUCT_ENUM_DEF(T) \
83 CE_STRUCT_ENUM_TO_STRING(T, T) \
84 CE_STRUCT_ENUM_FROM_STRING(T, T)
86#define CE_STRUCT_ENUM_DEF2(T, M) \
87 CE_STRUCT_ENUM_TO_STRING(T, M) \
88 CE_STRUCT_ENUM_FROM_STRING(T, M)
Definition StructEnum.hpp:18
static Self fromRawUnderlying(UnderlyingType underlying) noexcept
Creates a new Self from it's underlying numeric representation.
Definition StructEnum.hpp:36
Underlying UnderlyingType
Definition StructEnum.hpp:20
friend std::ostream & operator<<(std::ostream &stream, const T &object)
Definition StructEnum.hpp:33
void toString(std::ostream &stream) const noexcept
Writes a string representation of the ShaderType to the given stream.
Definition StructEnum.hpp:30
friend bool operator==(const T &lhs, const T &rhs) noexcept
Checks if the two values are equal.
Definition StructEnum.hpp:40
friend bool operator!=(const T &lhs, const T &rhs) noexcept
Checks if the two values are not equal.
Definition StructEnum.hpp:43
T Self
Definition StructEnum.hpp:21
Definition StructEnum.hpp:47
Definition Application.hpp:19
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25