40 #include <QtCore/qglobal.h>
41 #include <QtCore/qcompare_impl.h>
46 #include <initializer_list>
57 constexpr
inline Q_IMPLICIT
operator int()
const noexcept {
return i; }
59 #if !defined(Q_CC_MSVC)
63 # if !defined(__LP64__) && !defined(Q_CLANG_QDOC)
70 constexpr
inline Q_IMPLICIT
operator uint()
const noexcept {
return uint(
i); }
80 constexpr
inline Q_IMPLICIT
operator int()
const noexcept {
return i; }
87 template<
typename Enum>
90 static_assert((
sizeof(
Enum) <=
sizeof(
int)),
91 "QFlags uses an int as storage, so an enum with underlying "
92 "long long will overflow.");
96 #if defined(Q_CC_MSVC) || defined(Q_CLANG_QDOC)
101 typedef typename std::conditional<
109 constexpr
inline QFlags() noexcept : i(0) {}
113 constexpr
inline QFlags(std::initializer_list<Enum>
flags) noexcept
114 :
i(initializer_list_helper(
flags.begin(),
flags.end())) {}
119 #ifndef QT_TYPESAFE_FLAGS
130 #ifdef QT_TYPESAFE_FLAGS
131 constexpr
inline explicit operator Int()
const noexcept {
return i; }
132 constexpr
inline explicit operator bool()
const noexcept {
return i; }
137 constexpr
inline explicit operator QFlag()
const noexcept {
return QFlag(i); }
139 constexpr
inline Q_IMPLICIT
operator Int()
const noexcept {
return i; }
147 #ifndef QT_TYPESAFE_FLAGS
168 return on ? (*
this |= flag) : (*
this &= ~
QFlags(flag));
172 {
return lhs.i ==
rhs.i; }
174 {
return lhs.i !=
rhs.i; }
184 #ifdef QT_TYPESAFE_FLAGS
210 #define Q_DECLARE_FLAGS(Flags, Enum)\
211 typedef QFlags<Enum> Flags;
214 #ifdef QT_TYPESAFE_FLAGS
217 #define QT_DECLARE_TYPESAFE_OPERATORS_FOR_FLAGS_ENUM(Flags) \
218 constexpr inline Flags operator~(Flags::enum_type e) noexcept \
219 { return ~Flags(e); } \
220 constexpr inline void operator|(Flags::enum_type f1, int f2) noexcept = delete;
222 #define QT_DECLARE_TYPESAFE_OPERATORS_FOR_FLAGS_ENUM(Flags) \
223 constexpr inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) noexcept \
224 { return QIncompatibleFlag(int(f1) | f2); }
227 #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \
228 constexpr inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) noexcept \
229 { return QFlags<Flags::enum_type>(f1) | f2; } \
230 constexpr inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
231 { return f2 | f1; } \
232 constexpr inline QFlags<Flags::enum_type> operator&(Flags::enum_type f1, Flags::enum_type f2) noexcept \
233 { return QFlags<Flags::enum_type>(f1) & f2; } \
234 constexpr inline QFlags<Flags::enum_type> operator&(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
235 { return f2 & f1; } \
236 constexpr inline QFlags<Flags::enum_type> operator^(Flags::enum_type f1, Flags::enum_type f2) noexcept \
237 { return QFlags<Flags::enum_type>(f1) ^ f2; } \
238 constexpr inline QFlags<Flags::enum_type> operator^(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept \
239 { return f2 ^ f1; } \
240 constexpr inline void operator+(Flags::enum_type f1, Flags::enum_type f2) noexcept = delete; \
241 constexpr inline void operator+(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept = delete; \
242 constexpr inline void operator+(int f1, QFlags<Flags::enum_type> f2) noexcept = delete; \
243 constexpr inline void operator-(Flags::enum_type f1, Flags::enum_type f2) noexcept = delete; \
244 constexpr inline void operator-(Flags::enum_type f1, QFlags<Flags::enum_type> f2) noexcept = delete; \
245 constexpr inline void operator-(int f1, QFlags<Flags::enum_type> f2) noexcept = delete; \
246 constexpr inline void operator+(int f1, Flags::enum_type f2) noexcept = delete; \
247 constexpr inline void operator+(Flags::enum_type f1, int f2) noexcept = delete; \
248 constexpr inline void operator-(int f1, Flags::enum_type f2) noexcept = delete; \
249 constexpr inline void operator-(Flags::enum_type f1, int f2) noexcept = delete; \
250 QT_DECLARE_TYPESAFE_OPERATORS_FOR_FLAGS_ENUM(Flags)
254 #if __cplusplus > 201702L
256 # define Q_DECLARE_MIXED_ENUM_OPERATOR(op, Ret, LHS, RHS) \
257 constexpr inline Ret operator op (LHS lhs, RHS rhs) noexcept \
258 { return static_cast<Ret>(qToUnderlying(lhs) op qToUnderlying(rhs)); } \
263 # define Q_DECLARE_MIXED_ENUM_OPERATOR(op, Ret, LHS, RHS) \
264 static_assert(std::is_same_v<decltype(std::declval<LHS>() op std::declval<RHS>()), Ret>);
267 #define Q_DECLARE_MIXED_ENUM_OPERATORS(Ret, Flags, Enum) \
268 Q_DECLARE_MIXED_ENUM_OPERATOR(|, Ret, Flags, Enum) \
269 Q_DECLARE_MIXED_ENUM_OPERATOR(&, Ret, Flags, Enum) \
270 Q_DECLARE_MIXED_ENUM_OPERATOR(^, Ret, Flags, Enum) \
273 #define Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(Ret, Flags, Enum) \
274 Q_DECLARE_MIXED_ENUM_OPERATORS(Ret, Flags, Enum) \
275 Q_DECLARE_MIXED_ENUM_OPERATORS(Ret, Enum, Flags) \
small capitals from c petite p scientific i
[1]
The QDataStream class provides serialization of binary data to a QIODevice.
The QFlag class is a helper data type for QFlags.
constexpr Q_IMPLICIT QFlag(int value) noexcept
constexpr Q_IMPLICIT QFlag(ushort value) noexcept
constexpr Q_IMPLICIT QFlag(uint value) noexcept
constexpr Q_IMPLICIT QFlag(ulong value) noexcept
constexpr Q_IMPLICIT QFlag(short value) noexcept
constexpr Q_IMPLICIT QFlag(long value) noexcept
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
constexpr QFlags & operator&=(QFlags mask) noexcept
constexpr QFlags operator&(QFlags other) const noexcept
constexpr QFlags operator|(Enum other) const noexcept
constexpr void operator+(int other) const noexcept=delete
constexpr QFlags & operator|=(QFlags other) noexcept
constexpr Int toInt() const noexcept
constexpr QFlags & setFlag(Enum flag, bool on=true) noexcept
constexpr QFlags & operator^=(Enum other) noexcept
constexpr QFlags & operator^=(QFlags other) noexcept
constexpr QFlags operator|(QFlags other) const noexcept
constexpr QFlags operator&(int mask) const noexcept
constexpr friend bool operator==(QFlags lhs, Enum rhs) noexcept
constexpr QFlags operator&(uint mask) const noexcept
constexpr void operator-(int other) const noexcept=delete
constexpr bool testAnyFlags(QFlags flags) const noexcept
constexpr friend bool operator==(QFlags lhs, QFlags rhs) noexcept
constexpr friend bool operator!=(QFlags lhs, Enum rhs) noexcept
constexpr QFlags operator^(Enum other) const noexcept
constexpr QFlags operator~() const noexcept
constexpr void operator+(Enum other) const noexcept=delete
constexpr static QFlags fromInt(Int i) noexcept
constexpr QFlags(std::initializer_list< Enum > flags) noexcept
constexpr void operator+(QFlags other) const noexcept=delete
constexpr Q_IMPLICIT QFlags(Enum flags) noexcept
constexpr QFlags & operator&=(Enum mask) noexcept
std::conditional< std::is_unsigned< typename std::underlying_type< Enum >::type >::value, unsigned int, signed int >::type Int
constexpr QFlags operator^(QFlags other) const noexcept
constexpr void operator-(Enum other) const noexcept=delete
constexpr friend bool operator!=(QFlags lhs, QFlags rhs) noexcept
constexpr QFlags operator&(Enum other) const noexcept
constexpr void operator-(QFlags other) const noexcept=delete
constexpr friend bool operator!=(Enum lhs, QFlags rhs) noexcept
constexpr bool operator!() const noexcept
constexpr QFlags() noexcept
constexpr friend bool operator==(Enum lhs, QFlags rhs) noexcept
constexpr QFlags & operator&=(uint mask) noexcept
constexpr Q_IMPLICIT QFlags(QFlag flag) noexcept
constexpr bool testFlag(Enum flag) const noexcept
constexpr QFlags & operator&=(int mask) noexcept
constexpr bool testFlags(QFlags flags) const noexcept
constexpr bool testAnyFlag(Enum flag) const noexcept
constexpr QFlags & operator|=(Enum other) noexcept
constexpr QIncompatibleFlag(int i) noexcept
auto it unsigned count const
typename C::const_iterator const_iterator
EGLOutputLayerEXT EGLint EGLAttrib value
Q_DECLARE_TYPEINFO(QFlag, Q_PRIMITIVE_TYPE)
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask