12#define defineEnumOperators(enumName)\
13 inline QDebug operator<<(QDebug pDbg, enumName pType)\
15 QDebugStateSaver saver(pDbg);\
16 return pDbg.noquote() << Enum<enumName>::getName(pType);\
19 inline QDebug operator<<(QDebug pDbg, const QList<enumName>& pList)\
21 QDebugStateSaver saver(pDbg);\
23 for (const auto& entry : pList)\
25 list << Enum<enumName>::getName(entry).data();\
27 return pDbg.noquote().nospace() << '(' << list.join(QByteArrayView(", ")) << ')';\
30 inline QString& operator+=(QString& pStr, enumName pType)\
32 pStr += Enum<enumName>::getName(pType);\
36 inline QString operator+(const QString& pStr, enumName pType)\
38 return pStr + Enum<enumName>::getName(pType);\
41 inline QString operator+(enumName pType, const QString& pStr)\
43 return Enum<enumName>::getName(pType) + pStr;\
46 inline bool operator==(std::underlying_type_t<enumName> pType, enumName pName)\
48 return static_cast<std::underlying_type_t<enumName>>(pName) == pType;\
50 inline bool operator!=(std::underlying_type_t<enumName> pType, enumName pName)\
52 return !(pType == pName);\
55 inline size_t qHash(enumName pKey, size_t pSeed)\
57 return ::qHash(static_cast<std::underlying_type_t<enumName>>(pKey), pSeed);\
61#define defineTypedEnumTypeProperty(enumName, enumType, enumProperty, ...)\
62 namespace Enum##enumName\
67 enum class enumName : enumType\
74 defineEnumOperators(enumName)\
77 using namespace Enum##enumName;
80#define defineTypedEnumType(enumName, enumType, ...) defineTypedEnumTypeProperty(enumName, enumType, , __VA_ARGS__)
81#define defineEnumType(enumName, ...) defineTypedEnumType(enumName, int, __VA_ARGS__)
84#define ENUM_HELPER_OP (
85#define ENUM_HELPER_CP )
86#define ENUM_HELPER_CO ,
88#define defineEnumTypeQmlExposed(enumName, ...) defineTypedEnumTypeProperty(enumName, int, Q_CLASSINFO ENUM_HELPER_OP "QML.Element" ENUM_HELPER_CO #enumName ENUM_HELPER_CP, __VA_ARGS__)
94template<
typename EnumTypeT>
class Enum
96 using EnumBaseTypeT = std::underlying_type_t<EnumTypeT>;
107 return QMetaEnum::fromType<EnumTypeT>();
117 [[nodiscard]]
static QLatin1String
getName(EnumTypeT pType)
119#if (QT_VERSION >= QT_VERSION_CHECK(6, 9, 0))
120 const auto value =
static_cast<quint64
>(pType);
122 const auto value =
static_cast<int>(pType);
125 if (Q_UNLIKELY(
name ==
nullptr))
127 qCritical().noquote().nospace() <<
"CRITICAL CONVERSION MISMATCH: UNKNOWN 0x" << QString::number(value, 16);
128 return QLatin1String();
131 return QLatin1String(
name);
141 [[nodiscard]]
static QList<EnumTypeT>
getList()
143 QList<EnumTypeT> list;
146 list.reserve(metaEnum.keyCount());
147 for (
int i = 0; i < metaEnum.keyCount(); ++i)
149 list << static_cast<EnumTypeT>(metaEnum.value(i));
156 [[nodiscard]]
static EnumTypeT
fromString(
const char*
const pValue, EnumTypeT pDefault)
162 return static_cast<EnumTypeT
>(key);
168 [[nodiscard]]
static EnumTypeT
fromString(
const QString& pValue, EnumTypeT pDefaultType)
170 return fromString(pValue.toUtf8().constData(), pDefaultType);
174#if (QT_VERSION >= QT_VERSION_CHECK(6, 9, 0))
175 [[nodiscard]]
static bool isValue(quint64 pValue)
177 [[nodiscard]]
static bool isValue(
int pValue)
184#if (QT_VERSION < QT_VERSION_CHECK(6, 9, 0))
185 [[nodiscard]]
static bool isValue(ushort pValue)
187 return isValue(
static_cast<int>(pValue));
193 [[nodiscard]]
static EnumBaseTypeT
getValue(EnumTypeT pType)
195 return static_cast<EnumBaseTypeT
>(pType);
static QLatin1String getName()
Definition EnumHelper.h:111
static QLatin1String getName(EnumTypeT pType)
Definition EnumHelper.h:117
static EnumTypeT fromString(const char *const pValue, EnumTypeT pDefault)
Definition EnumHelper.h:156
static EnumTypeT fromString(const QString &pValue, EnumTypeT pDefaultType)
Definition EnumHelper.h:168
static QList< EnumTypeT > getList()
Definition EnumHelper.h:141
static int getCount()
Definition EnumHelper.h:135
static EnumBaseTypeT getValue(EnumTypeT pType)
Definition EnumHelper.h:193
static QMetaEnum getQtEnumMetaEnum()
Definition EnumHelper.h:105
static bool isValue(quint64 pValue)
Definition EnumHelper.h:175
const char * name
Definition http_parser.cpp:473
#define T(v)
Definition http_parser.cpp:237
Defines the AccessRight and AccessRole enum.
Definition CommandApdu.h:17
QLatin1String getEnumName(T pType)
Definition EnumHelper.h:202