1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2016 Intel Corporation.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QGLOBAL_H
42#define QGLOBAL_H
43
44#ifdef __cplusplus
45# include <type_traits>
46# include <cstddef>
47# include <utility>
48#endif
49#ifndef __ASSEMBLER__
50# include <assert.h>
51# include <stddef.h>
52#endif
53
54/*
55 QT_VERSION is (major << 16) + (minor << 8) + patch.
56*/
57#define QT_VERSION QT_VERSION_CHECK(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH)
58/*
59 can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
60*/
61#define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
62
63#ifdef QT_BOOTSTRAPPED
64#include <QtCore/qconfig-bootstrapped.h>
65#else
66#include <QtCore/qconfig.h>
67#include <QtCore/qtcore-config.h>
68#endif
69
70// The QT_SUPPORTS macro is deprecated. Don't use it in new code.
71// Instead, use QT_CONFIG(feature)
72// ### Qt6: remove macro
73#ifdef _MSC_VER
74# define QT_SUPPORTS(FEATURE) (!defined QT_NO_##FEATURE)
75#else
76# define QT_SUPPORTS(FEATURE) (!defined(QT_NO_##FEATURE))
77#endif
78
79/*
80 The QT_CONFIG macro implements a safe compile time check for features of Qt.
81 Features can be in three states:
82 0 or undefined: This will lead to a compile error when testing for it
83 -1: The feature is not available
84 1: The feature is available
85*/
86#define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
87#define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.")
88
89#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
90# define QT_NO_UNSHARABLE_CONTAINERS
91# define QT6_VIRTUAL virtual
92# define QT6_NOT_VIRTUAL
93#else
94# define QT6_VIRTUAL
95# define QT6_NOT_VIRTUAL virtual
96#endif
97
98/* These two macros makes it possible to turn the builtin line expander into a
99 * string literal. */
100#define QT_STRINGIFY2(x) #x
101#define QT_STRINGIFY(x) QT_STRINGIFY2(x)
102
103#include <QtCore/qsystemdetection.h>
104#include <QtCore/qprocessordetection.h>
105#include <QtCore/qcompilerdetection.h>
106
107#if defined (__ELF__)
108# define Q_OF_ELF
109#endif
110#if defined (__MACH__) && defined (__APPLE__)
111# define Q_OF_MACH_O
112#endif
113
114/*
115 Avoid "unused parameter" warnings
116*/
117#define Q_UNUSED(x) (void)x;
118
119#if defined(__cplusplus) && defined(Q_COMPILER_STATIC_ASSERT)
120# define Q_STATIC_ASSERT(Condition) static_assert(bool(Condition), #Condition)
121# define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
122#elif defined(Q_COMPILER_STATIC_ASSERT)
123// C11 mode - using the _S version in case <assert.h> doesn't do the right thing
124# define Q_STATIC_ASSERT(Condition) _Static_assert(!!(Condition), #Condition)
125# define Q_STATIC_ASSERT_X(Condition, Message) _Static_assert(!!(Condition), Message)
126#else
127// C89 & C99 version
128# define Q_STATIC_ASSERT_PRIVATE_JOIN(A, B) Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B)
129# define Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) A ## B
130# ifdef __COUNTER__
131# define Q_STATIC_ASSERT(Condition) \
132 typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __COUNTER__) [(Condition) ? 1 : -1];
133# else
134# define Q_STATIC_ASSERT(Condition) \
135 typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) [(Condition) ? 1 : -1];
136# endif /* __COUNTER__ */
137# define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition)
138#endif
139
140#ifdef __cplusplus
141
142#include <algorithm>
143
144#if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */
145
146# define QT_PREPEND_NAMESPACE(name) ::name
147# define QT_USE_NAMESPACE
148# define QT_BEGIN_NAMESPACE
149# define QT_END_NAMESPACE
150# define QT_BEGIN_INCLUDE_NAMESPACE
151# define QT_END_INCLUDE_NAMESPACE
152#ifndef QT_BEGIN_MOC_NAMESPACE
153# define QT_BEGIN_MOC_NAMESPACE
154#endif
155#ifndef QT_END_MOC_NAMESPACE
156# define QT_END_MOC_NAMESPACE
157#endif
158# define QT_FORWARD_DECLARE_CLASS(name) class name;
159# define QT_FORWARD_DECLARE_STRUCT(name) struct name;
160# define QT_MANGLE_NAMESPACE(name) name
161
162#else /* user namespace */
163
164# define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
165# define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE;
166# define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
167# define QT_END_NAMESPACE }
168# define QT_BEGIN_INCLUDE_NAMESPACE }
169# define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE {
170#ifndef QT_BEGIN_MOC_NAMESPACE
171# define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE
172#endif
173#ifndef QT_END_MOC_NAMESPACE
174# define QT_END_MOC_NAMESPACE
175#endif
176# define QT_FORWARD_DECLARE_CLASS(name) \
177 QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \
178 using QT_PREPEND_NAMESPACE(name);
179
180# define QT_FORWARD_DECLARE_STRUCT(name) \
181 QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \
182 using QT_PREPEND_NAMESPACE(name);
183
184# define QT_MANGLE_NAMESPACE0(x) x
185# define QT_MANGLE_NAMESPACE1(a, b) a##_##b
186# define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b)
187# define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \
188 QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE))
189
190namespace QT_NAMESPACE {}
191
192# ifndef QT_BOOTSTRAPPED
193# ifndef QT_NO_USING_NAMESPACE
194 /*
195 This expands to a "using QT_NAMESPACE" also in _header files_.
196 It is the only way the feature can be used without too much
197 pain, but if people _really_ do not want it they can add
198 DEFINES += QT_NO_USING_NAMESPACE to their .pro files.
199 */
200 QT_USE_NAMESPACE
201# endif
202# endif
203
204#endif /* user namespace */
205
206#else /* __cplusplus */
207
208# define QT_BEGIN_NAMESPACE
209# define QT_END_NAMESPACE
210# define QT_USE_NAMESPACE
211# define QT_BEGIN_INCLUDE_NAMESPACE
212# define QT_END_INCLUDE_NAMESPACE
213
214#endif /* __cplusplus */
215
216// ### Qt6: remove me.
217#define QT_BEGIN_HEADER
218#define QT_END_HEADER
219
220#if defined(Q_OS_DARWIN) && !defined(QT_LARGEFILE_SUPPORT)
221# define QT_LARGEFILE_SUPPORT 64
222#endif
223
224#ifndef __ASSEMBLER__
225QT_BEGIN_NAMESPACE
226
227/*
228 Size-dependent types (architechture-dependent byte order)
229
230 Make sure to update QMetaType when changing these typedefs
231*/
232
233typedef signed char qint8; /* 8 bit signed */
234typedef unsigned char quint8; /* 8 bit unsigned */
235typedef short qint16; /* 16 bit signed */
236typedef unsigned short quint16; /* 16 bit unsigned */
237typedef int qint32; /* 32 bit signed */
238typedef unsigned int quint32; /* 32 bit unsigned */
239#if defined(Q_OS_WIN) && !defined(Q_CC_GNU)
240# define Q_INT64_C(c) c ## i64 /* signed 64 bit constant */
241# define Q_UINT64_C(c) c ## ui64 /* unsigned 64 bit constant */
242typedef __int64 qint64; /* 64 bit signed */
243typedef unsigned __int64 quint64; /* 64 bit unsigned */
244#else
245#ifdef __cplusplus
246# define Q_INT64_C(c) static_cast<long long>(c ## LL) /* signed 64 bit constant */
247# define Q_UINT64_C(c) static_cast<unsigned long long>(c ## ULL) /* unsigned 64 bit constant */
248#else
249# define Q_INT64_C(c) ((long long)(c ## LL)) /* signed 64 bit constant */
250# define Q_UINT64_C(c) ((unsigned long long)(c ## ULL)) /* unsigned 64 bit constant */
251#endif
252typedef long long qint64; /* 64 bit signed */
253typedef unsigned long long quint64; /* 64 bit unsigned */
254#endif
255
256typedef qint64 qlonglong;
257typedef quint64 qulonglong;
258
259#ifndef __cplusplus
260// In C++ mode, we define below using QIntegerForSize template
261Q_STATIC_ASSERT_X(sizeof(ptrdiff_t) == sizeof(size_t), "Weird ptrdiff_t and size_t definitions");
262typedef ptrdiff_t qptrdiff;
263typedef ptrdiff_t qsizetype;
264typedef ptrdiff_t qintptr;
265typedef size_t quintptr;
266#endif
267
268/*
269 Useful type definitions for Qt
270*/
271
272QT_BEGIN_INCLUDE_NAMESPACE
273typedef unsigned char uchar;
274typedef unsigned short ushort;
275typedef unsigned int uint;
276typedef unsigned long ulong;
277QT_END_INCLUDE_NAMESPACE
278
279#if defined(QT_COORD_TYPE)
280typedef QT_COORD_TYPE qreal;
281#else
282typedef double qreal;
283#endif
284
285#if defined(QT_NO_DEPRECATED)
286# undef QT_DEPRECATED
287# undef QT_DEPRECATED_X
288# undef QT_DEPRECATED_VARIABLE
289# undef QT_DEPRECATED_CONSTRUCTOR
290#elif defined(QT_DEPRECATED_WARNINGS)
291# undef QT_DEPRECATED
292# define QT_DEPRECATED Q_DECL_DEPRECATED
293# undef QT_DEPRECATED_X
294# define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
295# undef QT_DEPRECATED_VARIABLE
296# define QT_DEPRECATED_VARIABLE Q_DECL_VARIABLE_DEPRECATED
297# undef QT_DEPRECATED_CONSTRUCTOR
298# define QT_DEPRECATED_CONSTRUCTOR explicit Q_DECL_CONSTRUCTOR_DEPRECATED
299#else
300# undef QT_DEPRECATED
301# define QT_DEPRECATED
302# undef QT_DEPRECATED_X
303# define QT_DEPRECATED_X(text)
304# undef QT_DEPRECATED_VARIABLE
305# define QT_DEPRECATED_VARIABLE
306# undef QT_DEPRECATED_CONSTRUCTOR
307# define QT_DEPRECATED_CONSTRUCTOR
308#endif
309
310#ifndef QT_DISABLE_DEPRECATED_BEFORE
311#define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(5, 0, 0)
312#endif
313
314/*
315 QT_DEPRECATED_SINCE(major, minor) evaluates as true if the Qt version is greater than
316 the deprecation point specified.
317
318 Use it to specify from which version of Qt a function or class has been deprecated
319
320 Example:
321 #if QT_DEPRECATED_SINCE(5,1)
322 QT_DEPRECATED void deprecatedFunction(); //function deprecated since Qt 5.1
323 #endif
324
325*/
326#ifdef QT_DEPRECATED
327#define QT_DEPRECATED_SINCE(major, minor) (QT_VERSION_CHECK(major, minor, 0) > QT_DISABLE_DEPRECATED_BEFORE)
328#else
329#define QT_DEPRECATED_SINCE(major, minor) 0
330#endif
331
332/*
333 The Qt modules' export macros.
334 The options are:
335 - defined(QT_STATIC): Qt was built or is being built in static mode
336 - defined(QT_SHARED): Qt was built or is being built in shared/dynamic mode
337 If neither was defined, then QT_SHARED is implied. If Qt was compiled in static
338 mode, QT_STATIC is defined in qconfig.h. In shared mode, QT_STATIC is implied
339 for the bootstrapped tools.
340*/
341
342#ifdef QT_BOOTSTRAPPED
343# ifdef QT_SHARED
344# error "QT_SHARED and QT_BOOTSTRAPPED together don't make sense. Please fix the build"
345# elif !defined(QT_STATIC)
346# define QT_STATIC
347# endif
348#endif
349
350#if defined(QT_SHARED) || !defined(QT_STATIC)
351# ifdef QT_STATIC
352# error "Both QT_SHARED and QT_STATIC defined, please make up your mind"
353# endif
354# ifndef QT_SHARED
355# define QT_SHARED
356# endif
357# if defined(QT_BUILD_CORE_LIB)
358# define Q_CORE_EXPORT Q_DECL_EXPORT
359# else
360# define Q_CORE_EXPORT Q_DECL_IMPORT
361# endif
362#else
363# define Q_CORE_EXPORT
364#endif
365
366/*
367 Some classes do not permit copies to be made of an object. These
368 classes contains a private copy constructor and assignment
369 operator to disable copying (the compiler gives an error message).
370*/
371#define Q_DISABLE_COPY(Class) \
372 Class(const Class &) Q_DECL_EQ_DELETE;\
373 Class &operator=(const Class &) Q_DECL_EQ_DELETE;
374
375#define Q_DISABLE_MOVE(Class) \
376 Class(Class &&) = delete; \
377 Class &operator=(Class &&) = delete;
378
379#define Q_DISABLE_COPY_MOVE(Class) \
380 Q_DISABLE_COPY(Class) \
381 Q_DISABLE_MOVE(Class)
382
383/*
384 No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols
385 for Qt's internal unit tests. If you want slower loading times and more
386 symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL.
387*/
388#if defined(QT_BUILD_INTERNAL) && defined(QT_BUILDING_QT) && defined(QT_SHARED)
389# define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
390#elif defined(QT_BUILD_INTERNAL) && defined(QT_SHARED)
391# define Q_AUTOTEST_EXPORT Q_DECL_IMPORT
392#else
393# define Q_AUTOTEST_EXPORT
394#endif
395
396#define Q_INIT_RESOURCE(name) \
397 do { extern int QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); \
398 QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); } while (false)
399#define Q_CLEANUP_RESOURCE(name) \
400 do { extern int QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); \
401 QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); } while (false)
402
403/*
404 * If we're compiling C++ code:
405 * - and this is a non-namespace build, declare qVersion as extern "C"
406 * - and this is a namespace build, declare it as a regular function
407 * (we're already inside QT_BEGIN_NAMESPACE / QT_END_NAMESPACE)
408 * If we're compiling C code, simply declare the function. If Qt was compiled
409 * in a namespace, qVersion isn't callable anyway.
410 */
411#if !defined(QT_NAMESPACE) && defined(__cplusplus) && !defined(Q_QDOC)
412extern "C"
413#endif
414Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char *qVersion(void) Q_DECL_NOTHROW;
415
416#if defined(__cplusplus)
417
418#ifndef Q_CONSTRUCTOR_FUNCTION
419# define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \
420 namespace { \
421 static const struct AFUNC ## _ctor_class_ { \
422 inline AFUNC ## _ctor_class_() { AFUNC(); } \
423 } AFUNC ## _ctor_instance_; \
424 }
425
426# define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC)
427#endif
428
429#ifndef Q_DESTRUCTOR_FUNCTION
430# define Q_DESTRUCTOR_FUNCTION0(AFUNC) \
431 namespace { \
432 static const struct AFUNC ## _dtor_class_ { \
433 inline AFUNC ## _dtor_class_() { } \
434 inline ~ AFUNC ## _dtor_class_() { AFUNC(); } \
435 } AFUNC ## _dtor_instance_; \
436 }
437# define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC)
438#endif
439
440namespace QtPrivate {
441 template <class T>
442 struct AlignOfHelper
443 {
444 char c;
445 T type;
446
447 AlignOfHelper();
448 ~AlignOfHelper();
449 };
450
451 template <class T>
452 struct AlignOf_Default
453 {
454 enum { Value = sizeof(AlignOfHelper<T>) - sizeof(T) };
455 };
456
457 template <class T> struct AlignOf : AlignOf_Default<T> { };
458 template <class T> struct AlignOf<T &> : AlignOf<T> {};
459 template <size_t N, class T> struct AlignOf<T[N]> : AlignOf<T> {};
460
461#ifdef Q_COMPILER_RVALUE_REFS
462 template <class T> struct AlignOf<T &&> : AlignOf<T> {};
463#endif
464
465#if defined(Q_PROCESSOR_X86_32) && !defined(Q_OS_WIN)
466 template <class T> struct AlignOf_WorkaroundForI386Abi { enum { Value = sizeof(T) }; };
467
468 // x86 ABI weirdness
469 // Alignment of naked type is 8, but inside struct has alignment 4.
470 template <> struct AlignOf<double> : AlignOf_WorkaroundForI386Abi<double> {};
471 template <> struct AlignOf<qint64> : AlignOf_WorkaroundForI386Abi<qint64> {};
472 template <> struct AlignOf<quint64> : AlignOf_WorkaroundForI386Abi<quint64> {};
473#ifdef Q_CC_CLANG
474 // GCC and Clang seem to disagree wrt to alignment of arrays
475 template <size_t N> struct AlignOf<double[N]> : AlignOf_Default<double> {};
476 template <size_t N> struct AlignOf<qint64[N]> : AlignOf_Default<qint64> {};
477 template <size_t N> struct AlignOf<quint64[N]> : AlignOf_Default<quint64> {};
478#endif
479#endif
480} // namespace QtPrivate
481
482#define QT_EMULATED_ALIGNOF(T) \
483 (size_t(QT_PREPEND_NAMESPACE(QtPrivate)::AlignOf<T>::Value))
484
485#ifndef Q_ALIGNOF
486#define Q_ALIGNOF(T) QT_EMULATED_ALIGNOF(T)
487#endif
488
489
490/*
491 quintptr and qptrdiff is guaranteed to be the same size as a pointer, i.e.
492
493 sizeof(void *) == sizeof(quintptr)
494 && sizeof(void *) == sizeof(qptrdiff)
495
496 size_t and qsizetype are not guaranteed to be the same size as a pointer, but
497 they usually are.
498*/
499template <int> struct QIntegerForSize;
500template <> struct QIntegerForSize<1> { typedef quint8 Unsigned; typedef qint8 Signed; };
501template <> struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
502template <> struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
503template <> struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
504#if defined(Q_CC_GNU) && defined(__SIZEOF_INT128__)
505template <> struct QIntegerForSize<16> { __extension__ typedef unsigned __int128 Unsigned; __extension__ typedef __int128 Signed; };
506#endif
507template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
508typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Signed qregisterint;
509typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Unsigned qregisteruint;
510typedef QIntegerForSizeof<void*>::Unsigned quintptr;
511typedef QIntegerForSizeof<void*>::Signed qptrdiff;
512typedef qptrdiff qintptr;
513using qsizetype = QIntegerForSizeof<std::size_t>::Signed;
514
515/* moc compats (signals/slots) */
516#ifndef QT_MOC_COMPAT
517# define QT_MOC_COMPAT
518#else
519# undef QT_MOC_COMPAT
520# define QT_MOC_COMPAT
521#endif
522
523#ifdef QT_ASCII_CAST_WARNINGS
524# define QT_ASCII_CAST_WARN Q_DECL_DEPRECATED_X("Use fromUtf8, QStringLiteral, or QLatin1String")
525#else
526# define QT_ASCII_CAST_WARN
527#endif
528
529#ifdef Q_PROCESSOR_X86_32
530# if defined(Q_CC_GNU)
531# define QT_FASTCALL __attribute__((regparm(3)))
532# elif defined(Q_CC_MSVC)
533# define QT_FASTCALL __fastcall
534# else
535# define QT_FASTCALL
536# endif
537#else
538# define QT_FASTCALL
539#endif
540
541// enable gcc warnings for printf-style functions
542#if defined(Q_CC_GNU) && !defined(__INSURE__)
543# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
544# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
545 __attribute__((format(gnu_printf, (A), (B))))
546# else
547# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
548 __attribute__((format(printf, (A), (B))))
549# endif
550#else
551# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B)
552#endif
553
554#ifdef Q_CC_MSVC
555# define Q_NEVER_INLINE __declspec(noinline)
556# define Q_ALWAYS_INLINE __forceinline
557#elif defined(Q_CC_GNU)
558# define Q_NEVER_INLINE __attribute__((noinline))
559# define Q_ALWAYS_INLINE inline __attribute__((always_inline))
560#else
561# define Q_NEVER_INLINE
562# define Q_ALWAYS_INLINE inline
563#endif
564
565#if defined(Q_CC_GNU) && defined(Q_OS_WIN)
566# define QT_INIT_METAOBJECT __attribute__((init_priority(101)))
567#else
568# define QT_INIT_METAOBJECT
569#endif
570
571//defines the type for the WNDPROC on windows
572//the alignment needs to be forced for sse2 to not crash with mingw
573#if defined(Q_OS_WIN)
574# if defined(Q_CC_MINGW) && !defined(Q_OS_WIN64)
575# define QT_ENSURE_STACK_ALIGNED_FOR_SSE __attribute__ ((force_align_arg_pointer))
576# else
577# define QT_ENSURE_STACK_ALIGNED_FOR_SSE
578# endif
579# define QT_WIN_CALLBACK CALLBACK QT_ENSURE_STACK_ALIGNED_FOR_SSE
580#endif
581
582typedef int QNoImplicitBoolCast;
583
584/*
585 Utility macros and inline functions
586*/
587
588template <typename T>
589Q_DECL_CONSTEXPR inline T qAbs(const T &t) { return t >= 0 ? t : -t; }
590
591Q_DECL_CONSTEXPR inline int qRound(double d)
592{ return d >= 0.0 ? int(d + 0.5) : int(d - double(int(d-1)) + 0.5) + int(d-1); }
593Q_DECL_CONSTEXPR inline int qRound(float d)
594{ return d >= 0.0f ? int(d + 0.5f) : int(d - float(int(d-1)) + 0.5f) + int(d-1); }
595
596Q_DECL_CONSTEXPR inline qint64 qRound64(double d)
597{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - double(qint64(d-1)) + 0.5) + qint64(d-1); }
598Q_DECL_CONSTEXPR inline qint64 qRound64(float d)
599{ return d >= 0.0f ? qint64(d + 0.5f) : qint64(d - float(qint64(d-1)) + 0.5f) + qint64(d-1); }
600
601template <typename T>
602constexpr inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; }
603template <typename T>
604constexpr inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; }
605template <typename T>
606constexpr inline const T &qBound(const T &min, const T &val, const T &max)
607{ return qMax(min, qMin(max, val)); }
608
609#ifndef Q_FORWARD_DECLARE_OBJC_CLASS
610# ifdef __OBJC__
611# define Q_FORWARD_DECLARE_OBJC_CLASS(classname) @class classname
612# else
613# define Q_FORWARD_DECLARE_OBJC_CLASS(classname) typedef struct objc_object classname
614# endif
615#endif
616#ifndef Q_FORWARD_DECLARE_CF_TYPE
617# define Q_FORWARD_DECLARE_CF_TYPE(type) typedef const struct __ ## type * type ## Ref
618#endif
619#ifndef Q_FORWARD_DECLARE_MUTABLE_CF_TYPE
620# define Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) typedef struct __ ## type * type ## Ref
621#endif
622#ifndef Q_FORWARD_DECLARE_CG_TYPE
623#define Q_FORWARD_DECLARE_CG_TYPE(type) typedef const struct type *type ## Ref;
624#endif
625#ifndef Q_FORWARD_DECLARE_MUTABLE_CG_TYPE
626#define Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(type) typedef struct type *type ## Ref;
627#endif
628
629#ifdef Q_OS_DARWIN
630# define QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, tvos, watchos) \
631 ((defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && macos != __MAC_NA && __MAC_OS_X_VERSION_MAX_ALLOWED >= macos) || \
632 (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && ios != __IPHONE_NA && __IPHONE_OS_VERSION_MAX_ALLOWED >= ios) || \
633 (defined(__TV_OS_VERSION_MAX_ALLOWED) && tvos != __TVOS_NA && __TV_OS_VERSION_MAX_ALLOWED >= tvos) || \
634 (defined(__WATCH_OS_VERSION_MAX_ALLOWED) && watchos != __WATCHOS_NA && __WATCH_OS_VERSION_MAX_ALLOWED >= watchos))
635
636# define QT_DARWIN_DEPLOYMENT_TARGET_BELOW(macos, ios, tvos, watchos) \
637 ((defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && macos != __MAC_NA && __MAC_OS_X_VERSION_MIN_REQUIRED < macos) || \
638 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && ios != __IPHONE_NA && __IPHONE_OS_VERSION_MIN_REQUIRED < ios) || \
639 (defined(__TV_OS_VERSION_MIN_REQUIRED) && tvos != __TVOS_NA && __TV_OS_VERSION_MIN_REQUIRED < tvos) || \
640 (defined(__WATCH_OS_VERSION_MIN_REQUIRED) && watchos != __WATCHOS_NA && __WATCH_OS_VERSION_MIN_REQUIRED < watchos))
641
642# define QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios) \
643 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, __TVOS_NA, __WATCHOS_NA)
644# define QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos) \
645 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, __IPHONE_NA, __TVOS_NA, __WATCHOS_NA)
646# define QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(ios) \
647 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, ios, __TVOS_NA, __WATCHOS_NA)
648# define QT_TVOS_PLATFORM_SDK_EQUAL_OR_ABOVE(tvos) \
649 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, __IPHONE_NA, tvos, __WATCHOS_NA)
650# define QT_WATCHOS_PLATFORM_SDK_EQUAL_OR_ABOVE(watchos) \
651 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, __IPHONE_NA, __TVOS_NA, watchos)
652
653# define QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(macos, ios) \
654 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(macos, ios, __TVOS_NA, __WATCHOS_NA)
655# define QT_MACOS_DEPLOYMENT_TARGET_BELOW(macos) \
656 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(macos, __IPHONE_NA, __TVOS_NA, __WATCHOS_NA)
657# define QT_IOS_DEPLOYMENT_TARGET_BELOW(ios) \
658 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(__MAC_NA, ios, __TVOS_NA, __WATCHOS_NA)
659# define QT_TVOS_DEPLOYMENT_TARGET_BELOW(tvos) \
660 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(__MAC_NA, __IPHONE_NA, tvos, __WATCHOS_NA)
661# define QT_WATCHOS_DEPLOYMENT_TARGET_BELOW(watchos) \
662 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(__MAC_NA, __IPHONE_NA, __TVOS_NA, watchos)
663
664// Compatibility synonyms, do not use
665# define QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(osx, ios) QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(osx, ios)
666# define QT_MAC_DEPLOYMENT_TARGET_BELOW(osx, ios) QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(osx, ios)
667# define QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(osx) QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(osx)
668# define QT_OSX_DEPLOYMENT_TARGET_BELOW(osx) QT_MACOS_DEPLOYMENT_TARGET_BELOW(osx)
669
670// Implemented in qcore_mac_objc.mm
671class Q_CORE_EXPORT QMacAutoReleasePool
672{
673public:
674 QMacAutoReleasePool();
675 ~QMacAutoReleasePool();
676private:
677 Q_DISABLE_COPY(QMacAutoReleasePool)
678 void *pool;
679};
680
681#else
682
683#define QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, tvos, watchos) (0)
684#define QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios) (0)
685#define QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos) (0)
686#define QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(ios) (0)
687#define QT_TVOS_PLATFORM_SDK_EQUAL_OR_ABOVE(tvos) (0)
688#define QT_WATCHOS_PLATFORM_SDK_EQUAL_OR_ABOVE(watchos) (0)
689
690#define QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(osx, ios) (0)
691#define QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(osx) (0)
692
693#endif // Q_OS_DARWIN
694
695/*
696 Data stream functions are provided by many classes (defined in qdatastream.h)
697*/
698
699class QDataStream;
700
701inline void qt_noop(void) {}
702
703/* These wrap try/catch so we can switch off exceptions later.
704
705 Beware - do not use more than one QT_CATCH per QT_TRY, and do not use
706 the exception instance in the catch block.
707 If you can't live with those constraints, don't use these macros.
708 Use the QT_NO_EXCEPTIONS macro to protect your code instead.
709*/
710
711#if !defined(QT_NO_EXCEPTIONS)
712# if !defined(Q_MOC_RUN)
713# if (defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !QT_HAS_FEATURE(cxx_exceptions)) || \
714 (defined(Q_CC_GNU) && !defined(__EXCEPTIONS))
715# define QT_NO_EXCEPTIONS
716# endif
717# elif defined(QT_BOOTSTRAPPED)
718# define QT_NO_EXCEPTIONS
719# endif
720#endif
721
722#ifdef QT_NO_EXCEPTIONS
723# define QT_TRY if (true)
724# define QT_CATCH(A) else
725# define QT_THROW(A) qt_noop()
726# define QT_RETHROW qt_noop()
727# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
728#else
729# define QT_TRY try
730# define QT_CATCH(A) catch (A)
731# define QT_THROW(A) throw A
732# define QT_RETHROW throw
733Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() Q_DECL_NOTHROW;
734# ifdef Q_COMPILER_NOEXCEPT
735# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
736# else
737# define QT_TERMINATE_ON_EXCEPTION(expr) do { try { expr; } catch (...) { qTerminate(); } } while (false)
738# endif
739#endif
740
741Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qSharedBuild() Q_DECL_NOTHROW;
742
743#ifndef Q_OUTOFLINE_TEMPLATE
744# define Q_OUTOFLINE_TEMPLATE
745#endif
746#ifndef Q_INLINE_TEMPLATE
747# define Q_INLINE_TEMPLATE inline
748#endif
749
750/*
751 Debugging and error handling
752*/
753
754#if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG)
755# define QT_DEBUG
756#endif
757
758// QtPrivate::asString defined in qstring.h
759#ifndef qPrintable
760# define qPrintable(string) QtPrivate::asString(string).toLocal8Bit().constData()
761#endif
762
763#ifndef qUtf8Printable
764# define qUtf8Printable(string) QtPrivate::asString(string).toUtf8().constData()
765#endif
766
767/*
768 Wrap QString::utf16() with enough casts to allow passing it
769 to QString::asprintf("%ls") without warnings.
770*/
771#ifndef qUtf16Printable
772# define qUtf16Printable(string) \
773 static_cast<const wchar_t*>(static_cast<const void*>(QString(string).utf16()))
774#endif
775
776class QString;
777Q_DECL_COLD_FUNCTION
778Q_CORE_EXPORT QString qt_error_string(int errorCode = -1);
779
780#ifndef Q_CC_MSVC
781Q_NORETURN
782#endif
783Q_DECL_COLD_FUNCTION
784Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) Q_DECL_NOTHROW;
785
786#if !defined(Q_ASSERT)
787# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
788# define Q_ASSERT(cond) static_cast<void>(false && (cond))
789# else
790# define Q_ASSERT(cond) ((cond) ? static_cast<void>(0) : qt_assert(#cond, __FILE__, __LINE__))
791# endif
792#endif
793
794#if defined(QT_NO_DEBUG) && !defined(QT_PAINT_DEBUG)
795#define QT_NO_PAINT_DEBUG
796#endif
797
798#ifndef Q_CC_MSVC
799Q_NORETURN
800#endif
801Q_DECL_COLD_FUNCTION
802Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line) Q_DECL_NOTHROW;
803
804#if !defined(Q_ASSERT_X)
805# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
806# define Q_ASSERT_X(cond, where, what) static_cast<void>(false && (cond))
807# else
808# define Q_ASSERT_X(cond, where, what) ((cond) ? static_cast<void>(0) : qt_assert_x(where, what, __FILE__, __LINE__))
809# endif
810#endif
811
812Q_NORETURN Q_CORE_EXPORT void qt_check_pointer(const char *, int) Q_DECL_NOTHROW;
813Q_DECL_COLD_FUNCTION
814Q_CORE_EXPORT void qBadAlloc();
815
816#ifdef QT_NO_EXCEPTIONS
817# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
818# define Q_CHECK_PTR(p) qt_noop()
819# else
820# define Q_CHECK_PTR(p) do {if (!(p)) qt_check_pointer(__FILE__,__LINE__);} while (false)
821# endif
822#else
823# define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (false)
824#endif
825
826template <typename T>
827inline T *q_check_ptr(T *p) { Q_CHECK_PTR(p); return p; }
828
829typedef void (*QFunctionPointer)();
830
831#if !defined(Q_UNIMPLEMENTED)
832# define Q_UNIMPLEMENTED() qWarning("Unimplemented code.")
833#endif
834
835Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool qFuzzyCompare(double p1, double p2)
836{
837 return (qAbs(p1 - p2) * 1000000000000. <= qMin(qAbs(p1), qAbs(p2)));
838}
839
840Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool qFuzzyCompare(float p1, float p2)
841{
842 return (qAbs(p1 - p2) * 100000.f <= qMin(qAbs(p1), qAbs(p2)));
843}
844
845Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool qFuzzyIsNull(double d)
846{
847 return qAbs(d) <= 0.000000000001;
848}
849
850Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool qFuzzyIsNull(float f)
851{
852 return qAbs(f) <= 0.00001f;
853}
854
855/*
856 This function tests a double for a null value. It doesn't
857 check whether the actual value is 0 or close to 0, but whether
858 it is binary 0, disregarding sign.
859*/
860Q_REQUIRED_RESULT static inline Q_DECL_UNUSED bool qIsNull(double d)
861{
862 union U {
863 double d;
864 quint64 u;
865 };
866 U val;
867 val.d = d;
868 return (val.u & Q_UINT64_C(0x7fffffffffffffff)) == 0;
869}
870
871/*
872 This function tests a float for a null value. It doesn't
873 check whether the actual value is 0 or close to 0, but whether
874 it is binary 0, disregarding sign.
875*/
876Q_REQUIRED_RESULT static inline Q_DECL_UNUSED bool qIsNull(float f)
877{
878 union U {
879 float f;
880 quint32 u;
881 };
882 U val;
883 val.f = f;
884 return (val.u & 0x7fffffff) == 0;
885}
886
887/*
888 Compilers which follow outdated template instantiation rules
889 require a class to have a comparison operator to exist when
890 a QList of this type is instantiated. It's not actually
891 used in the list, though. Hence the dummy implementation.
892 Just in case other code relies on it we better trigger a warning
893 mandating a real implementation.
894*/
895
896#ifdef Q_FULL_TEMPLATE_INSTANTIATION
897# define Q_DUMMY_COMPARISON_OPERATOR(C) \
898 bool operator==(const C&) const { \
899 qWarning(#C"::operator==(const "#C"&) was called"); \
900 return false; \
901 }
902#else
903
904# define Q_DUMMY_COMPARISON_OPERATOR(C)
905#endif
906
907namespace QtPrivate
908{
909namespace SwapExceptionTester { // insulate users from the "using std::swap" below
910 using std::swap; // import std::swap
911 template <typename T>
912 void checkSwap(T &t)
913 Q_DECL_NOEXCEPT_EXPR(noexcept(swap(t, t)));
914 // declared, but not implemented (only to be used in unevaluated contexts (noexcept operator))
915}
916} // namespace QtPrivate
917
918template <typename T>
919inline void qSwap(T &value1, T &value2)
920 Q_DECL_NOEXCEPT_EXPR(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1)))
921{
922 using std::swap;
923 swap(value1, value2);
924}
925
926#if QT_DEPRECATED_SINCE(5, 0)
927Q_CORE_EXPORT QT_DEPRECATED void *qMalloc(size_t size) Q_ALLOC_SIZE(1);
928Q_CORE_EXPORT QT_DEPRECATED void qFree(void *ptr);
929Q_CORE_EXPORT QT_DEPRECATED void *qRealloc(void *ptr, size_t size) Q_ALLOC_SIZE(2);
930Q_CORE_EXPORT QT_DEPRECATED void *qMemCopy(void *dest, const void *src, size_t n);
931Q_CORE_EXPORT QT_DEPRECATED void *qMemSet(void *dest, int c, size_t n);
932#endif
933Q_CORE_EXPORT void *qMallocAligned(size_t size, size_t alignment) Q_ALLOC_SIZE(1);
934Q_CORE_EXPORT void *qReallocAligned(void *ptr, size_t size, size_t oldsize, size_t alignment) Q_ALLOC_SIZE(2);
935Q_CORE_EXPORT void qFreeAligned(void *ptr);
936
937
938/*
939 Avoid some particularly useless warnings from some stupid compilers.
940 To get ALL C++ compiler warnings, define QT_CC_WARNINGS or comment out
941 the line "#define QT_NO_WARNINGS".
942*/
943#if !defined(QT_CC_WARNINGS)
944# define QT_NO_WARNINGS
945#endif
946#if defined(QT_NO_WARNINGS)
947# if defined(Q_CC_MSVC)
948QT_WARNING_DISABLE_MSVC(4251) /* class 'type' needs to have dll-interface to be used by clients of class 'type2' */
949QT_WARNING_DISABLE_MSVC(4244) /* conversion from 'type1' to 'type2', possible loss of data */
950QT_WARNING_DISABLE_MSVC(4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */
951QT_WARNING_DISABLE_MSVC(4514) /* unreferenced inline function has been removed */
952QT_WARNING_DISABLE_MSVC(4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */
953QT_WARNING_DISABLE_MSVC(4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */
954QT_WARNING_DISABLE_MSVC(4706) /* assignment within conditional expression */
955QT_WARNING_DISABLE_MSVC(4355) /* 'this' : used in base member initializer list */
956QT_WARNING_DISABLE_MSVC(4710) /* function not inlined */
957QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc */
958# elif defined(Q_CC_BOR)
959# pragma option -w-inl
960# pragma option -w-aus
961# pragma warn -inl
962# pragma warn -pia
963# pragma warn -ccc
964# pragma warn -rch
965# pragma warn -sig
966# endif
967#endif
968
969// this adds const to non-const objects (like std::as_const)
970template <typename T>
971Q_DECL_CONSTEXPR typename std::add_const<T>::type &qAsConst(T &t) Q_DECL_NOTHROW { return t; }
972// prevent rvalue arguments:
973template <typename T>
974void qAsConst(const T &&) Q_DECL_EQ_DELETE;
975
976#ifndef QT_NO_FOREACH
977
978namespace QtPrivate {
979
980template <typename T>
981class QForeachContainer {
982 Q_DISABLE_COPY(QForeachContainer)
983public:
984 QForeachContainer(const T &t) : c(t), i(qAsConst(c).begin()), e(qAsConst(c).end()) {}
985 QForeachContainer(T &&t) : c(std::move(t)), i(qAsConst(c).begin()), e(qAsConst(c).end()) {}
986
987 QForeachContainer(QForeachContainer &&other)
988 : c(std::move(other.c)),
989 i(qAsConst(c).begin()),
990 e(qAsConst(c).end()),
991 control(std::move(other.control))
992 {
993 }
994
995 QForeachContainer &operator=(QForeachContainer &&other)
996 {
997 c = std::move(other.c);
998 i = qAsConst(c).begin();
999 e = qAsConst(c).end();
1000 control = std::move(other.control);
1001 return *this;
1002 }
1003
1004 T c;
1005 typename T::const_iterator i, e;
1006 int control = 1;
1007};
1008
1009template<typename T>
1010QForeachContainer<typename std::decay<T>::type> qMakeForeachContainer(T &&t)
1011{
1012 return QForeachContainer<typename std::decay<T>::type>(std::forward<T>(t));
1013}
1014
1015}
1016
1017#if __cplusplus >= 201703L
1018// Use C++17 if statement with initializer. User's code ends up in a else so
1019// scoping of different ifs is not broken
1020#define Q_FOREACH(variable, container) \
1021for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \
1022 _container_.i != _container_.e; ++_container_.i) \
1023 if (variable = *_container_.i; false) {} else
1024#else
1025// Explanation of the control word:
1026// - it's initialized to 1
1027// - that means both the inner and outer loops start
1028// - if there were no breaks, at the end of the inner loop, it's set to 0, which
1029// causes it to exit (the inner loop is run exactly once)
1030// - at the end of the outer loop, it's inverted, so it becomes 1 again, allowing
1031// the outer loop to continue executing
1032// - if there was a break inside the inner loop, it will exit with control still
1033// set to 1; in that case, the outer loop will invert it to 0 and will exit too
1034#define Q_FOREACH(variable, container) \
1035for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \
1036 _container_.control && _container_.i != _container_.e; \
1037 ++_container_.i, _container_.control ^= 1) \
1038 for (variable = *_container_.i; _container_.control; _container_.control = 0)
1039#endif
1040#endif // QT_NO_FOREACH
1041
1042#define Q_FOREVER for(;;)
1043#ifndef QT_NO_KEYWORDS
1044# ifndef QT_NO_FOREACH
1045# ifndef foreach
1046# define foreach Q_FOREACH
1047# endif
1048# endif // QT_NO_FOREACH
1049# ifndef forever
1050# define forever Q_FOREVER
1051# endif
1052#endif
1053
1054template <typename T> inline T *qGetPtrHelper(T *ptr) { return ptr; }
1055template <typename Ptr> inline auto qGetPtrHelper(const Ptr &ptr) -> decltype(ptr.operator->()) { return ptr.operator->(); }
1056
1057#define Q_DECLARE_PRIVATE(Class) \
1058 inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \
1059 inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \
1060 friend class Class##Private;
1061
1062#define Q_DECLARE_PRIVATE_D(Dptr, Class) \
1063 inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(Dptr)); } \
1064 inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(Dptr)); } \
1065 friend class Class##Private;
1066
1067#define Q_DECLARE_PUBLIC(Class) \
1068 inline Class* q_func() { return static_cast<Class *>(q_ptr); } \
1069 inline const Class* q_func() const { return static_cast<const Class *>(q_ptr); } \
1070 friend class Class;
1071
1072#define Q_D(Class) Class##Private * const d = d_func()
1073#define Q_Q(Class) Class * const q = q_func()
1074
1075#define QT_TR_NOOP(x) x
1076#define QT_TR_NOOP_UTF8(x) x
1077#define QT_TRANSLATE_NOOP(scope, x) x
1078#define QT_TRANSLATE_NOOP_UTF8(scope, x) x
1079#define QT_TRANSLATE_NOOP3(scope, x, comment) {x, comment}
1080#define QT_TRANSLATE_NOOP3_UTF8(scope, x, comment) {x, comment}
1081
1082#ifndef QT_NO_TRANSLATION // ### Qt6: This should enclose the NOOPs above
1083
1084#define QT_TR_N_NOOP(x) x
1085#define QT_TRANSLATE_N_NOOP(scope, x) x
1086#define QT_TRANSLATE_N_NOOP3(scope, x, comment) {x, comment}
1087
1088// Defined in qcoreapplication.cpp
1089// The better name qTrId() is reserved for an upcoming function which would
1090// return a much more powerful QStringFormatter instead of a QString.
1091Q_CORE_EXPORT QString qtTrId(const char *id, int n = -1);
1092
1093#define QT_TRID_NOOP(id) id
1094
1095#endif // QT_NO_TRANSLATION
1096
1097/*
1098 When RTTI is not available, define this macro to force any uses of
1099 dynamic_cast to cause a compile failure.
1100*/
1101
1102#if defined(QT_NO_DYNAMIC_CAST) && !defined(dynamic_cast)
1103# define dynamic_cast QT_PREPEND_NAMESPACE(qt_dynamic_cast_check)
1104
1105 template<typename T, typename X>
1106 T qt_dynamic_cast_check(X, T* = 0)
1107 { return T::dynamic_cast_will_always_fail_because_rtti_is_disabled; }
1108#endif
1109
1110
1111#ifdef Q_QDOC
1112
1113// Just for documentation generation
1114template<typename T>
1115auto qOverload(T functionPointer);
1116template<typename T>
1117auto qConstOverload(T memberFunctionPointer);
1118template<typename T>
1119auto qNonConstOverload(T memberFunctionPointer);
1120
1121#elif defined(Q_COMPILER_VARIADIC_TEMPLATES)
1122
1123template <typename... Args>
1124struct QNonConstOverload
1125{
1126 template <typename R, typename T>
1127 Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr)
1128 { return ptr; }
1129
1130 template <typename R, typename T>
1131 static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr)
1132 { return ptr; }
1133};
1134
1135template <typename... Args>
1136struct QConstOverload
1137{
1138 template <typename R, typename T>
1139 Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const Q_DECL_NOTHROW -> decltype(ptr)
1140 { return ptr; }
1141
1142 template <typename R, typename T>
1143 static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) Q_DECL_NOTHROW -> decltype(ptr)
1144 { return ptr; }
1145};
1146
1147template <typename... Args>
1148struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
1149{
1150 using QConstOverload<Args...>::of;
1151 using QConstOverload<Args...>::operator();
1152 using QNonConstOverload<Args...>::of;
1153 using QNonConstOverload<Args...>::operator();
1154
1155 template <typename R>
1156 Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr)
1157 { return ptr; }
1158
1159 template <typename R>
1160 static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr)
1161 { return ptr; }
1162};
1163
1164#if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 // C++14
1165template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QOverload<Args...> qOverload = {};
1166template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QConstOverload<Args...> qConstOverload = {};
1167template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QNonConstOverload<Args...> qNonConstOverload = {};
1168#endif
1169
1170#endif
1171
1172
1173class QByteArray;
1174Q_CORE_EXPORT QByteArray qgetenv(const char *varName);
1175// need it as two functions because QString is only forward-declared here
1176Q_CORE_EXPORT QString qEnvironmentVariable(const char *varName);
1177Q_CORE_EXPORT QString qEnvironmentVariable(const char *varName, const QString &defaultValue);
1178Q_CORE_EXPORT bool qputenv(const char *varName, const QByteArray& value);
1179Q_CORE_EXPORT bool qunsetenv(const char *varName);
1180
1181Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT;
1182Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) Q_DECL_NOEXCEPT;
1183Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) Q_DECL_NOEXCEPT;
1184
1185inline int qIntCast(double f) { return int(f); }
1186inline int qIntCast(float f) { return int(f); }
1187
1188/*
1189 Reentrant versions of basic rand() functions for random number generation
1190*/
1191Q_CORE_EXPORT void qsrand(uint seed);
1192Q_CORE_EXPORT int qrand();
1193
1194#define QT_MODULE(x)
1195
1196#if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && \
1197 (!defined(__PIC__) || (defined(__PIE__) && defined(Q_CC_GNU) && Q_CC_GNU >= 500))
1198# error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
1199 "Compile your code with -fPIC (-fPIE is not enough)."
1200#endif
1201
1202namespace QtPrivate {
1203//like std::enable_if
1204template <bool B, typename T = void> struct QEnableIf;
1205template <typename T> struct QEnableIf<true, T> { typedef T Type; };
1206}
1207
1208QT_END_NAMESPACE
1209
1210// We need to keep QTypeInfo, QSysInfo, QFlags, qDebug & family in qglobal.h for compatibility with Qt 4.
1211// Be careful when changing the order of these files.
1212#include <QtCore/qtypeinfo.h>
1213#include <QtCore/qsysinfo.h>
1214#include <QtCore/qlogging.h>
1215
1216#include <QtCore/qflags.h>
1217
1218#include <QtCore/qatomic.h>
1219#include <QtCore/qglobalstatic.h>
1220#include <QtCore/qnumeric.h>
1221#include <QtCore/qversiontagging.h>
1222
1223#endif /* __cplusplus */
1224#endif /* !__ASSEMBLER__ */
1225
1226#endif /* QGLOBAL_H */
1227