11 #include <type_traits> 17 #define defineEnumOperators(enumName)\ 18 inline QDebug operator<<(QDebug pDbg, enumName pType)\ 20 QDebugStateSaver saver(pDbg);\ 21 return pDbg.noquote() << Enum<enumName>::getName(pType);\ 24 inline QString& operator+=(QString & pStr, enumName pType)\ 26 pStr += Enum<enumName>::getName(pType);\ 30 inline QString operator+(const QString& pStr, enumName pType)\ 32 return pStr + Enum<enumName>::getName(pType);\ 35 inline QString operator+(enumName pType, const QString& pStr)\ 37 return Enum<enumName>::getName(pType) + pStr;\ 40 inline bool operator==(std::underlying_type<enumName>::type pType, enumName pName)\ 42 return static_cast<std::underlying_type<enumName>::type>(pName) == pType;\ 44 inline bool operator!=(std::underlying_type<enumName>::type pType, enumName pName)\ 46 return !(pType == pName);\ 49 inline uint qHash(enumName pKey, uint pSeed)\ 51 return ::qHash(static_cast<std::underlying_type<enumName>::type>(pKey), pSeed);\ 55 #define defineTypedEnumType(enumName, enumType, ...)\ 61 Q_DISABLE_COPY(Enum##enumName)\ 64 enum class enumName : enumType\ 72 using enumName = Enum##enumName::enumName;\ 74 defineEnumOperators(enumName) 77 #define defineEnumType(enumName, ...) defineTypedEnumType(enumName, int, __VA_ARGS__) 80 template<
typename EnumTypeT>
class Enum 82 using EnumBaseTypeT =
typename std::underlying_type<EnumTypeT>::type;
91 return QMetaEnum::fromType<EnumTypeT>();
103 const int value = static_cast<int>(pType);
105 if (Q_UNLIKELY(
name ==
nullptr))
107 qCritical().noquote().nospace() <<
"CRITICAL CONVERSION MISMATCH: UNKNOWN 0x" << QString::number(value, 16);
108 return QLatin1String();
111 return QLatin1String(
name);
123 QVector<EnumTypeT> list;
126 list.reserve(metaEnum.keyCount());
127 for (
int i = 0; i < metaEnum.keyCount(); ++i)
129 list << static_cast<EnumTypeT>(metaEnum.value(i));
136 static EnumTypeT
fromString(
const char*
const pValue, EnumTypeT pDefault)
142 return static_cast<EnumTypeT>(key);
148 static EnumTypeT
fromString(
const QString& pValue, EnumTypeT pDefaultType)
150 return fromString(pValue.toUtf8().constData(), pDefaultType);
162 return isValue(static_cast<int>(pValue));
168 return isValue(static_cast<uchar>(pValue));
174 return static_cast<EnumBaseTypeT>(pType);
static QMetaEnum getQtEnumMetaEnum()
Definition: EnumHelper.h:89
static bool isValue(uchar pValue)
Definition: EnumHelper.h:160
Definition: EnumHelper.h:80
static QVector< EnumTypeT > getList()
Definition: EnumHelper.h:121
QLatin1String getEnumName(T pType)
Definition: EnumHelper.h:181
Implementation of ActivationContext for Intent based activation on Android systems.
Definition: ActivationContext.h:14
static bool isValue(int pValue)
Definition: EnumHelper.h:154
static QLatin1String getName()
Definition: EnumHelper.h:95
static EnumTypeT fromString(const QString &pValue, EnumTypeT pDefaultType)
Definition: EnumHelper.h:148
static EnumBaseTypeT getValue(EnumTypeT pType)
Definition: EnumHelper.h:172
#define T(v)
Definition: http_parser.cpp:237
static QLatin1String getName(EnumTypeT pType)
Definition: EnumHelper.h:101
const char * name
Definition: http_parser.cpp:470
static EnumTypeT fromString(const char *const pValue, EnumTypeT pDefault)
Definition: EnumHelper.h:136
static int getCount()
Definition: EnumHelper.h:115
static bool isValue(char pValue)
Definition: EnumHelper.h:166