1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Copyright (C) 2016 Ivailo Monev
6 ** This file is part of the QtCore module of the Katie Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser
12 ** General Public License version 2.1 as published by the Free Software
13 ** Foundation and appearing in the file LICENSE.LGPL included in the
14 ** packaging of this file. Please review the following information to
15 ** ensure the GNU Lesser General Public License version 2.1 requirements
16 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
20 ****************************************************************************/
29 can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
31 #define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
33 // Compatibility, used to be conditional
37 #include <utility> // std::swap
38 #include <cstdint> // std::uintptr_t
40 #if !defined(QT_NO_USING_NAMESPACE)
42 # define QT_NAMESPACE Katie
43 # define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
44 # define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE;
46 # define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
47 # define QT_END_NAMESPACE }
48 # define QT_BEGIN_INCLUDE_NAMESPACE }
49 # define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE {
51 namespace QT_NAMESPACE {}
53 # ifdef QT_NAMESPACE_COMPAT
57 #else /* QT_NO_USING_NAMESPACE */
60 # define QT_PREPEND_NAMESPACE(name) ::name
61 # define QT_USE_NAMESPACE
63 # define QT_BEGIN_NAMESPACE
64 # define QT_END_NAMESPACE
65 # define QT_BEGIN_INCLUDE_NAMESPACE
66 # define QT_END_INCLUDE_NAMESPACE
68 #endif /* QT_NO_USING_NAMESPACE */
70 #define QT_BEGIN_INCLUDE_HEADER
71 #define QT_END_INCLUDE_HEADER extern "C++"
74 The compiler, must be one of: (Q_CC_x)
77 CLANG - C++ front-end for the LLVM compiler
79 Should be sorted most to least authoritative.
81 Paper Macro SD-6 macro
82 N2672 Q_COMPILER_INITIALIZER_LISTS
83 N2118 N2844 N3053 Q_COMPILER_RVALUE_REFS __cpp_rvalue_references = 200610
85 For any future version of the C++ standard, we use only the SD-6 macro.
87 http://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations
91 # if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
92 /* C++0x features supported in GCC 4.3: */
93 # define Q_COMPILER_RVALUE_REFS
94 /* C++0x features supported in GCC 4.4: */
95 # define Q_COMPILER_INITIALIZER_LISTS
96 /* C++0x features supported in GCC 4.6: */
98 # define Q_COMPILER_EXCEPTIONS
102 #elif defined(__clang__)
104 # if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
105 /* Detect C++ features using __has_feature(), see http://clang.llvm.org/docs/LanguageExtensions.html#cxx11 */
106 # if __has_feature(cxx_generalized_initializers)
107 # define Q_COMPILER_INITIALIZER_LISTS
109 # if __has_feature(cxx_rvalue_references)
110 # define Q_COMPILER_RVALUE_REFS
112 # if __has_feature(cxx_exceptions)
113 # define Q_COMPILER_EXCEPTIONS
118 # error "Katie has not been tested with this compiler"
121 #define Q_C_CALLBACKS
122 #define Q_ALIGNOF(type) __alignof__(type)
123 #define Q_TYPEOF(expr) __typeof__(expr)
124 #define Q_DECL_ALIGN(n) __attribute__((__aligned__(n)))
125 #define Q_REQUIRED_RESULT __attribute__((warn_unused_result))
126 #define Q_LIKELY(expr) __builtin_expect(!!(expr), true)
127 #define Q_UNLIKELY(expr) __builtin_expect(!!(expr), false)
128 #define Q_FUNC_INFO __PRETTY_FUNCTION__
129 #define Q_PACKED __attribute__((__packed__))
130 #define Q_OUTOFLINE_TEMPLATE
131 #define Q_INLINE_TEMPLATE inline
133 #define Q_CONSTRUCTOR_FUNCTION(AFUNC) \
134 static const int __init_variable__ ## AFUNC = AFUNC();
136 #define Q_DESTRUCTOR_FUNCTION0(AFUNC) \
137 class AFUNC ## __dest_class__ { \
139 inline AFUNC ## __dest_class__() { } \
140 inline ~ AFUNC ## __dest_class__() { AFUNC(); } \
141 } AFUNC ## __dest_instance__;
142 #define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC)
147 Size-dependent types (architechture-dependent byte order)
149 Make sure to update QMetaType when changing these typedefs
151 typedef signed char qint8; /* 8 bit signed */
152 typedef unsigned char quint8; /* 8 bit unsigned */
153 typedef short qint16; /* 16 bit signed */
154 typedef unsigned short quint16; /* 16 bit unsigned */
155 typedef int qint32; /* 32 bit signed */
156 typedef unsigned int quint32; /* 32 bit unsigned */
157 #define Q_INT64_C(c) static_cast<long long>(c ## LL) /* signed 64 bit constant */
158 #define Q_UINT64_C(c) static_cast<unsigned long long>(c ## ULL) /* unsigned 64 bit constant */
159 typedef long long qint64; /* 64 bit signed */
160 typedef unsigned long long quint64; /* 64 bit unsigned */
162 typedef qint64 qlonglong;
163 typedef quint64 qulonglong;
165 #define Q_INIT_RESOURCE(name) \
166 extern int qInitResources_ ## name (); \
167 qInitResources_ ## name ();
168 #define Q_CLEANUP_RESOURCE(name) \
169 extern int qCleanupResources_ ## name (); \
170 qCleanupResources_ ## name ();
173 Useful type definitions for Qt
175 typedef std::uintptr_t quintptr;
176 typedef std::ptrdiff_t qptrdiff;
178 QT_BEGIN_INCLUDE_NAMESPACE
179 typedef unsigned char uchar;
180 typedef unsigned short ushort;
181 typedef unsigned int uint;
182 typedef unsigned long ulong;
183 QT_END_INCLUDE_NAMESPACE
186 Warnings and errors when using deprecated methods
188 #if defined(Q_MOC_RUN)
189 # define Q_DECL_DEPRECATED Q_DECL_DEPRECATED
191 # define Q_DECL_DEPRECATED __attribute__((__deprecated__))
194 #if defined(QT_NO_DEPRECATED)
195 # undef QT_DEPRECATED
196 # undef QT_DEPRECATED_CONSTRUCTOR
197 #elif defined(QT_DEPRECATED_WARNINGS)
198 # undef QT_DEPRECATED
199 # define QT_DEPRECATED Q_DECL_DEPRECATED
200 # undef QT_DEPRECATED_CONSTRUCTOR
201 # define QT_DEPRECATED_CONSTRUCTOR explicit Q_DECL_DEPRECATED
203 # undef QT_DEPRECATED
204 # define QT_DEPRECATED
205 # undef QT_DEPRECATED_CONSTRUCTOR
206 # define QT_DEPRECATED_CONSTRUCTOR
209 #ifdef QT_ASCII_CAST_WARNINGS
210 # define QT_ASCII_CAST_WARN Q_DECL_DEPRECATED
211 # define QT_ASCII_CAST_WARN_CONSTRUCTOR QT_DEPRECATED_CONSTRUCTOR
213 # define QT_ASCII_CAST_WARN
214 # define QT_ASCII_CAST_WARN_CONSTRUCTOR
217 #if defined(QT_ARCH_I386)
218 # define QT_FASTCALL __attribute__((regparm(3)))
220 # define QT_FASTCALL __attribute__((hot))
223 // This logic must match the one in qmetatype.h
224 #if !defined(QT_NO_FPU) && defined(QT_ARCH_ARM) || defined(QT_ARCH_AVR32) || defined(QT_ARCH_SH)
228 #if defined(QT_NO_FPU)
231 typedef double qreal;
234 #define Q_DECL_EXPORT __attribute__((visibility("default")))
235 #define Q_DECL_HIDDEN __attribute__((visibility("hidden")))
236 #define Q_DECL_IMPORT
238 #ifdef KtCore_EXPORTS
239 # define Q_CORE_EXPORT Q_DECL_EXPORT
241 # define Q_CORE_EXPORT Q_DECL_IMPORT
245 # define Q_GUI_EXPORT Q_DECL_EXPORT
247 # define Q_GUI_EXPORT Q_DECL_IMPORT
251 # define Q_SQL_EXPORT Q_DECL_EXPORT
253 # define Q_SQL_EXPORT Q_DECL_IMPORT
256 #ifdef KtNetwork_EXPORTS
257 # define Q_NETWORK_EXPORT Q_DECL_EXPORT
259 # define Q_NETWORK_EXPORT Q_DECL_IMPORT
263 # define Q_SVG_EXPORT Q_DECL_EXPORT
265 # define Q_SVG_EXPORT Q_DECL_IMPORT
268 #ifdef KtTest_EXPORTS
269 # define Q_TEST_EXPORT Q_DECL_EXPORT
271 # define Q_TEST_EXPORT Q_DECL_IMPORT
274 #ifdef KtDeclarative_EXPORTS
275 # define Q_DECLARATIVE_EXPORT Q_DECL_EXPORT
277 # define Q_DECLARATIVE_EXPORT Q_DECL_IMPORT
281 # define Q_XML_EXPORT Q_DECL_EXPORT
283 # define Q_XML_EXPORT Q_DECL_IMPORT
286 #ifdef KtScript_EXPORTS
287 # define Q_SCRIPT_EXPORT Q_DECL_EXPORT
289 # define Q_SCRIPT_EXPORT Q_DECL_IMPORT
292 #ifdef KtScriptTools_EXPORTS
293 # define Q_SCRIPTTOOLS_EXPORT Q_DECL_EXPORT
295 # define Q_SCRIPTTOOLS_EXPORT Q_DECL_IMPORT
298 #ifdef KtDBus_EXPORTS
299 # define Q_DBUS_EXPORT Q_DECL_EXPORT
301 # define Q_DBUS_EXPORT Q_DECL_IMPORT
304 #ifdef KtUiTools_EXPORTS
305 # define Q_UITOOLS_EXPORT Q_DECL_EXPORT
307 # define Q_UITOOLS_EXPORT Q_DECL_IMPORT
310 #ifdef KtDesigner_EXPORTS
311 # define Q_DESIGNER_EXPORT Q_DECL_EXPORT
313 # define Q_DESIGNER_EXPORT Q_DECL_IMPORT
316 #define Q_CORE_EXPORT_INLINE Q_CORE_EXPORT inline
317 #define Q_GUI_EXPORT_INLINE Q_GUI_EXPORT inline
320 No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols
321 for Qt's internal unit tests. If you want slower loading times and more
322 symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL.
324 #if defined(QT_BUILD_INTERNAL)
325 # define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
327 # define Q_AUTOTEST_EXPORT
330 /* These wrap try/catch so we can switch off exceptions later.
332 Beware - do not use the exception instance in the catch block.
333 If you can't live with that constraint, don't use these macros.
334 Use the QT_NO_EXCEPTIONS macro to protect your code instead.
336 #if !defined(QT_NO_EXCEPTIONS) && !defined(Q_COMPILER_EXCEPTIONS) && !defined(Q_MOC_RUN)
337 # define QT_NO_EXCEPTIONS
340 #ifdef QT_NO_EXCEPTIONS
341 # define QT_TRY if (true)
342 # define QT_CATCH(A) else if (false)
343 # define QT_THROW(A) {}
344 # define QT_RETHROW {}
347 # define QT_CATCH(A) catch (A)
348 # define QT_THROW(A) throw A
349 # define QT_RETHROW throw
352 Q_CORE_EXPORT const char *qVersion();
355 Avoid "unused parameter" warnings
357 #define Q_UNUSED(x) (void)x;
360 #define qPrintable(string) QString(string).toLocal8Bit().constData()
362 Q_CORE_EXPORT QString qt_error_string(int errorCode);
364 Q_CORE_EXPORT void qDebug(const char *, ...) /* print debug message */
365 #if !defined(__INSURE__)
366 __attribute__((format (printf, 1, 2)))
370 Q_CORE_EXPORT void qWarning(const char *, ...) /* print warning message */
371 #if !defined(__INSURE__)
372 __attribute__((format (printf, 1, 2)))
376 Q_CORE_EXPORT void qCritical(const char *, ...) /* print critical message */
377 #if !defined(__INSURE__)
378 __attribute__((format (printf, 1, 2)))
381 Q_CORE_EXPORT void qFatal(const char *, ...) /* print fatal message and exit */
382 #if !defined(__INSURE__)
383 __attribute__((format (printf, 1, 2)))
387 Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line);
388 Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line);
389 Q_CORE_EXPORT void qt_check_pointer(const char *file, int line);
392 # define Q_ASSERT(cond) do { if(!(cond)) qt_assert(#cond,__FILE__,__LINE__); } while (0)
393 # define Q_ASSERT_X(cond, where, what) do { if(!(cond)) qt_assert_x(where, what,__FILE__,__LINE__); } while (0)
394 # define Q_CHECK_PTR(p) do { if(!p) qt_check_pointer(__FILE__,__LINE__); } while (0)
396 # define Q_ASSERT(cond)
397 # define Q_ASSERT_X(cond, where, what)
398 # define Q_CHECK_PTR(p)
401 enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg };
403 Q_CORE_EXPORT void qt_message_output(QtMsgType, const char *buf);
405 typedef void (*QtMsgHandler)(QtMsgType, const char *);
406 Q_CORE_EXPORT QtMsgHandler qInstallMsgHandler(QtMsgHandler);
409 #if defined(QT_NO_THREAD)
411 template <typename T>
416 inline QGlobalStatic(T *p) : pointer(p) { }
417 inline ~QGlobalStatic() { pointer = nullptr; }
420 #define Q_GLOBAL_STATIC(TYPE, NAME) \
421 static TYPE *NAME() \
423 static TYPE thisVariable; \
424 static QGlobalStatic<TYPE > thisGlobalStatic(&thisVariable); \
425 return thisGlobalStatic.pointer; \
428 #define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \
429 static TYPE *NAME() \
431 static TYPE thisVariable ARGS; \
432 static QGlobalStatic<TYPE > thisGlobalStatic(&thisVariable); \
433 return thisGlobalStatic.pointer; \
436 #define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER) \
437 static TYPE *NAME() \
439 static TYPE thisVariable; \
440 static QGlobalStatic<TYPE > thisGlobalStatic(nullptr); \
441 if (!thisGlobalStatic.pointer) { \
442 TYPE *x = thisGlobalStatic.pointer = &thisVariable; \
445 return thisGlobalStatic.pointer; \
448 #else // QT_NO_THREAD
450 // Forward declaration, since qatomic.h needs qglobal.h
451 template <typename T> class QAtomicPointer;
453 // POD for Q_GLOBAL_STATIC
454 template <typename T>
458 QAtomicPointer<T> pointer;
462 // Created as a function-local static to delete a QGlobalStatic<T>
463 template <typename T>
464 class QGlobalStaticDeleter
467 QGlobalStatic<T> &globalStatic;
468 QGlobalStaticDeleter(QGlobalStatic<T> &_globalStatic)
469 : globalStatic(_globalStatic)
472 inline ~QGlobalStaticDeleter()
474 delete globalStatic.pointer;
475 globalStatic.pointer = nullptr;
476 globalStatic.destroyed = true;
480 #define Q_GLOBAL_STATIC(TYPE, NAME) \
481 static TYPE *NAME() \
483 static QGlobalStatic<TYPE > this__StaticVar_ \
484 = { QAtomicPointer<TYPE>(new TYPE), false }; \
485 static QGlobalStaticDeleter<TYPE > cleanup(this__StaticVar_); \
486 return this__StaticVar_.pointer; \
489 #define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS) \
490 static TYPE *NAME() \
492 static QGlobalStatic<TYPE > this__StaticVar_ \
493 = { QAtomicPointer<TYPE>(new TYPE ARGS), false }; \
494 static QGlobalStaticDeleter<TYPE > cleanup(this__StaticVar_); \
495 return this__StaticVar_.pointer; \
498 #define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER) \
499 static TYPE *NAME() \
501 static QGlobalStatic<TYPE > this__StaticVar_ \
502 = { QAtomicPointer<TYPE>(nullptr), false }; \
503 if (!this__StaticVar_.pointer && !this__StaticVar_.destroyed) { \
504 QScopedPointer<TYPE > x(new TYPE); \
506 if (this__StaticVar_.pointer.testAndSetOrdered(nullptr, x.data())) { \
507 static QGlobalStaticDeleter<TYPE > cleanup(this__StaticVar_); \
511 return this__StaticVar_.pointer; \
514 #endif // QT_NO_THREAD
518 Utility macros and inline functions
520 template <typename T>
521 constexpr inline T qAbs(const T &t)
523 return t >= 0 ? t : -t;
526 template <typename T>
527 constexpr inline const T &qMin(const T &a, const T &b)
529 return (a < b) ? a : b;
532 template <typename T>
533 constexpr inline const T &qMax(const T &a, const T &b)
535 return (a < b) ? b : a;
538 template <typename T>
539 constexpr inline const T &qBound(const T &min, const T &val, const T &max)
541 return qMax(min, qMin(max, val));
544 constexpr static inline bool qFuzzyCompare(double p1, double p2)
546 return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2)));
549 constexpr static inline bool qFuzzyCompare(float p1, float p2)
551 return (qAbs(p1 - p2) <= 0.00001f * qMin(qAbs(p1), qAbs(p2)));
557 constexpr static inline bool qFuzzyIsNull(double d)
559 return qAbs(d) <= 0.000000000001;
565 constexpr static inline bool qFuzzyIsNull(float f)
567 return qAbs(f) <= 0.00001f;
571 This function tests a double for a null value. It doesn't
572 check whether the actual value is 0 or close to 0, but whether
575 static inline bool qIsNull(double d)
583 return val.u == quint64(0);
587 This function tests a float for a null value. It doesn't
588 check whether the actual value is 0 or close to 0, but whether
591 static inline bool qIsNull(float f)
603 QTypeInfo - type trait functionality
605 template <typename T>
612 isLarge = (sizeof(T) > QT_POINTER_SIZE)
616 template <typename T>
628 Specialize a specific type with:
630 Q_DECLARE_TYPEINFO(type, flags);
632 where 'type' is the name of the type to specialize and 'flags' is
633 logically-OR'ed combination of the flags below.
635 enum { /* TYPEINFO flags */
637 Q_PRIMITIVE_TYPE = 0x1,
642 #define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS) \
643 class QTypeInfo<TYPE > \
647 isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \
648 isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \
649 isLarge = (sizeof(TYPE) > QT_POINTER_SIZE), \
651 static inline const char *name() { return #TYPE; } \
654 #define Q_DECLARE_TYPEINFO(TYPE, FLAGS) \
656 Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS)
658 template <typename T>
659 inline void qSwap(T &value1, T &value2)
661 std::swap(value1, value2);
665 Specialize a shared type with:
667 Q_DECLARE_SHARED(type);
669 where 'type' is the name of the type to specialize. NOTE: shared
670 types must declare a 'bool isDetached(void) const;' member for this
673 #define Q_DECLARE_SHARED(TYPE) \
674 template <> inline void qSwap<TYPE>(TYPE &value1, TYPE &value2) \
675 { qSwap(value1.data_ptr(), value2.data_ptr()); } \
678 template<> inline void swap<QT_PREPEND_NAMESPACE(TYPE)>(QT_PREPEND_NAMESPACE(TYPE) &value1, QT_PREPEND_NAMESPACE(TYPE) &value2) \
679 { swap(value1.data_ptr(), value2.data_ptr()); } \
684 QTypeInfo primitive specializations
686 Q_DECLARE_TYPEINFO(bool, Q_PRIMITIVE_TYPE);
687 Q_DECLARE_TYPEINFO(char, Q_PRIMITIVE_TYPE);
688 Q_DECLARE_TYPEINFO(signed char, Q_PRIMITIVE_TYPE);
689 Q_DECLARE_TYPEINFO(uchar, Q_PRIMITIVE_TYPE);
690 Q_DECLARE_TYPEINFO(short, Q_PRIMITIVE_TYPE);
691 Q_DECLARE_TYPEINFO(ushort, Q_PRIMITIVE_TYPE);
692 Q_DECLARE_TYPEINFO(int, Q_PRIMITIVE_TYPE);
693 Q_DECLARE_TYPEINFO(uint, Q_PRIMITIVE_TYPE);
694 Q_DECLARE_TYPEINFO(long, Q_PRIMITIVE_TYPE);
695 Q_DECLARE_TYPEINFO(ulong, Q_PRIMITIVE_TYPE);
696 Q_DECLARE_TYPEINFO(qint64, Q_PRIMITIVE_TYPE);
697 Q_DECLARE_TYPEINFO(quint64, Q_PRIMITIVE_TYPE);
698 Q_DECLARE_TYPEINFO(float, Q_PRIMITIVE_TYPE);
699 Q_DECLARE_TYPEINFO(double, Q_PRIMITIVE_TYPE);
700 Q_DECLARE_TYPEINFO(long double, Q_PRIMITIVE_TYPE);
703 These functions make it possible to use standard C++ functions with
704 a similar name from Qt header files (especially template classes).
706 class Q_CORE_EXPORT QFlag
710 inline QFlag(int ai) : i(ai) {}
711 inline operator int() const { return i; }
714 class Q_CORE_EXPORT QIncompatibleFlag
718 inline explicit QIncompatibleFlag(int i);
719 inline operator int() const { return i; }
722 inline QIncompatibleFlag::QIncompatibleFlag(int ai) : i(ai) {}
724 #ifndef Q_NO_TYPESAFE_FLAGS
726 template<typename Enum>
732 typedef Enum enum_type;
733 constexpr inline QFlags(const QFlags &f) : i(f.i) {}
734 constexpr inline QFlags(Enum f) : i(f) {}
735 constexpr inline QFlags(Zero = 0) : i(0) {}
736 inline QFlags(QFlag f) : i(f) {}
738 inline QFlags &operator=(const QFlags &f) { i = f.i; return *this; }
739 inline QFlags &operator&=(int mask) { i &= mask; return *this; }
740 inline QFlags &operator&=(uint mask) { i &= mask; return *this; }
741 inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; }
742 inline QFlags &operator|=(Enum f) { i |= f; return *this; }
743 inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; }
744 inline QFlags &operator^=(Enum f) { i ^= f; return *this; }
746 constexpr inline operator int() const { return i; }
748 constexpr inline QFlags operator|(QFlags f) const { return QFlags(Enum(i | f.i)); }
749 constexpr inline QFlags operator|(Enum f) const { return QFlags(Enum(i | f)); }
750 constexpr inline QFlags operator^(QFlags f) const { return QFlags(Enum(i ^ f.i)); }
751 constexpr inline QFlags operator^(Enum f) const { return QFlags(Enum(i ^ f)); }
752 constexpr inline QFlags operator&(int mask) const { return QFlags(Enum(i & mask)); }
753 constexpr inline QFlags operator&(uint mask) const { return QFlags(Enum(i & mask)); }
754 constexpr inline QFlags operator&(Enum f) const { return QFlags(Enum(i & f)); }
755 constexpr inline QFlags operator~() const { return QFlags(Enum(~i)); }
757 constexpr inline bool operator!() const { return !i; }
759 inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); }
762 #define Q_DECLARE_FLAGS(Flags, Enum)\
763 typedef QFlags<Enum> Flags;
765 #define Q_DECLARE_INCOMPATIBLE_FLAGS(Flags) \
766 inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) \
767 { return QIncompatibleFlag(int(f1) | f2); }
769 #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \
770 constexpr inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
771 { return QFlags<Flags::enum_type>(f1) | f2; } \
772 constexpr inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
773 { return f2 | f1; } Q_DECLARE_INCOMPATIBLE_FLAGS(Flags)
776 #else /* Q_NO_TYPESAFE_FLAGS */
778 #define Q_DECLARE_FLAGS(Flags, Enum)\
780 #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
782 #endif /* Q_NO_TYPESAFE_FLAGS */
784 #ifdef QT_FOREACH_COMPAT
785 template <typename T>
786 class QForeachContainer {
788 inline QForeachContainer(const T& t) : c(t) { }
789 inline typename T::const_iterator begin() { return c.begin(); }
790 inline typename T::const_iterator end() { return c.end(); }
795 #define Q_FOREACH(variable, container) \
796 for (variable: QForeachContainer<Q_TYPEOF(container)>(container))
798 #else // QT_FOREACH_COMPAT
800 #define Q_FOREACH(variable, container) for (variable: container)
802 #endif // QT_FOREACH_COMPAT
804 #define Q_FOREVER for(;;)
805 #ifndef QT_NO_KEYWORDS
807 # define foreach Q_FOREACH
810 # define forever Q_FOREVER
814 #define Q_UNREACHABLE() \
815 Q_ASSERT_X(false, "Q_UNREACHABLE()", "Q_UNREACHABLE was reached"); \
816 __builtin_unreachable()
818 template <typename T> static inline T *qGetPtrHelper(T *ptr) { return ptr; }
819 template <typename Wrapper> static inline typename Wrapper::pointer qGetPtrHelper(const Wrapper &p) { return p.data(); }
821 #define Q_DECLARE_PRIVATE(Class) \
822 inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \
823 inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \
824 friend class Class##Private;
826 #define Q_DECLARE_PRIVATE_D(Dptr, Class) \
827 inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(Dptr); } \
828 inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(Dptr); } \
829 friend class Class##Private;
831 #define Q_DECLARE_PUBLIC(Class) \
832 inline Class* q_func() { return static_cast<Class *>(q_ptr); } \
833 inline const Class* q_func() const { return static_cast<const Class *>(q_ptr); } \
836 #define Q_D(Class) Class##Private * const d = d_func()
837 #define Q_Q(Class) Class * const q = q_func()
839 #define QT_TR_NOOP(x) (x)
840 #define QT_TR_NOOP_UTF8(x) (x)
841 #define QT_TRANSLATE_NOOP(scope, x) (x)
842 #define QT_TRANSLATE_NOOP_UTF8(scope, x) (x)
845 When RTTI is not available, define this macro to force any uses of
846 dynamic_cast to cause a compile failure.
848 #ifdef QT_NO_DYNAMIC_CAST
849 # define dynamic_cast QT_PREPEND_NAMESPACE(qt_dynamic_cast_check)
851 template<typename T, typename X>
852 T qt_dynamic_cast_check(X, T* = 0)
853 { return T::dynamic_cast_will_always_fail_because_rtti_is_disabled; }
857 Some classes do not permit copies to be made of an object. These
858 classes contains a private copy constructor and assignment
859 operator to disable copying (the compiler gives an error message).
861 #define Q_DISABLE_COPY(Class) \
862 Class(const Class &) = delete; \
863 Class &operator=(const Class &) = delete;
866 Q_CORE_EXPORT QByteArray qgetenv(const char *varName);
867 Q_CORE_EXPORT bool qputenv(const char *varName, const QByteArray& value);
870 Reentrant versions of basic rand() functions for random number generation
872 Q_CORE_EXPORT void qsrand(uint seed);
873 Q_CORE_EXPORT int qrand();
877 #endif /* QGLOBAL_H */