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