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