11 #include <type_traits>
18 #define defineEnumOperators(enumName)\
19 inline QDebug operator<<(QDebug pDbg, enumName pType)\
21 QDebugStateSaver saver(pDbg);\
22 return pDbg.noquote() << Enum<enumName>::getName(pType);\
25 inline QString& operator+=(QString & pStr, enumName pType)\
27 pStr += Enum<enumName>::getName(pType);\
31 inline QString operator+(const QString& pStr, enumName pType)\
33 return pStr + Enum<enumName>::getName(pType);\
36 inline QString operator+(enumName pType, const QString& pStr)\
38 return Enum<enumName>::getName(pType) + pStr;\
41 inline bool operator==(std::underlying_type<enumName>::type pType, enumName pName)\
43 return static_cast<std::underlying_type<enumName>::type>(pName) == pType;\
45 inline bool operator!=(std::underlying_type<enumName>::type pType, enumName pName)\
47 return !(pType == pName);\
51 #define defineTypedEnumType(enumName, enumType, ...)\
57 Q_DISABLE_COPY(Enum##enumName)\
60 enum class enumName : enumType\
68 using enumName = Enum##enumName::enumName;\
70 defineEnumOperators(enumName)
73 #define defineEnumType(enumName, ...) defineTypedEnumType(enumName, int, __VA_ARGS__)
76 template<
typename EnumTypeT>
class Enum
78 using EnumBaseTypeT =
typename std::underlying_type<EnumTypeT>::type;
87 return QMetaEnum::fromType<EnumTypeT>();
97 static QLatin1String
getName(EnumTypeT pType)
99 const int value =
static_cast<int>(pType);
101 if (Q_UNLIKELY(name ==
nullptr))
103 qCritical().noquote().nospace() <<
"CRITICAL CONVERSION MISMATCH: UNKNOWN 0x" << QString::number(value, 16);
104 return QLatin1String();
107 return QLatin1String(name);
119 static QVector<EnumTypeT> list;
123 list.reserve(metaEnum.keyCount());
124 for (
int i = 0; i < metaEnum.keyCount(); ++i)
126 list.push_back(static_cast<EnumTypeT>(metaEnum.value(i)));
133 static EnumTypeT
fromString(
const char* pValue, EnumTypeT pDefault)
139 return static_cast<EnumTypeT
>(key);
145 static EnumTypeT
fromString(
const QString& pValue, EnumTypeT pDefaultType)
147 return fromString(pValue.toUtf8().constData(), pDefaultType);
159 return isValue(static_cast<int>(pValue));
165 return isValue(static_cast<uchar>(pValue));
171 return static_cast<EnumBaseTypeT
>(pType);
static QMetaEnum getQtEnumMetaEnum()
Definition: EnumHelper.h:85
static bool isValue(uchar pValue)
Definition: EnumHelper.h:157
Definition: EnumHelper.h:76
static EnumTypeT fromString(const char *pValue, EnumTypeT pDefault)
Definition: EnumHelper.h:133
QLatin1String getEnumName(T pType)
Definition: EnumHelper.h:178
static bool isValue(int pValue)
Definition: EnumHelper.h:151
static QLatin1String getName()
Definition: EnumHelper.h:91
static EnumTypeT fromString(const QString &pValue, EnumTypeT pDefaultType)
Definition: EnumHelper.h:145
static EnumBaseTypeT getValue(EnumTypeT pType)
Definition: EnumHelper.h:169
#define T(v)
Definition: http_parser.cpp:234
static QLatin1String getName(EnumTypeT pType)
Definition: EnumHelper.h:97
static const QVector< EnumTypeT > & getList()
Definition: EnumHelper.h:117
const char * name
Definition: http_parser.cpp:463
static int getCount()
Definition: EnumHelper.h:111
static bool isValue(char pValue)
Definition: EnumHelper.h:163