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/*
376 No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols
377 for Qt's internal unit tests. If you want slower loading times and more
378 symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL.
379*/
380#if defined(QT_BUILD_INTERNAL) && defined(QT_BUILDING_QT) && defined(QT_SHARED)
381# define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
382#elif defined(QT_BUILD_INTERNAL) && defined(QT_SHARED)
383# define Q_AUTOTEST_EXPORT Q_DECL_IMPORT
384#else
385# define Q_AUTOTEST_EXPORT
386#endif
387
388#define Q_INIT_RESOURCE(name) \
389 do { extern int QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); \
390 QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); } while (false)
391#define Q_CLEANUP_RESOURCE(name) \
392 do { extern int QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); \
393 QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); } while (false)
394
395/*
396 * If we're compiling C++ code:
397 * - and this is a non-namespace build, declare qVersion as extern "C"
398 * - and this is a namespace build, declare it as a regular function
399 * (we're already inside QT_BEGIN_NAMESPACE / QT_END_NAMESPACE)
400 * If we're compiling C code, simply declare the function. If Qt was compiled
401 * in a namespace, qVersion isn't callable anyway.
402 */
403#if !defined(QT_NAMESPACE) && defined(__cplusplus) && !defined(Q_QDOC)
404extern "C"
405#endif
406Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char *qVersion(void) Q_DECL_NOTHROW;
407
408#if defined(__cplusplus)
409
410#ifndef Q_CONSTRUCTOR_FUNCTION
411# define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \
412 namespace { \
413 static const struct AFUNC ## _ctor_class_ { \
414 inline AFUNC ## _ctor_class_() { AFUNC(); } \
415 } AFUNC ## _ctor_instance_; \
416 }
417
418# define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC)
419#endif
420
421#ifndef Q_DESTRUCTOR_FUNCTION
422# define Q_DESTRUCTOR_FUNCTION0(AFUNC) \
423 namespace { \
424 static const struct AFUNC ## _dtor_class_ { \
425 inline AFUNC ## _dtor_class_() { } \
426 inline ~ AFUNC ## _dtor_class_() { AFUNC(); } \
427 } AFUNC ## _dtor_instance_; \
428 }
429# define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC)
430#endif
431
432namespace QtPrivate {
433 template <class T>
434 struct AlignOfHelper
435 {
436 char c;
437 T type;
438
439 AlignOfHelper();
440 ~AlignOfHelper();
441 };
442
443 template <class T>
444 struct AlignOf_Default
445 {
446 enum { Value = sizeof(AlignOfHelper<T>) - sizeof(T) };
447 };
448
449 template <class T> struct AlignOf : AlignOf_Default<T> { };
450 template <class T> struct AlignOf<T &> : AlignOf<T> {};
451 template <size_t N, class T> struct AlignOf<T[N]> : AlignOf<T> {};
452
453#ifdef Q_COMPILER_RVALUE_REFS
454 template <class T> struct AlignOf<T &&> : AlignOf<T> {};
455#endif
456
457#if defined(Q_PROCESSOR_X86_32) && !defined(Q_OS_WIN)
458 template <class T> struct AlignOf_WorkaroundForI386Abi { enum { Value = sizeof(T) }; };
459
460 // x86 ABI weirdness
461 // Alignment of naked type is 8, but inside struct has alignment 4.
462 template <> struct AlignOf<double> : AlignOf_WorkaroundForI386Abi<double> {};
463 template <> struct AlignOf<qint64> : AlignOf_WorkaroundForI386Abi<qint64> {};
464 template <> struct AlignOf<quint64> : AlignOf_WorkaroundForI386Abi<quint64> {};
465#ifdef Q_CC_CLANG
466 // GCC and Clang seem to disagree wrt to alignment of arrays
467 template <size_t N> struct AlignOf<double[N]> : AlignOf_Default<double> {};
468 template <size_t N> struct AlignOf<qint64[N]> : AlignOf_Default<qint64> {};
469 template <size_t N> struct AlignOf<quint64[N]> : AlignOf_Default<quint64> {};
470#endif
471#endif
472} // namespace QtPrivate
473
474#define QT_EMULATED_ALIGNOF(T) \
475 (size_t(QT_PREPEND_NAMESPACE(QtPrivate)::AlignOf<T>::Value))
476
477#ifndef Q_ALIGNOF
478#define Q_ALIGNOF(T) QT_EMULATED_ALIGNOF(T)
479#endif
480
481
482/*
483 quintptr and qptrdiff is guaranteed to be the same size as a pointer, i.e.
484
485 sizeof(void *) == sizeof(quintptr)
486 && sizeof(void *) == sizeof(qptrdiff)
487
488 size_t and qsizetype are not guaranteed to be the same size as a pointer, but
489 they usually are.
490*/
491template <int> struct QIntegerForSize;
492template <> struct QIntegerForSize<1> { typedef quint8 Unsigned; typedef qint8 Signed; };
493template <> struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
494template <> struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
495template <> struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
496#if defined(Q_CC_GNU) && defined(__SIZEOF_INT128__)
497template <> struct QIntegerForSize<16> { __extension__ typedef unsigned __int128 Unsigned; __extension__ typedef __int128 Signed; };
498#endif
499template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
500typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Signed qregisterint;
501typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Unsigned qregisteruint;
502typedef QIntegerForSizeof<void*>::Unsigned quintptr;
503typedef QIntegerForSizeof<void*>::Signed qptrdiff;
504typedef qptrdiff qintptr;
505using qsizetype = QIntegerForSizeof<std::size_t>::Signed;
506
507/* moc compats (signals/slots) */
508#ifndef QT_MOC_COMPAT
509# define QT_MOC_COMPAT
510#else
511# undef QT_MOC_COMPAT
512# define QT_MOC_COMPAT
513#endif
514
515#ifdef QT_ASCII_CAST_WARNINGS
516# define QT_ASCII_CAST_WARN Q_DECL_DEPRECATED_X("Use fromUtf8, QStringLiteral, or QLatin1String")
517#else
518# define QT_ASCII_CAST_WARN
519#endif
520
521#ifdef Q_PROCESSOR_X86_32
522# if defined(Q_CC_GNU)
523# define QT_FASTCALL __attribute__((regparm(3)))
524# elif defined(Q_CC_MSVC)
525# define QT_FASTCALL __fastcall
526# else
527# define QT_FASTCALL
528# endif
529#else
530# define QT_FASTCALL
531#endif
532
533// enable gcc warnings for printf-style functions
534#if defined(Q_CC_GNU) && !defined(__INSURE__)
535# if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
536# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
537 __attribute__((format(gnu_printf, (A), (B))))
538# else
539# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
540 __attribute__((format(printf, (A), (B))))
541# endif
542#else
543# define Q_ATTRIBUTE_FORMAT_PRINTF(A, B)
544#endif
545
546#ifdef Q_CC_MSVC
547# define Q_NEVER_INLINE __declspec(noinline)
548# define Q_ALWAYS_INLINE __forceinline
549#elif defined(Q_CC_GNU)
550# define Q_NEVER_INLINE __attribute__((noinline))
551# define Q_ALWAYS_INLINE inline __attribute__((always_inline))
552#else
553# define Q_NEVER_INLINE
554# define Q_ALWAYS_INLINE inline
555#endif
556
557#if defined(Q_CC_GNU) && defined(Q_OS_WIN)
558# define QT_INIT_METAOBJECT __attribute__((init_priority(101)))
559#else
560# define QT_INIT_METAOBJECT
561#endif
562
563//defines the type for the WNDPROC on windows
564//the alignment needs to be forced for sse2 to not crash with mingw
565#if defined(Q_OS_WIN)
566# if defined(Q_CC_MINGW) && !defined(Q_OS_WIN64)
567# define QT_ENSURE_STACK_ALIGNED_FOR_SSE __attribute__ ((force_align_arg_pointer))
568# else
569# define QT_ENSURE_STACK_ALIGNED_FOR_SSE
570# endif
571# define QT_WIN_CALLBACK CALLBACK QT_ENSURE_STACK_ALIGNED_FOR_SSE
572#endif
573
574typedef int QNoImplicitBoolCast;
575
576/*
577 Utility macros and inline functions
578*/
579
580template <typename T>
581Q_DECL_CONSTEXPR inline T qAbs(const T &t) { return t >= 0 ? t : -t; }
582
583Q_DECL_CONSTEXPR inline int qRound(double d)
584{ return d >= 0.0 ? int(d + 0.5) : int(d - double(int(d-1)) + 0.5) + int(d-1); }
585Q_DECL_CONSTEXPR inline int qRound(float d)
586{ return d >= 0.0f ? int(d + 0.5f) : int(d - float(int(d-1)) + 0.5f) + int(d-1); }
587
588Q_DECL_CONSTEXPR inline qint64 qRound64(double d)
589{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - double(qint64(d-1)) + 0.5) + qint64(d-1); }
590Q_DECL_CONSTEXPR inline qint64 qRound64(float d)
591{ return d >= 0.0f ? qint64(d + 0.5f) : qint64(d - float(qint64(d-1)) + 0.5f) + qint64(d-1); }
592
593template <typename T>
594Q_DECL_CONSTEXPR inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; }
595template <typename T>
596Q_DECL_CONSTEXPR inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; }
597template <typename T>
598Q_DECL_CONSTEXPR inline const T &qBound(const T &min, const T &val, const T &max)
599{ return qMax(min, qMin(max, val)); }
600
601#ifndef Q_FORWARD_DECLARE_OBJC_CLASS
602# ifdef __OBJC__
603# define Q_FORWARD_DECLARE_OBJC_CLASS(classname) @class classname
604# else
605# define Q_FORWARD_DECLARE_OBJC_CLASS(classname) typedef struct objc_object classname
606# endif
607#endif
608#ifndef Q_FORWARD_DECLARE_CF_TYPE
609# define Q_FORWARD_DECLARE_CF_TYPE(type) typedef const struct __ ## type * type ## Ref
610#endif
611#ifndef Q_FORWARD_DECLARE_MUTABLE_CF_TYPE
612# define Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) typedef struct __ ## type * type ## Ref
613#endif
614#ifndef Q_FORWARD_DECLARE_CG_TYPE
615#define Q_FORWARD_DECLARE_CG_TYPE(type) typedef const struct type *type ## Ref;
616#endif
617#ifndef Q_FORWARD_DECLARE_MUTABLE_CG_TYPE
618#define Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(type) typedef struct type *type ## Ref;
619#endif
620
621#ifdef Q_OS_DARWIN
622# define QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, tvos, watchos) \
623 ((defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && macos != __MAC_NA && __MAC_OS_X_VERSION_MAX_ALLOWED >= macos) || \
624 (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && ios != __IPHONE_NA && __IPHONE_OS_VERSION_MAX_ALLOWED >= ios) || \
625 (defined(__TV_OS_VERSION_MAX_ALLOWED) && tvos != __TVOS_NA && __TV_OS_VERSION_MAX_ALLOWED >= tvos) || \
626 (defined(__WATCH_OS_VERSION_MAX_ALLOWED) && watchos != __WATCHOS_NA && __WATCH_OS_VERSION_MAX_ALLOWED >= watchos))
627
628# define QT_DARWIN_DEPLOYMENT_TARGET_BELOW(macos, ios, tvos, watchos) \
629 ((defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && macos != __MAC_NA && __MAC_OS_X_VERSION_MIN_REQUIRED < macos) || \
630 (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && ios != __IPHONE_NA && __IPHONE_OS_VERSION_MIN_REQUIRED < ios) || \
631 (defined(__TV_OS_VERSION_MIN_REQUIRED) && tvos != __TVOS_NA && __TV_OS_VERSION_MIN_REQUIRED < tvos) || \
632 (defined(__WATCH_OS_VERSION_MIN_REQUIRED) && watchos != __WATCHOS_NA && __WATCH_OS_VERSION_MIN_REQUIRED < watchos))
633
634# define QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios) \
635 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, __TVOS_NA, __WATCHOS_NA)
636# define QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos) \
637 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, __IPHONE_NA, __TVOS_NA, __WATCHOS_NA)
638# define QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(ios) \
639 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, ios, __TVOS_NA, __WATCHOS_NA)
640# define QT_TVOS_PLATFORM_SDK_EQUAL_OR_ABOVE(tvos) \
641 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, __IPHONE_NA, tvos, __WATCHOS_NA)
642# define QT_WATCHOS_PLATFORM_SDK_EQUAL_OR_ABOVE(watchos) \
643 QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, __IPHONE_NA, __TVOS_NA, watchos)
644
645# define QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(macos, ios) \
646 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(macos, ios, __TVOS_NA, __WATCHOS_NA)
647# define QT_MACOS_DEPLOYMENT_TARGET_BELOW(macos) \
648 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(macos, __IPHONE_NA, __TVOS_NA, __WATCHOS_NA)
649# define QT_IOS_DEPLOYMENT_TARGET_BELOW(ios) \
650 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(__MAC_NA, ios, __TVOS_NA, __WATCHOS_NA)
651# define QT_TVOS_DEPLOYMENT_TARGET_BELOW(tvos) \
652 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(__MAC_NA, __IPHONE_NA, tvos, __WATCHOS_NA)
653# define QT_WATCHOS_DEPLOYMENT_TARGET_BELOW(watchos) \
654 QT_DARWIN_DEPLOYMENT_TARGET_BELOW(__MAC_NA, __IPHONE_NA, __TVOS_NA, watchos)
655
656// Compatibility synonyms, do not use
657# define QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(osx, ios) QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(osx, ios)
658# define QT_MAC_DEPLOYMENT_TARGET_BELOW(osx, ios) QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(osx, ios)
659# define QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(osx) QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(osx)
660# define QT_OSX_DEPLOYMENT_TARGET_BELOW(osx) QT_MACOS_DEPLOYMENT_TARGET_BELOW(osx)
661
662// Implemented in qcore_mac_objc.mm
663class Q_CORE_EXPORT QMacAutoReleasePool
664{
665public:
666 QMacAutoReleasePool();
667 ~QMacAutoReleasePool();
668private:
669 Q_DISABLE_COPY(QMacAutoReleasePool)
670 void *pool;
671};
672
673#else
674
675#define QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, tvos, watchos) (0)
676#define QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios) (0)
677#define QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(macos) (0)
678#define QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(ios) (0)
679#define QT_TVOS_PLATFORM_SDK_EQUAL_OR_ABOVE(tvos) (0)
680#define QT_WATCHOS_PLATFORM_SDK_EQUAL_OR_ABOVE(watchos) (0)
681
682#define QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(osx, ios) (0)
683#define QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(osx) (0)
684
685#endif // Q_OS_DARWIN
686
687/*
688 Data stream functions are provided by many classes (defined in qdatastream.h)
689*/
690
691class QDataStream;
692
693inline void qt_noop(void) {}
694
695/* These wrap try/catch so we can switch off exceptions later.
696
697 Beware - do not use more than one QT_CATCH per QT_TRY, and do not use
698 the exception instance in the catch block.
699 If you can't live with those constraints, don't use these macros.
700 Use the QT_NO_EXCEPTIONS macro to protect your code instead.
701*/
702
703#if !defined(QT_NO_EXCEPTIONS)
704# if !defined(Q_MOC_RUN)
705# if (defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) && !QT_HAS_FEATURE(cxx_exceptions)) || \
706 (defined(Q_CC_GNU) && !defined(__EXCEPTIONS))
707# define QT_NO_EXCEPTIONS
708# endif
709# elif defined(QT_BOOTSTRAPPED)
710# define QT_NO_EXCEPTIONS
711# endif
712#endif
713
714#ifdef QT_NO_EXCEPTIONS
715# define QT_TRY if (true)
716# define QT_CATCH(A) else
717# define QT_THROW(A) qt_noop()
718# define QT_RETHROW qt_noop()
719# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
720#else
721# define QT_TRY try
722# define QT_CATCH(A) catch (A)
723# define QT_THROW(A) throw A
724# define QT_RETHROW throw
725Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() Q_DECL_NOTHROW;
726# ifdef Q_COMPILER_NOEXCEPT
727# define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false)
728# else
729# define QT_TERMINATE_ON_EXCEPTION(expr) do { try { expr; } catch (...) { qTerminate(); } } while (false)
730# endif
731#endif
732
733Q_CORE_EXPORT Q_DECL_CONST_FUNCTION bool qSharedBuild() Q_DECL_NOTHROW;
734
735#ifndef Q_OUTOFLINE_TEMPLATE
736# define Q_OUTOFLINE_TEMPLATE
737#endif
738#ifndef Q_INLINE_TEMPLATE
739# define Q_INLINE_TEMPLATE inline
740#endif
741
742/*
743 Debugging and error handling
744*/
745
746#if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG)
747# define QT_DEBUG
748#endif
749
750// QtPrivate::asString defined in qstring.h
751#ifndef qPrintable
752# define qPrintable(string) QtPrivate::asString(string).toLocal8Bit().constData()
753#endif
754
755#ifndef qUtf8Printable
756# define qUtf8Printable(string) QtPrivate::asString(string).toUtf8().constData()
757#endif
758
759/*
760 Wrap QString::utf16() with enough casts to allow passing it
761 to QString::asprintf("%ls") without warnings.
762*/
763#ifndef qUtf16Printable
764# define qUtf16Printable(string) \
765 static_cast<const wchar_t*>(static_cast<const void*>(QString(string).utf16()))
766#endif
767
768class QString;
769Q_DECL_COLD_FUNCTION
770Q_CORE_EXPORT QString qt_error_string(int errorCode = -1);
771
772#ifndef Q_CC_MSVC
773Q_NORETURN
774#endif
775Q_DECL_COLD_FUNCTION
776Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) Q_DECL_NOTHROW;
777
778#if !defined(Q_ASSERT)
779# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
780# define Q_ASSERT(cond) static_cast<void>(false && (cond))
781# else
782# define Q_ASSERT(cond) ((cond) ? static_cast<void>(0) : qt_assert(#cond, __FILE__, __LINE__))
783# endif
784#endif
785
786#if defined(QT_NO_DEBUG) && !defined(QT_PAINT_DEBUG)
787#define QT_NO_PAINT_DEBUG
788#endif
789
790#ifndef Q_CC_MSVC
791Q_NORETURN
792#endif
793Q_DECL_COLD_FUNCTION
794Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line) Q_DECL_NOTHROW;
795
796#if !defined(Q_ASSERT_X)
797# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
798# define Q_ASSERT_X(cond, where, what) static_cast<void>(false && (cond))
799# else
800# define Q_ASSERT_X(cond, where, what) ((cond) ? static_cast<void>(0) : qt_assert_x(where, what, __FILE__, __LINE__))
801# endif
802#endif
803
804Q_NORETURN Q_CORE_EXPORT void qt_check_pointer(const char *, int) Q_DECL_NOTHROW;
805Q_DECL_COLD_FUNCTION
806Q_CORE_EXPORT void qBadAlloc();
807
808#ifdef QT_NO_EXCEPTIONS
809# if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
810# define Q_CHECK_PTR(p) qt_noop()
811# else
812# define Q_CHECK_PTR(p) do {if (!(p)) qt_check_pointer(__FILE__,__LINE__);} while (false)
813# endif
814#else
815# define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (false)
816#endif
817
818template <typename T>
819inline T *q_check_ptr(T *p) { Q_CHECK_PTR(p); return p; }
820
821typedef void (*QFunctionPointer)();
822
823#if !defined(Q_UNIMPLEMENTED)
824# define Q_UNIMPLEMENTED() qWarning("Unimplemented code.")
825#endif
826
827Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool qFuzzyCompare(double p1, double p2)
828{
829 return (qAbs(p1 - p2) * 1000000000000. <= qMin(qAbs(p1), qAbs(p2)));
830}
831
832Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool qFuzzyCompare(float p1, float p2)
833{
834 return (qAbs(p1 - p2) * 100000.f <= qMin(qAbs(p1), qAbs(p2)));
835}
836
837Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool qFuzzyIsNull(double d)
838{
839 return qAbs(d) <= 0.000000000001;
840}
841
842Q_REQUIRED_RESULT Q_DECL_CONSTEXPR static inline Q_DECL_UNUSED bool qFuzzyIsNull(float f)
843{
844 return qAbs(f) <= 0.00001f;
845}
846
847/*
848 This function tests a double for a null value. It doesn't
849 check whether the actual value is 0 or close to 0, but whether
850 it is binary 0, disregarding sign.
851*/
852Q_REQUIRED_RESULT static inline Q_DECL_UNUSED bool qIsNull(double d)
853{
854 union U {
855 double d;
856 quint64 u;
857 };
858 U val;
859 val.d = d;
860 return (val.u & Q_UINT64_C(0x7fffffffffffffff)) == 0;
861}
862
863/*
864 This function tests a float for a null value. It doesn't
865 check whether the actual value is 0 or close to 0, but whether
866 it is binary 0, disregarding sign.
867*/
868Q_REQUIRED_RESULT static inline Q_DECL_UNUSED bool qIsNull(float f)
869{
870 union U {
871 float f;
872 quint32 u;
873 };
874 U val;
875 val.f = f;
876 return (val.u & 0x7fffffff) == 0;
877}
878
879/*
880 Compilers which follow outdated template instantiation rules
881 require a class to have a comparison operator to exist when
882 a QList of this type is instantiated. It's not actually
883 used in the list, though. Hence the dummy implementation.
884 Just in case other code relies on it we better trigger a warning
885 mandating a real implementation.
886*/
887
888#ifdef Q_FULL_TEMPLATE_INSTANTIATION
889# define Q_DUMMY_COMPARISON_OPERATOR(C) \
890 bool operator==(const C&) const { \
891 qWarning(#C"::operator==(const "#C"&) was called"); \
892 return false; \
893 }
894#else
895
896# define Q_DUMMY_COMPARISON_OPERATOR(C)
897#endif
898
899namespace QtPrivate
900{
901namespace SwapExceptionTester { // insulate users from the "using std::swap" below
902 using std::swap; // import std::swap
903 template <typename T>
904 void checkSwap(T &t)
905 Q_DECL_NOEXCEPT_EXPR(noexcept(swap(t, t)));
906 // declared, but not implemented (only to be used in unevaluated contexts (noexcept operator))
907}
908} // namespace QtPrivate
909
910template <typename T>
911inline void qSwap(T &value1, T &value2)
912 Q_DECL_NOEXCEPT_EXPR(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1)))
913{
914 using std::swap;
915 swap(value1, value2);
916}
917
918#if QT_DEPRECATED_SINCE(5, 0)
919Q_CORE_EXPORT QT_DEPRECATED void *qMalloc(size_t size) Q_ALLOC_SIZE(1);
920Q_CORE_EXPORT QT_DEPRECATED void qFree(void *ptr);
921Q_CORE_EXPORT QT_DEPRECATED void *qRealloc(void *ptr, size_t size) Q_ALLOC_SIZE(2);
922Q_CORE_EXPORT QT_DEPRECATED void *qMemCopy(void *dest, const void *src, size_t n);
923Q_CORE_EXPORT QT_DEPRECATED void *qMemSet(void *dest, int c, size_t n);
924#endif
925Q_CORE_EXPORT void *qMallocAligned(size_t size, size_t alignment) Q_ALLOC_SIZE(1);
926Q_CORE_EXPORT void *qReallocAligned(void *ptr, size_t size, size_t oldsize, size_t alignment) Q_ALLOC_SIZE(2);
927Q_CORE_EXPORT void qFreeAligned(void *ptr);
928
929
930/*
931 Avoid some particularly useless warnings from some stupid compilers.
932 To get ALL C++ compiler warnings, define QT_CC_WARNINGS or comment out
933 the line "#define QT_NO_WARNINGS".
934*/
935#if !defined(QT_CC_WARNINGS)
936# define QT_NO_WARNINGS
937#endif
938#if defined(QT_NO_WARNINGS)
939# if defined(Q_CC_MSVC)
940QT_WARNING_DISABLE_MSVC(4251) /* class 'type' needs to have dll-interface to be used by clients of class 'type2' */
941QT_WARNING_DISABLE_MSVC(4244) /* conversion from 'type1' to 'type2', possible loss of data */
942QT_WARNING_DISABLE_MSVC(4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */
943QT_WARNING_DISABLE_MSVC(4514) /* unreferenced inline function has been removed */
944QT_WARNING_DISABLE_MSVC(4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */
945QT_WARNING_DISABLE_MSVC(4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */
946QT_WARNING_DISABLE_MSVC(4706) /* assignment within conditional expression */
947QT_WARNING_DISABLE_MSVC(4355) /* 'this' : used in base member initializer list */
948QT_WARNING_DISABLE_MSVC(4710) /* function not inlined */
949QT_WARNING_DISABLE_MSVC(4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc */
950# elif defined(Q_CC_BOR)
951# pragma option -w-inl
952# pragma option -w-aus
953# pragma warn -inl
954# pragma warn -pia
955# pragma warn -ccc
956# pragma warn -rch
957# pragma warn -sig
958# endif
959#endif
960
961// this adds const to non-const objects (like std::as_const)
962template <typename T>
963Q_DECL_CONSTEXPR typename std::add_const<T>::type &qAsConst(T &t) Q_DECL_NOTHROW { return t; }
964// prevent rvalue arguments:
965template <typename T>
966void qAsConst(const T &&) Q_DECL_EQ_DELETE;
967
968#ifndef QT_NO_FOREACH
969
970namespace QtPrivate {
971
972template <typename T>
973class QForeachContainer {
974 Q_DISABLE_COPY(QForeachContainer)
975public:
976 QForeachContainer(const T &t) : c(t), i(qAsConst(c).begin()), e(qAsConst(c).end()) {}
977 QForeachContainer(T &&t) : c(std::move(t)), i(qAsConst(c).begin()), e(qAsConst(c).end()) {}
978
979 QForeachContainer(QForeachContainer &&other)
980 : c(std::move(other.c)),
981 i(qAsConst(c).begin()),
982 e(qAsConst(c).end()),
983 control(std::move(other.control))
984 {
985 }
986
987 QForeachContainer &operator=(QForeachContainer &&other)
988 {
989 c = std::move(other.c);
990 i = qAsConst(c).begin();
991 e = qAsConst(c).end();
992 control = std::move(other.control);
993 return *this;
994 }
995
996 T c;
997 typename T::const_iterator i, e;
998 int control = 1;
999};
1000
1001template<typename T>
1002QForeachContainer<typename std::decay<T>::type> qMakeForeachContainer(T &&t)
1003{
1004 return QForeachContainer<typename std::decay<T>::type>(std::forward<T>(t));
1005}
1006
1007}
1008// Explanation of the control word:
1009// - it's initialized to 1
1010// - that means both the inner and outer loops start
1011// - if there were no breaks, at the end of the inner loop, it's set to 0, which
1012// causes it to exit (the inner loop is run exactly once)
1013// - at the end of the outer loop, it's inverted, so it becomes 1 again, allowing
1014// the outer loop to continue executing
1015// - if there was a break inside the inner loop, it will exit with control still
1016// set to 1; in that case, the outer loop will invert it to 0 and will exit too
1017#define Q_FOREACH(variable, container) \
1018for (auto _container_ = QtPrivate::qMakeForeachContainer(container); \
1019 _container_.control && _container_.i != _container_.e; \
1020 ++_container_.i, _container_.control ^= 1) \
1021 for (variable = *_container_.i; _container_.control; _container_.control = 0)
1022
1023#endif // QT_NO_FOREACH
1024
1025#define Q_FOREVER for(;;)
1026#ifndef QT_NO_KEYWORDS
1027# ifndef QT_NO_FOREACH
1028# ifndef foreach
1029# define foreach Q_FOREACH
1030# endif
1031# endif // QT_NO_FOREACH
1032# ifndef forever
1033# define forever Q_FOREVER
1034# endif
1035#endif
1036
1037template <typename T> inline T *qGetPtrHelper(T *ptr) { return ptr; }
1038template <typename Ptr> inline auto qGetPtrHelper(const Ptr &ptr) -> decltype(ptr.operator->()) { return ptr.operator->(); }
1039
1040#define Q_DECLARE_PRIVATE(Class) \
1041 inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \
1042 inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \
1043 friend class Class##Private;
1044
1045#define Q_DECLARE_PRIVATE_D(Dptr, Class) \
1046 inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(Dptr)); } \
1047 inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(Dptr)); } \
1048 friend class Class##Private;
1049
1050#define Q_DECLARE_PUBLIC(Class) \
1051 inline Class* q_func() { return static_cast<Class *>(q_ptr); } \
1052 inline const Class* q_func() const { return static_cast<const Class *>(q_ptr); } \
1053 friend class Class;
1054
1055#define Q_D(Class) Class##Private * const d = d_func()
1056#define Q_Q(Class) Class * const q = q_func()
1057
1058#define QT_TR_NOOP(x) x
1059#define QT_TR_NOOP_UTF8(x) x
1060#define QT_TRANSLATE_NOOP(scope, x) x
1061#define QT_TRANSLATE_NOOP_UTF8(scope, x) x
1062#define QT_TRANSLATE_NOOP3(scope, x, comment) {x, comment}
1063#define QT_TRANSLATE_NOOP3_UTF8(scope, x, comment) {x, comment}
1064
1065#ifndef QT_NO_TRANSLATION // ### Qt6: This should enclose the NOOPs above
1066
1067#define QT_TR_N_NOOP(x) x
1068#define QT_TRANSLATE_N_NOOP(scope, x) x
1069#define QT_TRANSLATE_N_NOOP3(scope, x, comment) {x, comment}
1070
1071// Defined in qcoreapplication.cpp
1072// The better name qTrId() is reserved for an upcoming function which would
1073// return a much more powerful QStringFormatter instead of a QString.
1074Q_CORE_EXPORT QString qtTrId(const char *id, int n = -1);
1075
1076#define QT_TRID_NOOP(id) id
1077
1078#endif // QT_NO_TRANSLATION
1079
1080/*
1081 When RTTI is not available, define this macro to force any uses of
1082 dynamic_cast to cause a compile failure.
1083*/
1084
1085#if defined(QT_NO_DYNAMIC_CAST) && !defined(dynamic_cast)
1086# define dynamic_cast QT_PREPEND_NAMESPACE(qt_dynamic_cast_check)
1087
1088 template<typename T, typename X>
1089 T qt_dynamic_cast_check(X, T* = 0)
1090 { return T::dynamic_cast_will_always_fail_because_rtti_is_disabled; }
1091#endif
1092
1093
1094#ifdef Q_QDOC
1095
1096// Just for documentation generation
1097template<typename T>
1098auto qOverload(T functionPointer);
1099template<typename T>
1100auto qConstOverload(T memberFunctionPointer);
1101template<typename T>
1102auto qNonConstOverload(T memberFunctionPointer);
1103
1104#elif defined(Q_COMPILER_VARIADIC_TEMPLATES)
1105
1106template <typename... Args>
1107struct QNonConstOverload
1108{
1109 template <typename R, typename T>
1110 Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr)
1111 { return ptr; }
1112
1113 template <typename R, typename T>
1114 static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr)
1115 { return ptr; }
1116};
1117
1118template <typename... Args>
1119struct QConstOverload
1120{
1121 template <typename R, typename T>
1122 Q_DECL_CONSTEXPR auto operator()(R (T::*ptr)(Args...) const) const Q_DECL_NOTHROW -> decltype(ptr)
1123 { return ptr; }
1124
1125 template <typename R, typename T>
1126 static Q_DECL_CONSTEXPR auto of(R (T::*ptr)(Args...) const) Q_DECL_NOTHROW -> decltype(ptr)
1127 { return ptr; }
1128};
1129
1130template <typename... Args>
1131struct QOverload : QConstOverload<Args...>, QNonConstOverload<Args...>
1132{
1133 using QConstOverload<Args...>::of;
1134 using QConstOverload<Args...>::operator();
1135 using QNonConstOverload<Args...>::of;
1136 using QNonConstOverload<Args...>::operator();
1137
1138 template <typename R>
1139 Q_DECL_CONSTEXPR auto operator()(R (*ptr)(Args...)) const Q_DECL_NOTHROW -> decltype(ptr)
1140 { return ptr; }
1141
1142 template <typename R>
1143 static Q_DECL_CONSTEXPR auto of(R (*ptr)(Args...)) Q_DECL_NOTHROW -> decltype(ptr)
1144 { return ptr; }
1145};
1146
1147#if defined(__cpp_variable_templates) && __cpp_variable_templates >= 201304 // C++14
1148template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QOverload<Args...> qOverload = {};
1149template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QConstOverload<Args...> qConstOverload = {};
1150template <typename... Args> Q_CONSTEXPR Q_DECL_UNUSED QNonConstOverload<Args...> qNonConstOverload = {};
1151#endif
1152
1153#endif
1154
1155
1156class QByteArray;
1157Q_CORE_EXPORT QByteArray qgetenv(const char *varName);
1158// need it as two functions because QString is only forward-declared here
1159Q_CORE_EXPORT QString qEnvironmentVariable(const char *varName);
1160Q_CORE_EXPORT QString qEnvironmentVariable(const char *varName, const QString &defaultValue);
1161Q_CORE_EXPORT bool qputenv(const char *varName, const QByteArray& value);
1162Q_CORE_EXPORT bool qunsetenv(const char *varName);
1163
1164Q_CORE_EXPORT bool qEnvironmentVariableIsEmpty(const char *varName) Q_DECL_NOEXCEPT;
1165Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) Q_DECL_NOEXCEPT;
1166Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) Q_DECL_NOEXCEPT;
1167
1168inline int qIntCast(double f) { return int(f); }
1169inline int qIntCast(float f) { return int(f); }
1170
1171/*
1172 Reentrant versions of basic rand() functions for random number generation
1173*/
1174Q_CORE_EXPORT void qsrand(uint seed);
1175Q_CORE_EXPORT int qrand();
1176
1177#define QT_MODULE(x)
1178
1179#if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && \
1180 (!defined(__PIC__) || (defined(__PIE__) && defined(Q_CC_GNU) && Q_CC_GNU >= 500))
1181# error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
1182 "Compile your code with -fPIC (-fPIE is not enough)."
1183#endif
1184
1185namespace QtPrivate {
1186//like std::enable_if
1187template <bool B, typename T = void> struct QEnableIf;
1188template <typename T> struct QEnableIf<true, T> { typedef T Type; };
1189
1190template <bool B, typename T, typename F> struct QConditional { typedef T Type; };
1191template <typename T, typename F> struct QConditional<false, T, F> { typedef F Type; };
1192}
1193
1194QT_END_NAMESPACE
1195
1196// We need to keep QTypeInfo, QSysInfo, QFlags, qDebug & family in qglobal.h for compatibility with Qt 4.
1197// Be careful when changing the order of these files.
1198#include <QtCore/qtypeinfo.h>
1199#include <QtCore/qsysinfo.h>
1200#include <QtCore/qlogging.h>
1201
1202#include <QtCore/qflags.h>
1203
1204#include <QtCore/qatomic.h>
1205#include <QtCore/qglobalstatic.h>
1206#include <QtCore/qnumeric.h>
1207#include <QtCore/qversiontagging.h>
1208
1209#endif /* __cplusplus */
1210#endif /* !__ASSEMBLER__ */
1211
1212#endif /* QGLOBAL_H */
1213