QFlags<>: let the compiler generate copy ctor/op=
[profile/ivi/qtbase.git] / src / corelib / global / qglobal.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QGLOBAL_H
43 #define QGLOBAL_H
44
45 #include <stddef.h>
46
47 #define QT_VERSION_STR   "5.0.0"
48 /*
49    QT_VERSION is (major << 16) + (minor << 8) + patch.
50 */
51 #define QT_VERSION 0x050000
52 /*
53    can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
54 */
55 #define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
56
57 #define QT_PACKAGEDATE_STR "YYYY-MM-DD"
58
59 #define QT_PACKAGE_TAG ""
60
61 #if !defined(QT_BUILD_MOC)
62 #include <QtCore/qconfig.h>
63 #endif
64
65
66 #include <QtCore/qsystemdetection.h>
67 #include <QtCore/qcompilerdetection.h>
68 #include <QtCore/qprocessordetection.h>
69
70 #ifdef __cplusplus
71
72 #ifndef QT_NO_STL
73 #include <algorithm>
74 #endif
75
76 #ifndef QT_NAMESPACE /* user namespace */
77
78 # define QT_PREPEND_NAMESPACE(name) ::name
79 # define QT_USE_NAMESPACE
80 # define QT_BEGIN_NAMESPACE
81 # define QT_END_NAMESPACE
82 # define QT_BEGIN_INCLUDE_NAMESPACE
83 # define QT_END_INCLUDE_NAMESPACE
84 #ifndef QT_BEGIN_MOC_NAMESPACE
85 # define QT_BEGIN_MOC_NAMESPACE
86 #endif
87 #ifndef QT_END_MOC_NAMESPACE
88 # define QT_END_MOC_NAMESPACE
89 #endif
90 # define QT_FORWARD_DECLARE_CLASS(name) class name;
91 # define QT_FORWARD_DECLARE_STRUCT(name) struct name;
92 # define QT_MANGLE_NAMESPACE(name) name
93
94 #else /* user namespace */
95
96 # define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
97 # define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE;
98 # define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
99 # define QT_END_NAMESPACE }
100 # define QT_BEGIN_INCLUDE_NAMESPACE }
101 # define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE {
102 #ifndef QT_BEGIN_MOC_NAMESPACE
103 # define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE
104 #endif
105 #ifndef QT_END_MOC_NAMESPACE
106 # define QT_END_MOC_NAMESPACE
107 #endif
108 # define QT_FORWARD_DECLARE_CLASS(name) \
109     QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \
110     using QT_PREPEND_NAMESPACE(name);
111
112 # define QT_FORWARD_DECLARE_STRUCT(name) \
113     QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \
114     using QT_PREPEND_NAMESPACE(name);
115
116 # define QT_MANGLE_NAMESPACE0(x) x
117 # define QT_MANGLE_NAMESPACE1(a, b) a##_##b
118 # define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b)
119 # define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \
120         QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE))
121
122 namespace QT_NAMESPACE {}
123
124 # ifndef QT_BOOTSTRAPPED
125 # ifndef QT_NO_USING_NAMESPACE
126    /*
127     This expands to a "using QT_NAMESPACE" also in _header files_.
128     It is the only way the feature can be used without too much
129     pain, but if people _really_ do not want it they can add
130     DEFINES += QT_NO_USING_NAMESPACE to their .pro files.
131     */
132    QT_USE_NAMESPACE
133 # endif
134 # endif
135
136 #endif /* user namespace */
137
138 #else /* __cplusplus */
139
140 # define QT_BEGIN_NAMESPACE
141 # define QT_END_NAMESPACE
142 # define QT_USE_NAMESPACE
143 # define QT_BEGIN_INCLUDE_NAMESPACE
144 # define QT_END_INCLUDE_NAMESPACE
145
146 #endif /* __cplusplus */
147
148 #define QT_BEGIN_HEADER
149 #define QT_END_HEADER
150
151 #if defined(Q_OS_DARWIN) && !defined(QT_LARGEFILE_SUPPORT)
152 #  define QT_LARGEFILE_SUPPORT 64
153 #endif
154
155 #ifndef Q_PACKED
156 #  define Q_PACKED
157 #  undef Q_NO_PACKED_REFERENCE
158 #endif
159
160 #ifndef Q_LIKELY
161 #  define Q_LIKELY(x) (x)
162 #endif
163 #ifndef Q_UNLIKELY
164 #  define Q_UNLIKELY(x) (x)
165 #endif
166
167 #ifndef Q_ALLOC_SIZE
168 #  define Q_ALLOC_SIZE(x)
169 #endif
170
171 #ifndef Q_CONSTRUCTOR_FUNCTION
172 # define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \
173     namespace { \
174     static const struct AFUNC ## _ctor_class_ { \
175         inline AFUNC ## _ctor_class_() { AFUNC(); } \
176     } AFUNC ## _ctor_instance_; \
177     }
178
179 # define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC)
180 #endif
181
182 #ifndef Q_DESTRUCTOR_FUNCTION
183 # define Q_DESTRUCTOR_FUNCTION0(AFUNC) \
184     namespace { \
185     static const struct AFUNC ## _dtor_class_ { \
186         inline AFUNC ## _dtor_class_() { } \
187         inline ~ AFUNC ## _dtor_class_() { AFUNC(); } \
188     } AFUNC ## _dtor_instance_; \
189     }
190 # define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC)
191 #endif
192
193 #ifndef Q_REQUIRED_RESULT
194 #  if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
195 #    define Q_REQUIRED_RESULT __attribute__ ((warn_unused_result))
196 #  else
197 #    define Q_REQUIRED_RESULT
198 #  endif
199 #endif
200
201 QT_BEGIN_HEADER
202 QT_BEGIN_NAMESPACE
203
204 /*
205    Size-dependent types (architechture-dependent byte order)
206
207    Make sure to update QMetaType when changing these typedefs
208 */
209
210 typedef signed char qint8;         /* 8 bit signed */
211 typedef unsigned char quint8;      /* 8 bit unsigned */
212 typedef short qint16;              /* 16 bit signed */
213 typedef unsigned short quint16;    /* 16 bit unsigned */
214 typedef int qint32;                /* 32 bit signed */
215 typedef unsigned int quint32;      /* 32 bit unsigned */
216 #if defined(Q_OS_WIN) && !defined(Q_CC_GNU)
217 #  define Q_INT64_C(c) c ## i64    /* signed 64 bit constant */
218 #  define Q_UINT64_C(c) c ## ui64   /* unsigned 64 bit constant */
219 typedef __int64 qint64;            /* 64 bit signed */
220 typedef unsigned __int64 quint64;  /* 64 bit unsigned */
221 #else
222 #  define Q_INT64_C(c) static_cast<long long>(c ## LL)     /* signed 64 bit constant */
223 #  define Q_UINT64_C(c) static_cast<unsigned long long>(c ## ULL) /* unsigned 64 bit constant */
224 typedef long long qint64;           /* 64 bit signed */
225 typedef unsigned long long quint64; /* 64 bit unsigned */
226 #endif
227
228 typedef qint64 qlonglong;
229 typedef quint64 qulonglong;
230
231 #ifndef QT_POINTER_SIZE
232 #  if defined(Q_OS_WIN64)
233 #   define QT_POINTER_SIZE 8
234 #  elif defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
235 #   define QT_POINTER_SIZE 4
236 #  endif
237 #endif
238
239 #define Q_INIT_RESOURCE_EXTERN(name) \
240     extern int QT_MANGLE_NAMESPACE(qInitResources_ ## name) ();
241
242 #define Q_INIT_RESOURCE(name) \
243     do { extern int QT_MANGLE_NAMESPACE(qInitResources_ ## name) ();       \
244         QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); } while (0)
245 #define Q_CLEANUP_RESOURCE(name) \
246     do { extern int QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) ();    \
247         QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); } while (0)
248
249 #if defined(__cplusplus)
250
251 /*
252   quintptr and qptrdiff is guaranteed to be the same size as a pointer, i.e.
253
254       sizeof(void *) == sizeof(quintptr)
255       && sizeof(void *) == sizeof(qptrdiff)
256 */
257 template <int> struct QIntegerForSize;
258 template <>    struct QIntegerForSize<1> { typedef quint8  Unsigned; typedef qint8  Signed; };
259 template <>    struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
260 template <>    struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
261 template <>    struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
262 template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
263 typedef QIntegerForSizeof<void*>::Unsigned quintptr;
264 typedef QIntegerForSizeof<void*>::Signed qptrdiff;
265 typedef qptrdiff qintptr;
266
267 /*
268    Useful type definitions for Qt
269 */
270
271 QT_BEGIN_INCLUDE_NAMESPACE
272 typedef unsigned char uchar;
273 typedef unsigned short ushort;
274 typedef unsigned int uint;
275 typedef unsigned long ulong;
276 QT_END_INCLUDE_NAMESPACE
277
278 /*
279    Constant bool values
280 */
281
282 #ifndef QT_LINUXBASE /* the LSB defines TRUE and FALSE for us */
283 #  ifndef TRUE
284 #   define TRUE true
285 #   define FALSE false
286 #  endif
287 #endif
288
289 /*
290    Proper for-scoping in MIPSpro CC
291 */
292 #ifndef QT_NO_KEYWORDS
293 #  if defined(Q_CC_MIPS) || (defined(Q_CC_HPACC) && defined(__ia64))
294 #    define for if(0){}else for
295 #  endif
296 #endif
297
298 /*
299    Workaround for static const members on MSVC++.
300 */
301
302 #if defined(Q_CC_MSVC)
303 #  define QT_STATIC_CONST static
304 #  define QT_STATIC_CONST_IMPL
305 #else
306 #  define QT_STATIC_CONST static const
307 #  define QT_STATIC_CONST_IMPL const
308 #endif
309
310 /*
311    Warnings and errors when using deprecated methods
312 */
313 #if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && (__GNUC__ - 0 > 3 || (__GNUC__ - 0 == 3 && __GNUC_MINOR__ - 0 >= 2))) || defined(Q_CC_RVCT)
314 #  define Q_DECL_DEPRECATED __attribute__ ((__deprecated__))
315 #elif defined(Q_CC_MSVC)
316 #  define Q_DECL_DEPRECATED __declspec(deprecated)
317 #  if defined (Q_CC_INTEL)
318 #    define Q_DECL_VARIABLE_DEPRECATED
319 #  else
320 #  endif
321 #else
322 #  define Q_DECL_DEPRECATED
323 #endif
324 #ifndef Q_DECL_VARIABLE_DEPRECATED
325 #  define Q_DECL_VARIABLE_DEPRECATED Q_DECL_DEPRECATED
326 #endif
327
328 #if defined(QT_NO_DEPRECATED)
329 #  undef QT_DEPRECATED
330 #  undef QT_DEPRECATED_VARIABLE
331 #  undef QT_DEPRECATED_CONSTRUCTOR
332 #elif defined(QT_DEPRECATED_WARNINGS)
333 #  undef QT_DEPRECATED
334 #  define QT_DEPRECATED Q_DECL_DEPRECATED
335 #  undef QT_DEPRECATED_VARIABLE
336 #  define QT_DEPRECATED_VARIABLE Q_DECL_VARIABLE_DEPRECATED
337 #  undef QT_DEPRECATED_CONSTRUCTOR
338 #  define QT_DEPRECATED_CONSTRUCTOR explicit Q_DECL_CONSTRUCTOR_DEPRECATED
339 #else
340 #  undef QT_DEPRECATED
341 #  define QT_DEPRECATED
342 #  undef QT_DEPRECATED_VARIABLE
343 #  define QT_DEPRECATED_VARIABLE
344 #  undef QT_DEPRECATED_CONSTRUCTOR
345 #  define QT_DEPRECATED_CONSTRUCTOR
346 #endif
347
348 #ifndef QT_DISABLE_DEPRECATED_BEFORE
349 // ### Qt5: remember to change that to 5 when we reach feature freeze
350 #define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 9, 0)
351 #endif
352
353 /*
354     QT_DEPRECATED_SINCE(major, minor) evaluates as true if the Qt version is greater than
355     the deprecation point specified.
356
357     Use it to specify from which version of Qt a function or class has been deprecated
358
359     Example:
360         #if QT_DEPRECATED_SINCE(5,1)
361             QT_DEPRECATED void deprecatedFunction(); //function deprecated since Qt 5.1
362         #endif
363
364 */
365 #ifdef QT_DEPRECATED
366 #define QT_DEPRECATED_SINCE(major, minor) (QT_VERSION_CHECK(major, minor, 0) > QT_DISABLE_DEPRECATED_BEFORE)
367 #else
368 #define QT_DEPRECATED_SINCE(major, minor) 0
369 #endif
370
371 /* moc compats (signals/slots) */
372 #ifndef QT_MOC_COMPAT
373 #  define QT_MOC_COMPAT
374 #else
375 #  undef QT_MOC_COMPAT
376 #  define QT_MOC_COMPAT
377 #endif
378
379 #ifdef QT_ASCII_CAST_WARNINGS
380 #  define QT_ASCII_CAST_WARN Q_DECL_DEPRECATED
381 #else
382 #  define QT_ASCII_CAST_WARN
383 #endif
384
385 #if defined(__i386__) || defined(_WIN32) || defined(_WIN32_WCE)
386 #  if defined(Q_CC_GNU)
387 #if !defined(Q_CC_INTEL) && ((100*(__GNUC__ - 0) + 10*(__GNUC_MINOR__ - 0) + __GNUC_PATCHLEVEL__) >= 332)
388 #    define QT_FASTCALL __attribute__((regparm(3)))
389 #else
390 #    define QT_FASTCALL
391 #endif
392 #  elif defined(Q_CC_MSVC)
393 #    define QT_FASTCALL __fastcall
394 #  else
395 #     define QT_FASTCALL
396 #  endif
397 #else
398 #  define QT_FASTCALL
399 #endif
400
401 #ifdef Q_COMPILER_NULLPTR
402 # define Q_NULLPTR         nullptr
403 #else
404 # define Q_NULLPTR         0
405 #endif
406
407 #ifdef Q_COMPILER_DEFAULT_DELETE_MEMBERS
408 # define Q_DECL_EQ_DELETE = delete
409 #else
410 # define Q_DECL_EQ_DELETE
411 #endif
412
413 #ifdef Q_COMPILER_CONSTEXPR
414 # define Q_DECL_CONSTEXPR constexpr
415 #else
416 # define Q_DECL_CONSTEXPR
417 #endif
418
419 #ifdef Q_COMPILER_EXPLICIT_OVERRIDES
420 # define Q_DECL_OVERRIDE override
421 # define Q_DECL_FINAL final
422 #else
423 # define Q_DECL_OVERRIDE
424 # define Q_DECL_FINAL
425 #endif
426
427 //defines the type for the WNDPROC on windows
428 //the alignment needs to be forced for sse2 to not crash with mingw
429 #if defined(Q_OS_WIN)
430 #  if defined(Q_CC_MINGW)
431 #    define QT_ENSURE_STACK_ALIGNED_FOR_SSE __attribute__ ((force_align_arg_pointer))
432 #  else
433 #    define QT_ENSURE_STACK_ALIGNED_FOR_SSE
434 #  endif
435 #  define QT_WIN_CALLBACK CALLBACK QT_ENSURE_STACK_ALIGNED_FOR_SSE 
436 #endif
437
438 typedef int QNoImplicitBoolCast;
439
440 // This logic must match the one in qmetatype.h
441 #if defined(QT_COORD_TYPE)
442 typedef QT_COORD_TYPE qreal;
443 #elif defined(QT_NO_FPU) || defined(Q_PROCESSOR_ARM) || defined(Q_OS_WINCE)
444 typedef float qreal;
445 #else
446 typedef double qreal;
447 #endif
448
449 /*
450    Utility macros and inline functions
451 */
452
453 template <typename T>
454 Q_DECL_CONSTEXPR inline T qAbs(const T &t) { return t >= 0 ? t : -t; }
455
456 Q_DECL_CONSTEXPR inline int qRound(double d)
457 { return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); }
458 Q_DECL_CONSTEXPR inline int qRound(float d)
459 { return d >= 0.0f ? int(d + 0.5f) : int(d - int(d-1) + 0.5f) + int(d-1); }
460 #ifdef Q_QDOC
461 /*
462     Just for documentation generation
463 */
464 int qRound(qreal d);
465 #endif
466
467 Q_DECL_CONSTEXPR inline qint64 qRound64(double d)
468 { return d >= 0.0 ? qint64(d + 0.5) : qint64(d - double(qint64(d-1)) + 0.5) + qint64(d-1); }
469 Q_DECL_CONSTEXPR inline qint64 qRound64(float d)
470 { return d >= 0.0f ? qint64(d + 0.5f) : qint64(d - float(qint64(d-1)) + 0.5f) + qint64(d-1); }
471 #ifdef Q_QDOC
472 /*
473     Just for documentation generation
474 */
475 qint64 qRound64(qreal d);
476 #endif
477
478 template <typename T>
479 Q_DECL_CONSTEXPR inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; }
480 template <typename T>
481 Q_DECL_CONSTEXPR inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; }
482 template <typename T>
483 Q_DECL_CONSTEXPR inline const T &qBound(const T &min, const T &val, const T &max)
484 { return qMax(min, qMin(max, val)); }
485
486 /*
487    Data stream functions are provided by many classes (defined in qdatastream.h)
488 */
489
490 class QDataStream;
491
492 #if defined(Q_OS_VXWORKS)
493 #  define QT_NO_CRASHHANDLER     // no popen
494 #  define QT_NO_PROCESS          // no exec*, no fork
495 #  define QT_NO_LPR
496 #  define QT_NO_SHAREDMEMORY     // only POSIX, no SysV and in the end...
497 #  define QT_NO_SYSTEMSEMAPHORE  // not needed at all in a flat address space
498 #endif
499
500 # include <QtCore/qfeatures.h>
501
502 #define QT_SUPPORTS(FEATURE) (!defined(QT_NO_##FEATURE))
503
504 #if defined(Q_OS_LINUX) && defined(Q_CC_RVCT)
505 #  define Q_DECL_EXPORT     __attribute__((visibility("default")))
506 #  define Q_DECL_IMPORT     __attribute__((visibility("default")))
507 #  define Q_DECL_HIDDEN     __attribute__((visibility("hidden")))
508 #endif
509
510 #ifndef Q_DECL_EXPORT
511 #  if defined(Q_OS_WIN) || defined(Q_CC_RVCT)
512 #    define Q_DECL_EXPORT __declspec(dllexport)
513 #  elif defined(QT_VISIBILITY_AVAILABLE)
514 #    define Q_DECL_EXPORT __attribute__((visibility("default")))
515 #    define Q_DECL_HIDDEN __attribute__((visibility("hidden")))
516 #  endif
517 #  ifndef Q_DECL_EXPORT
518 #    define Q_DECL_EXPORT
519 #  endif
520 #endif
521 #ifndef Q_DECL_IMPORT
522 #  if defined(Q_OS_WIN) || defined(Q_CC_RVCT)
523 #    define Q_DECL_IMPORT __declspec(dllimport)
524 #  else
525 #    define Q_DECL_IMPORT
526 #  endif
527 #endif
528 #ifndef Q_DECL_HIDDEN
529 #  define Q_DECL_HIDDEN
530 #endif
531
532
533 /*
534    Create Qt DLL if QT_DLL is defined (Windows only)
535 */
536
537 #if defined(Q_OS_WIN)
538 #  if defined(QT_NODLL)
539 #    undef QT_MAKEDLL
540 #    undef QT_DLL
541 #  elif defined(QT_MAKEDLL)        /* create a Qt DLL library */
542 #    if defined(QT_DLL)
543 #      undef QT_DLL
544 #    endif
545 #    if defined(QT_BUILD_CORE_LIB)
546 #      define Q_CORE_EXPORT Q_DECL_EXPORT
547 #    else
548 #      define Q_CORE_EXPORT Q_DECL_IMPORT
549 #    endif
550 #    if defined(QT_BUILD_GUI_LIB)
551 #      define Q_GUI_EXPORT Q_DECL_EXPORT
552 #    else
553 #      define Q_GUI_EXPORT Q_DECL_IMPORT
554 #    endif
555 #    if defined(QT_BUILD_WIDGETS_LIB)
556 #      define Q_WIDGETS_EXPORT Q_DECL_EXPORT
557 #    else
558 #      define Q_WIDGETS_EXPORT Q_DECL_IMPORT
559 #    endif
560 #    if defined(QT_BUILD_PLATFORMSUPPORT_LIB)
561 #      define Q_PLATFORMSUPPORT_EXPORT Q_DECL_EXPORT
562 #    else
563 #      define Q_PLATFORMSUPPORT_EXPORT Q_DECL_IMPORT
564 #    endif
565 #    if defined(QT_BUILD_PRINTSUPPORT_LIB)
566 #      define Q_PRINTSUPPORT_EXPORT Q_DECL_EXPORT
567 #    else
568 #      define Q_PRINTSUPPORT_EXPORT Q_DECL_IMPORT
569 #    endif
570 #    if defined(QT_BUILD_SQL_LIB)
571 #      define Q_SQL_EXPORT Q_DECL_EXPORT
572 #    else
573 #      define Q_SQL_EXPORT Q_DECL_IMPORT
574 #    endif
575 #    if defined(QT_BUILD_NETWORK_LIB)
576 #      define Q_NETWORK_EXPORT Q_DECL_EXPORT
577 #    else
578 #      define Q_NETWORK_EXPORT Q_DECL_IMPORT
579 #    endif
580 #    if defined(QT_BUILD_SVG_LIB)
581 #      define Q_SVG_EXPORT Q_DECL_EXPORT
582 #    else
583 #      define Q_SVG_EXPORT Q_DECL_IMPORT
584 #    endif
585 #    if defined(QT_BUILD_QTQUICK1_LIB)
586 #      define Q_QTQUICK1_EXPORT Q_DECL_EXPORT
587 #    else
588 #      define Q_QTQUICK1_EXPORT Q_DECL_IMPORT
589 #    endif
590 #    if defined(QT_BUILD_DECLARATIVE_LIB)
591 #      define Q_DECLARATIVE_EXPORT Q_DECL_EXPORT
592 #    else
593 #      define Q_DECLARATIVE_EXPORT Q_DECL_IMPORT
594 #    endif
595 #    if defined(QT_BUILD_OPENGL_LIB)
596 #      define Q_OPENGL_EXPORT Q_DECL_EXPORT
597 #    else
598 #      define Q_OPENGL_EXPORT Q_DECL_IMPORT
599 #    endif
600 #    if defined(QT_BUILD_MULTIMEDIA_LIB)
601 #      define Q_MULTIMEDIA_EXPORT Q_DECL_EXPORT
602 #    else
603 #      define Q_MULTIMEDIA_EXPORT Q_DECL_IMPORT
604 #    endif
605 #    if defined(QT_BUILD_OPENVG_LIB)
606 #      define Q_OPENVG_EXPORT Q_DECL_EXPORT
607 #    else
608 #      define Q_OPENVG_EXPORT Q_DECL_IMPORT
609 #    endif
610 #    if defined(QT_BUILD_XML_LIB)
611 #      define Q_XML_EXPORT Q_DECL_EXPORT
612 #    else
613 #      define Q_XML_EXPORT Q_DECL_IMPORT
614 #    endif
615 #    if defined(QT_BUILD_XMLPATTERNS_LIB)
616 #      define Q_XMLPATTERNS_EXPORT Q_DECL_EXPORT
617 #    else
618 #      define Q_XMLPATTERNS_EXPORT Q_DECL_IMPORT
619 #    endif
620 #    if defined(QT_BUILD_SCRIPT_LIB)
621 #      define Q_SCRIPT_EXPORT Q_DECL_EXPORT
622 #    else
623 #      define Q_SCRIPT_EXPORT Q_DECL_IMPORT
624 #    endif
625 #    if defined(QT_BUILD_SCRIPTTOOLS_LIB)
626 #      define Q_SCRIPTTOOLS_EXPORT Q_DECL_EXPORT
627 #    else
628 #      define Q_SCRIPTTOOLS_EXPORT Q_DECL_IMPORT
629 #    endif
630 #    if defined(QT_BUILD_CANVAS_LIB)
631 #      define Q_CANVAS_EXPORT Q_DECL_EXPORT
632 #    else
633 #      define Q_CANVAS_EXPORT Q_DECL_IMPORT
634 #    endif
635 #    if defined(QT_BUILD_COMPAT_LIB)
636 #      define Q_COMPAT_EXPORT Q_DECL_EXPORT
637 #    else
638 #      define Q_COMPAT_EXPORT Q_DECL_IMPORT
639 #    endif
640 #    if defined(QT_BUILD_DBUS_LIB)
641 #      define Q_DBUS_EXPORT Q_DECL_EXPORT
642 #    else
643 #      define Q_DBUS_EXPORT Q_DECL_IMPORT
644 #    endif
645 #    define Q_TEMPLATEDLL
646 #  elif defined(QT_DLL) /* use a Qt DLL library */
647 #    define Q_CORE_EXPORT Q_DECL_IMPORT
648 #    define Q_GUI_EXPORT Q_DECL_IMPORT
649 #    define Q_WIDGETS_EXPORT Q_DECL_IMPORT
650 #    define Q_PLATFORMSUPPORT_EXPORT Q_DECL_IMPORT
651 #    define Q_PRINTSUPPORT_EXPORT Q_DECL_IMPORT
652 #    define Q_SQL_EXPORT Q_DECL_IMPORT
653 #    define Q_NETWORK_EXPORT Q_DECL_IMPORT
654 #    define Q_SVG_EXPORT Q_DECL_IMPORT
655 #    define Q_DECLARATIVE_EXPORT Q_DECL_IMPORT
656 #    define Q_QTQUICK1_EXPORT Q_DECL_IMPORT
657 #    define Q_CANVAS_EXPORT Q_DECL_IMPORT
658 #    define Q_OPENGL_EXPORT Q_DECL_IMPORT
659 #    define Q_MULTIMEDIA_EXPORT Q_DECL_IMPORT
660 #    define Q_OPENVG_EXPORT Q_DECL_IMPORT
661 #    define Q_XML_EXPORT Q_DECL_IMPORT
662 #    define Q_XMLPATTERNS_EXPORT Q_DECL_IMPORT
663 #    define Q_SCRIPT_EXPORT Q_DECL_IMPORT
664 #    define Q_SCRIPTTOOLS_EXPORT Q_DECL_IMPORT
665 #    define Q_COMPAT_EXPORT Q_DECL_IMPORT
666 #    define Q_DBUS_EXPORT Q_DECL_IMPORT
667 #    define Q_TEMPLATEDLL
668 #  endif
669 #  define Q_NO_DECLARED_NOT_DEFINED
670 #else
671 #  if defined(Q_OS_LINUX) && defined(Q_CC_BOR)
672 #    define Q_TEMPLATEDLL
673 #    define Q_NO_DECLARED_NOT_DEFINED
674 #  endif
675 #  undef QT_MAKEDLL /* ignore these for other platforms */
676 #  undef QT_DLL
677 #endif
678
679 #if !defined(Q_CORE_EXPORT)
680 #  if defined(QT_SHARED)
681 #    define Q_CORE_EXPORT Q_DECL_EXPORT
682 #    define Q_GUI_EXPORT Q_DECL_EXPORT
683 #    define Q_WIDGETS_EXPORT Q_DECL_EXPORT
684 #    define Q_PLATFORMSUPPORT_EXPORT Q_DECL_EXPORT
685 #    define Q_PRINTSUPPORT_EXPORT Q_DECL_EXPORT
686 #    define Q_SQL_EXPORT Q_DECL_EXPORT
687 #    define Q_NETWORK_EXPORT Q_DECL_EXPORT
688 #    define Q_SVG_EXPORT Q_DECL_EXPORT
689 #    define Q_DECLARATIVE_EXPORT Q_DECL_EXPORT
690 #    define Q_QTQUICK1_EXPORT Q_DECL_EXPORT
691 #    define Q_OPENGL_EXPORT Q_DECL_EXPORT
692 #    define Q_MULTIMEDIA_EXPORT Q_DECL_EXPORT
693 #    define Q_OPENVG_EXPORT Q_DECL_EXPORT
694 #    define Q_XML_EXPORT Q_DECL_EXPORT
695 #    define Q_XMLPATTERNS_EXPORT Q_DECL_EXPORT
696 #    define Q_SCRIPT_EXPORT Q_DECL_EXPORT
697 #    define Q_SCRIPTTOOLS_EXPORT Q_DECL_EXPORT
698 #    define Q_COMPAT_EXPORT Q_DECL_EXPORT
699 #    define Q_DBUS_EXPORT Q_DECL_EXPORT
700 #  else
701 #    define Q_CORE_EXPORT
702 #    define Q_GUI_EXPORT
703 #    define Q_WIDGETS_EXPORT
704 #    define Q_PLATFORMSUPPORT_EXPORT
705 #    define Q_PRINTSUPPORT_EXPORT
706 #    define Q_SQL_EXPORT
707 #    define Q_NETWORK_EXPORT
708 #    define Q_SVG_EXPORT
709 #    define Q_DECLARATIVE_EXPORT
710 #    define Q_QTQUICK1_EXPORT
711 #    define Q_OPENGL_EXPORT
712 #    define Q_MULTIMEDIA_EXPORT
713 #    define Q_OPENVG_EXPORT
714 #    define Q_XML_EXPORT
715 #    define Q_XMLPATTERNS_EXPORT
716 #    define Q_SCRIPT_EXPORT
717 #    define Q_SCRIPTTOOLS_EXPORT
718 #    define Q_COMPAT_EXPORT
719 #    define Q_DBUS_EXPORT
720 #  endif
721 #endif
722
723 // Functions marked as Q_GUI_EXPORT_INLINE were exported and inlined by mistake.
724 // Compilers like MinGW complain that the import attribute is ignored.
725 #if defined(Q_CC_MINGW)
726 #    if defined(QT_BUILD_CORE_LIB)
727 #      define Q_CORE_EXPORT_INLINE Q_CORE_EXPORT inline
728 #    else
729 #      define Q_CORE_EXPORT_INLINE inline
730 #    endif
731 #    if defined(QT_BUILD_GUI_LIB)
732 #      define Q_GUI_EXPORT_INLINE Q_GUI_EXPORT inline
733 #    else
734 #      define Q_GUI_EXPORT_INLINE inline
735 #    endif
736 #    if defined(QT_BUILD_WIDGETS_LIB)
737 #      define Q_WIDGETS_EXPORT_INLINE Q_WIDGETS_EXPORT inline
738 #    else
739 #      define Q_WIDGETS_EXPORT_INLINE inline
740 #    endif
741 #    if defined(QT_BUILD_PLATFORMSUPPORT_LIB)
742 #      define Q_PLATFORMSUPPORT_EXPORT_INLINE Q_PLATFORMSUPPORT_EXPORT inline
743 #    else
744 #      define Q_PLATFORMSUPPORT_EXPORT_INLINE inline
745 #    endif
746 #    if defined(QT_BUILD_PRINTSUPPORT_LIB)
747 #      define Q_PRINTSUPPORT_EXPORT_INLINE Q_PRINTSUPPORT_EXPORT inline
748 #    else
749 #      define Q_PRINTSUPPORT_EXPORT_INLINE inline
750 #    endif
751 #    if defined(QT_BUILD_COMPAT_LIB)
752 #      define Q_COMPAT_EXPORT_INLINE Q_COMPAT_EXPORT inline
753 #    else
754 #      define Q_COMPAT_EXPORT_INLINE inline
755 #    endif
756 #elif defined(Q_CC_RVCT)
757 // we force RVCT not to export inlines by passing --visibility_inlines_hidden
758 // so we need to just inline it, rather than exporting and inlining
759 // note: this affects the contents of the DEF files (ie. these functions do not appear)
760 #    define Q_CORE_EXPORT_INLINE inline
761 #    define Q_GUI_EXPORT_INLINE inline
762 #    define Q_WIDGETS_EXPORT_INLINE inline
763 #    define Q_PLATFORMSUPPORT_EXPORT_INLINE inline
764 #    define Q_PRINTSUPPORT_EXPORT_INLINE inline
765 #    define Q_COMPAT_EXPORT_INLINE inline
766 #else
767 #    define Q_CORE_EXPORT_INLINE Q_CORE_EXPORT inline
768 #    define Q_GUI_EXPORT_INLINE Q_GUI_EXPORT inline
769 #    define Q_WIDGETS_EXPORT_INLINE Q_WIDGETS_EXPORT inline
770 #    define Q_PLATFORMSUPPORT_EXPORT_INLINE Q_PLATFORMSUPPORT_EXPORT inline
771 #    define Q_PRINTSUPPORT_EXPORT_INLINE Q_PRINTSUPPORT_EXPORT inline
772 #    define Q_COMPAT_EXPORT_INLINE Q_COMPAT_EXPORT inline
773 #endif
774
775 /*
776    No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols
777    for Qt's internal unit tests. If you want slower loading times and more
778    symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL.
779 */
780 #if defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN) && defined(QT_MAKEDLL)
781 #    define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
782 #elif defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN) && defined(QT_DLL)
783 #    define Q_AUTOTEST_EXPORT Q_DECL_IMPORT
784 #elif defined(QT_BUILD_INTERNAL) && !defined(Q_OS_WIN) && defined(QT_SHARED)
785 #    define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
786 #else
787 #    define Q_AUTOTEST_EXPORT
788 #endif
789
790 inline void qt_noop(void) {}
791
792 /* These wrap try/catch so we can switch off exceptions later.
793
794    Beware - do not use more than one QT_CATCH per QT_TRY, and do not use
795    the exception instance in the catch block.
796    If you can't live with those constraints, don't use these macros.
797    Use the QT_NO_EXCEPTIONS macro to protect your code instead.
798 */
799
800 #ifdef QT_BOOTSTRAPPED
801 #  define QT_NO_EXCEPTIONS
802 #endif
803 #if !defined(QT_NO_EXCEPTIONS) && defined(Q_CC_GNU) && !defined (__EXCEPTIONS) && !defined(Q_MOC_RUN)
804 #  define QT_NO_EXCEPTIONS
805 #endif
806
807 #ifdef QT_NO_EXCEPTIONS
808 #  define QT_TRY if (true)
809 #  define QT_CATCH(A) else
810 #  define QT_THROW(A) qt_noop()
811 #  define QT_RETHROW qt_noop()
812 #else
813 #  define QT_TRY try
814 #  define QT_CATCH(A) catch (A)
815 #  define QT_THROW(A) throw A
816 #  define QT_RETHROW throw
817 #endif
818
819 Q_CORE_EXPORT const char *qVersion();
820 Q_CORE_EXPORT bool qSharedBuild();
821
822 #ifndef Q_OUTOFLINE_TEMPLATE
823 #  define Q_OUTOFLINE_TEMPLATE
824 #endif
825 #ifndef Q_INLINE_TEMPLATE
826 #  define Q_INLINE_TEMPLATE inline
827 #endif
828
829 /*
830    Avoid "unused parameter" warnings
831 */
832
833 #if defined(Q_CC_INTEL) && !defined(Q_OS_WIN) || defined(Q_CC_RVCT)
834 template <typename T>
835 inline void qUnused(T &x) { (void)x; }
836 #  define Q_UNUSED(x) qUnused(x);
837 #else
838 #  define Q_UNUSED(x) (void)x;
839 #endif
840
841 /*
842    Debugging and error handling
843 */
844
845 #if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG)
846 #  define QT_DEBUG
847 #endif
848
849 #ifndef qPrintable
850 #  define qPrintable(string) QString(string).toLocal8Bit().constData()
851 #endif
852
853 class QString;
854 Q_CORE_EXPORT QString qt_error_string(int errorCode = -1);
855 Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line);
856
857 #if !defined(Q_ASSERT)
858 #  if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
859 #    define Q_ASSERT(cond) qt_noop()
860 #  else
861 #    define Q_ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop())
862 #  endif
863 #endif
864
865 #if defined(QT_NO_DEBUG) && !defined(QT_PAINT_DEBUG)
866 #define QT_NO_PAINT_DEBUG
867 #endif
868
869 Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line);
870
871 #if !defined(Q_ASSERT_X)
872 #  if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
873 #    define Q_ASSERT_X(cond, where, what) qt_noop()
874 #  else
875 #    define Q_ASSERT_X(cond, where, what) ((!(cond)) ? qt_assert_x(where, what,__FILE__,__LINE__) : qt_noop())
876 #  endif
877 #endif
878
879
880 #ifdef Q_COMPILER_STATIC_ASSERT
881 #define Q_STATIC_ASSERT(Condition) static_assert(bool(Condition), #Condition)
882 #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
883 #else
884 // Intentionally undefined
885 template <bool Test> class QStaticAssertFailure;
886 template <> class QStaticAssertFailure<true> {};
887
888 #define Q_STATIC_ASSERT_PRIVATE_JOIN(A, B) Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B)
889 #define Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) A ## B
890 #define Q_STATIC_ASSERT(Condition) \
891     enum {Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) = sizeof(QStaticAssertFailure<!!(Condition)>)}
892 #define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition)
893 #endif
894
895 Q_CORE_EXPORT void qt_check_pointer(const char *, int);
896 Q_CORE_EXPORT void qBadAlloc();
897
898 #ifdef QT_NO_EXCEPTIONS
899 #  if defined(QT_NO_DEBUG)
900 #    define Q_CHECK_PTR(p) qt_noop()
901 #  else
902 #    define Q_CHECK_PTR(p) do {if(!(p))qt_check_pointer(__FILE__,__LINE__);} while (0)
903 #  endif
904 #else
905 #  define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (0)
906 #endif
907
908 template <typename T>
909 inline T *q_check_ptr(T *p) { Q_CHECK_PTR(p); return p; }
910
911 #if (defined(Q_CC_GNU) && !defined(Q_OS_SOLARIS)) || defined(Q_CC_HPACC) || defined(Q_CC_DIAB)
912 #  define Q_FUNC_INFO __PRETTY_FUNCTION__
913 #elif defined(_MSC_VER)
914 #  define Q_FUNC_INFO __FUNCSIG__
915 #else
916 #   if defined(Q_OS_SOLARIS) || defined(Q_CC_XLC)
917 #      define Q_FUNC_INFO __FILE__ "(line number unavailable)"
918 #   else
919         /* These two macros makes it possible to turn the builtin line expander into a
920          * string literal. */
921 #       define QT_STRINGIFY2(x) #x
922 #       define QT_STRINGIFY(x) QT_STRINGIFY2(x)
923 #       define Q_FUNC_INFO __FILE__ ":" QT_STRINGIFY(__LINE__)
924 #   endif
925     /* The MIPSpro and RVCT compilers postpones macro expansion,
926        and therefore macros must be in scope when being used. */
927 #   if !defined(Q_CC_MIPS) && !defined(Q_CC_RVCT)
928 #       undef QT_STRINGIFY2
929 #       undef QT_STRINGIFY
930 #   endif
931 #endif
932
933
934 typedef void (*QFunctionPointer)();
935
936 #if !defined(Q_UNIMPLEMENTED)
937 #  define Q_UNIMPLEMENTED() qWarning("%s:%d: %s: Unimplemented code.", __FILE__, __LINE__, Q_FUNC_INFO)
938 #endif
939
940 #if defined(QT_NO_THREAD)
941
942 template <typename T>
943 class QGlobalStatic
944 {
945 public:
946     T *pointer;
947     inline QGlobalStatic(T *p) : pointer(p) { }
948     inline ~QGlobalStatic() { pointer = 0; }
949 };
950
951 #define Q_GLOBAL_STATIC(TYPE, NAME)                                  \
952     static TYPE *NAME()                                              \
953     {                                                                \
954         static TYPE thisVariable;                                    \
955         static QGlobalStatic<TYPE > thisGlobalStatic(&thisVariable); \
956         return thisGlobalStatic.pointer;                             \
957     }
958
959 #define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)                  \
960     static TYPE *NAME()                                              \
961     {                                                                \
962         static TYPE thisVariable ARGS;                               \
963         static QGlobalStatic<TYPE > thisGlobalStatic(&thisVariable); \
964         return thisGlobalStatic.pointer;                             \
965     }
966
967 #define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER)    \
968     static TYPE *NAME()                                              \
969     {                                                                \
970         static TYPE thisVariable;                                    \
971         static QGlobalStatic<TYPE > thisGlobalStatic(0);             \
972         if (!thisGlobalStatic.pointer) {                             \
973             TYPE *x = thisGlobalStatic.pointer = &thisVariable;      \
974             INITIALIZER;                                             \
975         }                                                            \
976         return thisGlobalStatic.pointer;                             \
977     }
978
979 #else
980
981 // forward declaration, since qatomic.h needs qglobal.h
982 template <typename T> class QBasicAtomicPointer;
983
984 // POD for Q_GLOBAL_STATIC
985 template <typename T>
986 class QGlobalStatic
987 {
988 public:
989     QBasicAtomicPointer<T> pointer;
990     bool destroyed;
991 };
992
993 // Created as a function-local static to delete a QGlobalStatic<T>
994 template <typename T>
995 class QGlobalStaticDeleter
996 {
997 public:
998     QGlobalStatic<T> &globalStatic;
999     QGlobalStaticDeleter(QGlobalStatic<T> &_globalStatic)
1000         : globalStatic(_globalStatic)
1001     { }
1002
1003     inline ~QGlobalStaticDeleter()
1004     {
1005         delete globalStatic.pointer.load();
1006         globalStatic.pointer.store(0);
1007         globalStatic.destroyed = true;
1008     }
1009 };
1010
1011 #define Q_GLOBAL_STATIC(TYPE, NAME)                                           \
1012     static TYPE *NAME()                                                       \
1013     {                                                                         \
1014         static QGlobalStatic<TYPE > thisGlobalStatic                          \
1015                             = { Q_BASIC_ATOMIC_INITIALIZER(0), false };       \
1016         if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { \
1017             TYPE *x = new TYPE;                                               \
1018             if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x))            \
1019                 delete x;                                                     \
1020             else                                                              \
1021                 static QGlobalStaticDeleter<TYPE > cleanup(thisGlobalStatic); \
1022         }                                                                     \
1023         return thisGlobalStatic.pointer.load();                               \
1024     }
1025
1026 #define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)                           \
1027     static TYPE *NAME()                                                       \
1028     {                                                                         \
1029         static QGlobalStatic<TYPE > thisGlobalStatic                          \
1030                             = { Q_BASIC_ATOMIC_INITIALIZER(0), false };       \
1031         if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) {       \
1032             TYPE *x = new TYPE ARGS;                                          \
1033             if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x))            \
1034                 delete x;                                                     \
1035             else                                                              \
1036                 static QGlobalStaticDeleter<TYPE > cleanup(thisGlobalStatic); \
1037         }                                                                     \
1038         return thisGlobalStatic.pointer.load();                               \
1039     }
1040
1041 #define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER)             \
1042     static TYPE *NAME()                                                       \
1043     {                                                                         \
1044         static QGlobalStatic<TYPE > thisGlobalStatic                          \
1045                             = { Q_BASIC_ATOMIC_INITIALIZER(0), false };       \
1046         if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) {       \
1047             QScopedPointer<TYPE > x(new TYPE);                                \
1048             INITIALIZER;                                                      \
1049             if (thisGlobalStatic.pointer.testAndSetOrdered(0, x.data())) {    \
1050                 static QGlobalStaticDeleter<TYPE > cleanup(thisGlobalStatic); \
1051                 x.take();                                                     \
1052             }                                                                 \
1053         }                                                                     \
1054         return thisGlobalStatic.pointer.load();                               \
1055     }
1056
1057 #endif
1058
1059 Q_DECL_CONSTEXPR static inline bool qFuzzyCompare(double p1, double p2)
1060 {
1061     return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2)));
1062 }
1063
1064 Q_DECL_CONSTEXPR static inline bool qFuzzyCompare(float p1, float p2)
1065 {
1066     return (qAbs(p1 - p2) <= 0.00001f * qMin(qAbs(p1), qAbs(p2)));
1067 }
1068
1069 /*!
1070   \internal
1071 */
1072 Q_DECL_CONSTEXPR static inline bool qFuzzyIsNull(double d)
1073 {
1074     return qAbs(d) <= 0.000000000001;
1075 }
1076
1077 /*!
1078   \internal
1079 */
1080 Q_DECL_CONSTEXPR static inline bool qFuzzyIsNull(float f)
1081 {
1082     return qAbs(f) <= 0.00001f;
1083 }
1084
1085 /*
1086    This function tests a double for a null value. It doesn't
1087    check whether the actual value is 0 or close to 0, but whether
1088    it is binary 0.
1089 */
1090 static inline bool qIsNull(double d)
1091 {
1092     union U {
1093         double d;
1094         quint64 u;
1095     };
1096     U val;
1097     val.d = d;
1098     return val.u == quint64(0);
1099 }
1100
1101 /*
1102    This function tests a float for a null value. It doesn't
1103    check whether the actual value is 0 or close to 0, but whether
1104    it is binary 0.
1105 */
1106 static inline bool qIsNull(float f)
1107 {
1108     union U {
1109         float f;
1110         quint32 u;
1111     };
1112     U val;
1113     val.f = f;
1114     return val.u == 0u;
1115 }
1116
1117 /*
1118    Compilers which follow outdated template instantiation rules
1119    require a class to have a comparison operator to exist when
1120    a QList of this type is instantiated. It's not actually
1121    used in the list, though. Hence the dummy implementation.
1122    Just in case other code relies on it we better trigger a warning
1123    mandating a real implementation.
1124 */
1125
1126 #ifdef Q_FULL_TEMPLATE_INSTANTIATION
1127 #  define Q_DUMMY_COMPARISON_OPERATOR(C) \
1128     bool operator==(const C&) const { \
1129         qWarning(#C"::operator==(const "#C"&) was called"); \
1130         return false; \
1131     }
1132 #else
1133
1134 #  define Q_DUMMY_COMPARISON_OPERATOR(C)
1135 #endif
1136
1137 template <typename T>
1138 inline void qSwap(T &value1, T &value2)
1139 {
1140 #ifdef QT_NO_STL
1141     const T t = value1;
1142     value1 = value2;
1143     value2 = t;
1144 #else
1145     using std::swap;
1146     swap(value1, value2);
1147 #endif
1148 }
1149
1150 /*
1151    These functions make it possible to use standard C++ functions with
1152    a similar name from Qt header files (especially template classes).
1153 */
1154 Q_CORE_EXPORT void *qMalloc(size_t size) Q_ALLOC_SIZE(1);
1155 Q_CORE_EXPORT void qFree(void *ptr);
1156 Q_CORE_EXPORT void *qRealloc(void *ptr, size_t size) Q_ALLOC_SIZE(2);
1157 Q_CORE_EXPORT void *qMallocAligned(size_t size, size_t alignment) Q_ALLOC_SIZE(1);
1158 Q_CORE_EXPORT void *qReallocAligned(void *ptr, size_t size, size_t oldsize, size_t alignment) Q_ALLOC_SIZE(2);
1159 Q_CORE_EXPORT void qFreeAligned(void *ptr);
1160 Q_CORE_EXPORT void *qMemCopy(void *dest, const void *src, size_t n);
1161 Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n);
1162
1163
1164 /*
1165    Avoid some particularly useless warnings from some stupid compilers.
1166    To get ALL C++ compiler warnings, define QT_CC_WARNINGS or comment out
1167    the line "#define QT_NO_WARNINGS".
1168 */
1169 #if !defined(QT_CC_WARNINGS)
1170 #  define QT_NO_WARNINGS
1171 #endif
1172 #if defined(QT_NO_WARNINGS)
1173 #  if defined(Q_CC_MSVC)
1174 #    pragma warning(disable: 4251) /* class 'A' needs to have dll interface for to be used by clients of class 'B'. */
1175 #    pragma warning(disable: 4244) /* 'conversion' conversion from 'type1' to 'type2', possible loss of data */
1176 #    pragma warning(disable: 4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */
1177 #    pragma warning(disable: 4514) /* unreferenced inline/local function has been removed */
1178 #    pragma warning(disable: 4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */
1179 #    pragma warning(disable: 4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */
1180 #    pragma warning(disable: 4706) /* assignment within conditional expression */
1181 #    pragma warning(disable: 4786) /* truncating debug info after 255 characters */
1182 #    pragma warning(disable: 4660) /* template-class specialization 'identifier' is already instantiated */
1183 #    pragma warning(disable: 4355) /* 'this' : used in base member initializer list */
1184 #    pragma warning(disable: 4231) /* nonstandard extension used : 'extern' before template explicit instantiation */
1185 #    pragma warning(disable: 4710) /* function not inlined */
1186 #    pragma warning(disable: 4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify -GX */
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 class Q_CORE_EXPORT QFlag
1199 {
1200     int i;
1201 public:
1202     inline QFlag(int i);
1203     inline operator int() const { return i; }
1204 };
1205
1206 inline QFlag::QFlag(int ai) : i(ai) {}
1207
1208 class Q_CORE_EXPORT QIncompatibleFlag
1209 {
1210     int i;
1211 public:
1212     inline explicit QIncompatibleFlag(int i);
1213     inline operator int() const { return i; }
1214 };
1215
1216 inline QIncompatibleFlag::QIncompatibleFlag(int ai) : i(ai) {}
1217
1218
1219 #ifndef Q_NO_TYPESAFE_FLAGS
1220
1221 template<typename Enum>
1222 class QFlags
1223 {
1224     typedef void **Zero;
1225     int i;
1226 public:
1227     typedef Enum enum_type;
1228     // compiler-generated copy/move ctor/assignment operators are fine!
1229 #ifdef qdoc
1230     inline QFlags(const QFlags &other);
1231     inline QFlags &operator=(const QFlags &other);
1232 #endif
1233     Q_DECL_CONSTEXPR inline QFlags(Enum f) : i(f) {}
1234     Q_DECL_CONSTEXPR inline QFlags(Zero = 0) : i(0) {}
1235     inline QFlags(QFlag f) : i(f) {}
1236
1237     inline QFlags &operator&=(int mask) { i &= mask; return *this; }
1238     inline QFlags &operator&=(uint mask) { i &= mask; return *this; }
1239     inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; }
1240     inline QFlags &operator|=(Enum f) { i |= f; return *this; }
1241     inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; }
1242     inline QFlags &operator^=(Enum f) { i ^= f; return *this; }
1243
1244     Q_DECL_CONSTEXPR  inline operator int() const { return i; }
1245
1246     Q_DECL_CONSTEXPR inline QFlags operator|(QFlags f) const { return QFlags(Enum(i | f.i)); }
1247     Q_DECL_CONSTEXPR inline QFlags operator|(Enum f) const { return QFlags(Enum(i | f)); }
1248     Q_DECL_CONSTEXPR inline QFlags operator^(QFlags f) const { return QFlags(Enum(i ^ f.i)); }
1249     Q_DECL_CONSTEXPR inline QFlags operator^(Enum f) const { return QFlags(Enum(i ^ f)); }
1250     Q_DECL_CONSTEXPR inline QFlags operator&(int mask) const { return QFlags(Enum(i & mask)); }
1251     Q_DECL_CONSTEXPR inline QFlags operator&(uint mask) const { return QFlags(Enum(i & mask)); }
1252     Q_DECL_CONSTEXPR inline QFlags operator&(Enum f) const { return QFlags(Enum(i & f)); }
1253     Q_DECL_CONSTEXPR inline QFlags operator~() const { return QFlags(Enum(~i)); }
1254
1255     Q_DECL_CONSTEXPR inline bool operator!() const { return !i; }
1256
1257     inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); }
1258 };
1259
1260 #define Q_DECLARE_FLAGS(Flags, Enum)\
1261 typedef QFlags<Enum> Flags;
1262
1263 #define Q_DECLARE_INCOMPATIBLE_FLAGS(Flags) \
1264 inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) \
1265 { return QIncompatibleFlag(int(f1) | f2); }
1266
1267 #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \
1268 Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
1269 { return QFlags<Flags::enum_type>(f1) | f2; } \
1270 Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
1271 { return f2 | f1; } Q_DECLARE_INCOMPATIBLE_FLAGS(Flags)
1272
1273
1274 #else /* Q_NO_TYPESAFE_FLAGS */
1275
1276 #define Q_DECLARE_FLAGS(Flags, Enum)\
1277 typedef uint Flags;
1278 #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
1279
1280 #endif /* Q_NO_TYPESAFE_FLAGS */
1281
1282 #if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_RVCT)
1283 /* make use of typeof-extension */
1284 template <typename T>
1285 class QForeachContainer {
1286 public:
1287     inline QForeachContainer(const T& t) : c(t), brk(0), i(c.begin()), e(c.end()) { }
1288     const T c;
1289     int brk;
1290     typename T::const_iterator i, e;
1291 };
1292
1293 #define Q_FOREACH(variable, container)                                \
1294 for (QForeachContainer<__typeof__(container)> _container_(container); \
1295      !_container_.brk && _container_.i != _container_.e;              \
1296      __extension__  ({ ++_container_.brk; ++_container_.i; }))                       \
1297     for (variable = *_container_.i;; __extension__ ({--_container_.brk; break;}))
1298
1299 #else
1300
1301 struct QForeachContainerBase {};
1302
1303 template <typename T>
1304 class QForeachContainer : public QForeachContainerBase {
1305 public:
1306     inline QForeachContainer(const T& t): c(t), brk(0), i(c.begin()), e(c.end()){}
1307     const T c;
1308     mutable int brk;
1309     mutable typename T::const_iterator i, e;
1310     inline bool condition() const { return (!brk++ && i != e); }
1311 };
1312
1313 template <typename T> inline T *qForeachPointer(const T &) { return 0; }
1314
1315 template <typename T> inline QForeachContainer<T> qForeachContainerNew(const T& t)
1316 { return QForeachContainer<T>(t); }
1317
1318 template <typename T>
1319 inline const QForeachContainer<T> *qForeachContainer(const QForeachContainerBase *base, const T *)
1320 { return static_cast<const QForeachContainer<T> *>(base); }
1321
1322 #if defined(Q_CC_MIPS)
1323 /*
1324    Proper for-scoping in MIPSpro CC
1325 */
1326 #  define Q_FOREACH(variable,container)                                                             \
1327     if(0){}else                                                                                     \
1328     for (const QForeachContainerBase &_container_ = qForeachContainerNew(container);                \
1329          qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->condition();       \
1330          ++qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i)               \
1331         for (variable = *qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i; \
1332              qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk;           \
1333              --qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk)
1334
1335 #elif defined(Q_CC_DIAB)
1336 // VxWorks DIAB generates unresolvable symbols, if container is a function call
1337 #  define Q_FOREACH(variable,container)                                                             \
1338     if(0){}else                                                                                     \
1339     for (const QForeachContainerBase &_container_ = qForeachContainerNew(container);                \
1340          qForeachContainer(&_container_, (__typeof__(container) *) 0)->condition();       \
1341          ++qForeachContainer(&_container_, (__typeof__(container) *) 0)->i)               \
1342         for (variable = *qForeachContainer(&_container_, (__typeof__(container) *) 0)->i; \
1343              qForeachContainer(&_container_, (__typeof__(container) *) 0)->brk;           \
1344              --qForeachContainer(&_container_, (__typeof__(container) *) 0)->brk)
1345
1346 #else
1347 #  define Q_FOREACH(variable, container) \
1348     for (const QForeachContainerBase &_container_ = qForeachContainerNew(container); \
1349          qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->condition();       \
1350          ++qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i)               \
1351         for (variable = *qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i; \
1352              qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk;           \
1353              --qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk)
1354 #endif // MSVC6 || MIPSpro
1355
1356 #endif
1357
1358 #define Q_FOREVER for(;;)
1359 #ifndef QT_NO_KEYWORDS
1360 #  ifndef foreach
1361 #    define foreach Q_FOREACH
1362 #  endif
1363 #  ifndef forever
1364 #    define forever Q_FOREVER
1365 #  endif
1366 #endif
1367
1368 #if 0
1369 /* tell gcc to use its built-in methods for some common functions */
1370 #if defined(QT_NO_DEBUG) && defined(Q_CC_GNU)
1371 #  define qMemCopy __builtin_memcpy
1372 #  define qMemSet __builtin_memset
1373 #endif
1374 #endif
1375
1376 template <typename T> static inline T *qGetPtrHelper(T *ptr) { return ptr; }
1377 template <typename Wrapper> static inline typename Wrapper::pointer qGetPtrHelper(const Wrapper &p) { return p.data(); }
1378
1379 #define Q_DECLARE_PRIVATE(Class) \
1380     inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \
1381     inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \
1382     friend class Class##Private;
1383
1384 #define Q_DECLARE_PRIVATE_D(Dptr, Class) \
1385     inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(Dptr); } \
1386     inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(Dptr); } \
1387     friend class Class##Private;
1388
1389 #define Q_DECLARE_PUBLIC(Class)                                    \
1390     inline Class* q_func() { return static_cast<Class *>(q_ptr); } \
1391     inline const Class* q_func() const { return static_cast<const Class *>(q_ptr); } \
1392     friend class Class;
1393
1394 #define Q_D(Class) Class##Private * const d = d_func()
1395 #define Q_Q(Class) Class * const q = q_func()
1396
1397 #define QT_TR_NOOP(x) x
1398 #define QT_TR_NOOP_UTF8(x) x
1399 #define QT_TRANSLATE_NOOP(scope, x) x
1400 #define QT_TRANSLATE_NOOP_UTF8(scope, x) x
1401 #define QT_TRANSLATE_NOOP3(scope, x, comment) {x, comment}
1402 #define QT_TRANSLATE_NOOP3_UTF8(scope, x, comment) {x, comment}
1403
1404 #ifndef QT_NO_TRANSLATION // ### This should enclose the NOOPs above
1405
1406 // Defined in qcoreapplication.cpp
1407 // The better name qTrId() is reserved for an upcoming function which would
1408 // return a much more powerful QStringFormatter instead of a QString.
1409 Q_CORE_EXPORT QString qtTrId(const char *id, int n = -1);
1410
1411 #define QT_TRID_NOOP(id) id
1412
1413 #endif // QT_NO_TRANSLATION
1414
1415 #define QDOC_PROPERTY(text)
1416
1417 /*
1418    When RTTI is not available, define this macro to force any uses of
1419    dynamic_cast to cause a compile failure.
1420 */
1421
1422 #ifdef QT_NO_DYNAMIC_CAST
1423 #  define dynamic_cast QT_PREPEND_NAMESPACE(qt_dynamic_cast_check)
1424
1425   template<typename T, typename X>
1426   T qt_dynamic_cast_check(X, T* = 0)
1427   { return T::dynamic_cast_will_always_fail_because_rtti_is_disabled; }
1428 #endif
1429
1430 /*
1431    Some classes do not permit copies to be made of an object. These
1432    classes contains a private copy constructor and assignment
1433    operator to disable copying (the compiler gives an error message).
1434 */
1435 #define Q_DISABLE_COPY(Class) \
1436     Class(const Class &) Q_DECL_EQ_DELETE;\
1437     Class &operator=(const Class &) Q_DECL_EQ_DELETE;
1438
1439 class QByteArray;
1440 Q_CORE_EXPORT QByteArray qgetenv(const char *varName);
1441 Q_CORE_EXPORT bool qputenv(const char *varName, const QByteArray& value);
1442
1443 inline int qIntCast(double f) { return int(f); }
1444 inline int qIntCast(float f) { return int(f); }
1445
1446 /*
1447   Reentrant versions of basic rand() functions for random number generation
1448 */
1449 Q_CORE_EXPORT void qsrand(uint seed);
1450 Q_CORE_EXPORT int qrand();
1451
1452 #define QT_MODULE(x)
1453
1454 #ifdef Q_OS_QNX
1455 // QNX doesn't have SYSV style shared memory. Multiprocess QWS apps,
1456 // shared fonts and QSystemSemaphore + QSharedMemory are not available
1457 #  define QT_NO_SYSTEMSEMAPHORE
1458 #  define QT_NO_SHAREDMEMORY
1459 #endif
1460
1461 #if defined (__ELF__)
1462 #  if defined (Q_OS_LINUX) || defined (Q_OS_SOLARIS) || defined (Q_OS_FREEBSD) || defined (Q_OS_OPENBSD) || defined (Q_OS_IRIX)
1463 #    define Q_OF_ELF
1464 #  endif
1465 #endif
1466
1467 #if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && !defined(__PIC__)
1468 #  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
1469          "Compile your code with -fPIC or -fPIE."
1470 #endif
1471
1472 namespace QtPrivate {
1473 //like std::enable_if
1474 template <bool B, typename T = void> struct QEnableIf;
1475 template <typename T> struct QEnableIf<true, T> { typedef T Type; };
1476 }
1477
1478 QT_END_NAMESPACE
1479 QT_END_HEADER
1480
1481 // qDebug and friends
1482 #include <QtCore/qlogging.h>
1483
1484 #include <QtCore/qsysinfo.h>
1485 #include <QtCore/qtypeinfo.h>
1486
1487 #endif /* __cplusplus */
1488
1489 #endif /* QGLOBAL_H */