16#define defineEnumOperators(enumName)\
17 inline QDebug operator<<(QDebug pDbg, enumName pType)\
19 QDebugStateSaver saver(pDbg);\
20 return pDbg.noquote() << Enum<enumName>::getName(pType);\
23 inline QDebug operator<<(QDebug pDbg, const QList<enumName>& pList)\
25 QDebugStateSaver saver(pDbg);\
27 for (const auto& entry : pList)\
29 list << Enum<enumName>::getName(entry).data();\
31 return pDbg.noquote().nospace() << '(' << list.join(QByteArrayView(", ")) << ')';\
34 inline QString& operator+=(QString& pStr, enumName pType)\
36 pStr += Enum<enumName>::getName(pType);\
40 inline QString operator+(const QString& pStr, enumName pType)\
42 return pStr + Enum<enumName>::getName(pType);\
45 inline QString operator+(enumName pType, const QString& pStr)\
47 return Enum<enumName>::getName(pType) + pStr;\
50 inline bool operator==(std::underlying_type_t<enumName> pType, enumName pName)\
52 return static_cast<std::underlying_type_t<enumName>>(pName) == pType;\
54 inline bool operator!=(std::underlying_type_t<enumName> pType, enumName pName)\
56 return !(pType == pName);\
59 inline size_t qHash(enumName pKey, size_t pSeed)\
61 return ::qHash(static_cast<std::underlying_type_t<enumName>>(pKey), pSeed);\
65#define defineTypedEnumTypeProperty(enumName, enumType, enumProperty, ...)\
66 namespace Enum##enumName\
71 enum class enumName : enumType\
78 defineEnumOperators(enumName)\
81 using namespace Enum##enumName;
84#define defineTypedEnumType(enumName, enumType, ...) defineTypedEnumTypeProperty(enumName, enumType, , __VA_ARGS__)
85#define defineEnumType(enumName, ...) defineTypedEnumType(enumName, int, __VA_ARGS__)
88#define ENUM_HELPER_OP (
89#define ENUM_HELPER_CP )
90#define ENUM_HELPER_CO ,
92#define defineEnumTypeQmlExposed(enumName, ...) defineTypedEnumTypeProperty(enumName, int, Q_CLASSINFO ENUM_HELPER_OP "QML.Element" ENUM_HELPER_CO #enumName ENUM_HELPER_CP, __VA_ARGS__)
98template<
typename EnumTypeT>
class Enum
100 using EnumBaseTypeT = std::underlying_type_t<EnumTypeT>;
111 return QMetaEnum::fromType<EnumTypeT>();
121 [[nodiscard]]
static QLatin1String
getName(EnumTypeT pType)
123 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);
180 [[nodiscard]]
static bool isValue(ushort pValue)
182 return isValue(
static_cast<int>(pValue));
186 [[nodiscard]]
static EnumBaseTypeT
getValue(EnumTypeT pType)
188 return static_cast<EnumBaseTypeT
>(pType);
Definition EnumHelper.h:99
static bool isValue(int pValue)
Definition EnumHelper.h:174
static QLatin1String getName()
Definition EnumHelper.h:115
static QLatin1String getName(EnumTypeT pType)
Definition EnumHelper.h:121
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 bool isValue(ushort pValue)
Definition EnumHelper.h:180
static int getCount()
Definition EnumHelper.h:135
static EnumBaseTypeT getValue(EnumTypeT pType)
Definition EnumHelper.h:186
static QMetaEnum getQtEnumMetaEnum()
Definition EnumHelper.h:109
const char * name
Definition http_parser.cpp:473
#define T(v)
Definition http_parser.cpp:237
Implementation of GeneralAuthenticate response APDUs.
Definition CommandApdu.h:17
QLatin1String getEnumName(T pType)
Definition EnumHelper.h:195