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

source code of qtbase/src/corelib/global/qglobal.h