[+] Added bool EnumIsValid(Enum e)

[*] Adjust padding
This commit is contained in:
Reece Wilson 2021-10-29 18:03:01 +01:00
parent 94117d5271
commit ce9d53f779

View File

@ -7,7 +7,6 @@
***/
#pragma once
///////////////////////////////////////////////////////////////////////////////////////////
/// Configuration
///////////////////////////////////////////////////////////////////////////////////////////
@ -36,7 +35,7 @@ using AuUInt = size_t;
#if !defined(AU_Consumer)
#define AU_Consumer
template<typename ...T>
template<typename ... T>
using AuConsumer = std::function<void(T...)>;
#endif
@ -78,12 +77,13 @@ using AuConsumer = std::function<void(T...)>;
///////////////////////////////////////////////////////////////////////////////////////////
#define AUE_DEFINE(name, vals) enum class name { AU_FOR_EACH(AUE_EMIT_ARRAY, AUE_STRIP_BRACKETS(vals)) kEnumCount }; \
static inline const AuString k ## name ## ToString[static_cast<AuUInt>(name::kEnumCount)] = {AU_FOR_EACH(AUE_EMIT_A, AUE_STRIP_BRACKETS(vals)) }; \
static inline const name k ## name ## Values[static_cast<AuUInt>(name::kEnumCount)] = {AU_FOR_EACH_THAT(AUE_EMIT_D, name, AUE_STRIP_BRACKETS(vals)) }; \
static inline const AuString k ## name ## ToString[static_cast<AuUInt>(name::kEnumCount)] = { AU_FOR_EACH(AUE_EMIT_A, AUE_STRIP_BRACKETS(vals)) }; \
static inline const name k ## name ## Values[static_cast<AuUInt>(name::kEnumCount)] = { AU_FOR_EACH_THAT(AUE_EMIT_D, name, AUE_STRIP_BRACKETS(vals)) }; \
inline const AuHashMap<AuString, name> k ## name ## FromString = { AU_FOR_EACH_THAT(AUE_EMIT_PAIRNAME, name, AUE_STRIP_BRACKETS(vals)) {"kEnumCount", name::kEnumCount} }; \
static inline name name ## FromString (const AuString &codename) { AU_FOR_EACH_THAT(AUE_EMIT_CHECK, name, AUE_STRIP_BRACKETS(vals)) return name::kEnumCount; } \
static inline name name ## FromHashString(const AuString &codename) { auto itr = k ## name ## FromString.find(codename); if (itr == k ## name ## FromString.end()) return name::kEnumCount; return itr->second; } \
static inline const AuString & name ## ToString(name val) { static const AuString invalid = "kEnumCount"; if (static_cast<AuUInt>(val) >= static_cast<AuUInt>(name::kEnumCount)) return invalid; return k ## name ## ToString[static_cast<AuUInt>(val)]; } \
static inline bool name ## IsValid(name val) { return static_cast<AuUInt>(val) < static_cast<AuUInt>(name::kEnumCount); } \
static inline void name ## ForEach(const AuConsumer<name> &consumer) { AU_FOR_EACH_THAT(AUE_EMIT_CALL, name, AUE_STRIP_BRACKETS(vals)) } \
static const AuUInt k ## name ## Count = static_cast<AuUInt>(name::kEnumCount); \
static const name k ## name ## Invalid = name::kEnumCount; \