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