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