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