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