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