Reshuffle code between qglobal, qlogging
[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 #if defined(Q_NO_BOOL_TYPE)
279 #error "Compiler doesn't support the bool type"
280 #endif
281
282
283 /*
284    Constant bool values
285 */
286
287 #ifndef QT_LINUXBASE /* the LSB defines TRUE and FALSE for us */
288 #  ifndef TRUE
289 #   define TRUE true
290 #   define FALSE false
291 #  endif
292 #endif
293
294 /*
295    Proper for-scoping in MIPSpro CC
296 */
297 #ifndef QT_NO_KEYWORDS
298 #  if defined(Q_CC_MIPS) || (defined(Q_CC_HPACC) && defined(__ia64))
299 #    define for if(0){}else for
300 #  endif
301 #endif
302
303 /*
304    Workaround for static const members on MSVC++.
305 */
306
307 #if defined(Q_CC_MSVC)
308 #  define QT_STATIC_CONST static
309 #  define QT_STATIC_CONST_IMPL
310 #else
311 #  define QT_STATIC_CONST static const
312 #  define QT_STATIC_CONST_IMPL const
313 #endif
314
315 /*
316    Warnings and errors when using deprecated methods
317 */
318 #if defined(Q_MOC_RUN)
319 #  define Q_DECL_DEPRECATED Q_DECL_DEPRECATED
320 #elif (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && (__GNUC__ - 0 > 3 || (__GNUC__ - 0 == 3 && __GNUC_MINOR__ - 0 >= 2))) || defined(Q_CC_RVCT)
321 #  define Q_DECL_DEPRECATED __attribute__ ((__deprecated__))
322 #elif defined(Q_CC_MSVC)
323 #  define Q_DECL_DEPRECATED __declspec(deprecated)
324 #  if defined (Q_CC_INTEL)
325 #    define Q_DECL_VARIABLE_DEPRECATED
326 #  else
327 #  endif
328 #else
329 #  define Q_DECL_DEPRECATED
330 #endif
331 #ifndef Q_DECL_VARIABLE_DEPRECATED
332 #  define Q_DECL_VARIABLE_DEPRECATED Q_DECL_DEPRECATED
333 #endif
334 #ifndef Q_DECL_CONSTRUCTOR_DEPRECATED
335 #  if defined(Q_MOC_RUN)
336 #    define Q_DECL_CONSTRUCTOR_DEPRECATED Q_DECL_CONSTRUCTOR_DEPRECATED
337 #  elif defined(Q_NO_DEPRECATED_CONSTRUCTORS)
338 #    define Q_DECL_CONSTRUCTOR_DEPRECATED
339 #  else
340 #    define Q_DECL_CONSTRUCTOR_DEPRECATED Q_DECL_DEPRECATED
341 #  endif
342 #endif
343
344 #if defined(QT_NO_DEPRECATED)
345 #  undef QT_DEPRECATED
346 #  undef QT_DEPRECATED_VARIABLE
347 #  undef QT_DEPRECATED_CONSTRUCTOR
348 #elif defined(QT_DEPRECATED_WARNINGS)
349 #  undef QT_DEPRECATED
350 #  define QT_DEPRECATED Q_DECL_DEPRECATED
351 #  undef QT_DEPRECATED_VARIABLE
352 #  define QT_DEPRECATED_VARIABLE Q_DECL_VARIABLE_DEPRECATED
353 #  undef QT_DEPRECATED_CONSTRUCTOR
354 #  define QT_DEPRECATED_CONSTRUCTOR explicit Q_DECL_CONSTRUCTOR_DEPRECATED
355 #else
356 #  undef QT_DEPRECATED
357 #  define QT_DEPRECATED
358 #  undef QT_DEPRECATED_VARIABLE
359 #  define QT_DEPRECATED_VARIABLE
360 #  undef QT_DEPRECATED_CONSTRUCTOR
361 #  define QT_DEPRECATED_CONSTRUCTOR
362 #endif
363
364 #ifndef QT_DISABLE_DEPRECATED_BEFORE
365 // ### Qt5: remember to change that to 5 when we reach feature freeze
366 #define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(4, 9, 0)
367 #endif
368
369 /*
370     QT_DEPRECATED_SINCE(major, minor) evaluates as true if the Qt version is greater than
371     the deprecation point specified.
372
373     Use it to specify from which version of Qt a function or class has been deprecated
374
375     Example:
376         #if QT_DEPRECATED_SINCE(5,1)
377             QT_DEPRECATED void deprecatedFunction(); //function deprecated since Qt 5.1
378         #endif
379
380 */
381 #ifdef QT_DEPRECATED
382 #define QT_DEPRECATED_SINCE(major, minor) (QT_VERSION_CHECK(major, minor, 0) > QT_DISABLE_DEPRECATED_BEFORE)
383 #else
384 #define QT_DEPRECATED_SINCE(major, minor) 0
385 #endif
386
387 /* moc compats (signals/slots) */
388 #ifndef QT_MOC_COMPAT
389 #  define QT_MOC_COMPAT
390 #else
391 #  undef QT_MOC_COMPAT
392 #  define QT_MOC_COMPAT
393 #endif
394
395 #ifdef QT_ASCII_CAST_WARNINGS
396 #  define QT_ASCII_CAST_WARN Q_DECL_DEPRECATED
397 #  if defined(Q_CC_GNU) && __GNUC__ < 4
398      /* gcc < 4 doesn't like Q_DECL_DEPRECATED in front of constructors */
399 #    define QT_ASCII_CAST_WARN_CONSTRUCTOR
400 #  else
401 #    define QT_ASCII_CAST_WARN_CONSTRUCTOR Q_DECL_CONSTRUCTOR_DEPRECATED
402 #  endif
403 #else
404 #  define QT_ASCII_CAST_WARN
405 #  define QT_ASCII_CAST_WARN_CONSTRUCTOR
406 #endif
407
408 #if defined(__i386__) || defined(_WIN32) || defined(_WIN32_WCE)
409 #  if defined(Q_CC_GNU)
410 #if !defined(Q_CC_INTEL) && ((100*(__GNUC__ - 0) + 10*(__GNUC_MINOR__ - 0) + __GNUC_PATCHLEVEL__) >= 332)
411 #    define QT_FASTCALL __attribute__((regparm(3)))
412 #else
413 #    define QT_FASTCALL
414 #endif
415 #  elif defined(Q_CC_MSVC)
416 #    define QT_FASTCALL __fastcall
417 #  else
418 #     define QT_FASTCALL
419 #  endif
420 #else
421 #  define QT_FASTCALL
422 #endif
423
424 #ifdef Q_COMPILER_NULLPTR
425 # define Q_NULLPTR         nullptr
426 #else
427 # define Q_NULLPTR         0
428 #endif
429
430 #ifdef Q_COMPILER_DEFAULT_DELETE_MEMBERS
431 # define Q_DECL_EQ_DELETE = delete
432 #else
433 # define Q_DECL_EQ_DELETE
434 #endif
435
436 #ifdef Q_COMPILER_CONSTEXPR
437 # define Q_DECL_CONSTEXPR constexpr
438 #else
439 # define Q_DECL_CONSTEXPR
440 #endif
441
442 #ifdef Q_COMPILER_EXPLICIT_OVERRIDES
443 # define Q_DECL_OVERRIDE override
444 # define Q_DECL_FINAL final
445 #else
446 # define Q_DECL_OVERRIDE
447 # define Q_DECL_FINAL
448 #endif
449
450 //defines the type for the WNDPROC on windows
451 //the alignment needs to be forced for sse2 to not crash with mingw
452 #if defined(Q_OS_WIN)
453 #  if defined(Q_CC_MINGW)
454 #    define QT_ENSURE_STACK_ALIGNED_FOR_SSE __attribute__ ((force_align_arg_pointer))
455 #  else
456 #    define QT_ENSURE_STACK_ALIGNED_FOR_SSE
457 #  endif
458 #  define QT_WIN_CALLBACK CALLBACK QT_ENSURE_STACK_ALIGNED_FOR_SSE 
459 #endif
460
461 typedef int QNoImplicitBoolCast;
462
463 // This logic must match the one in qmetatype.h
464 #if defined(QT_COORD_TYPE)
465 typedef QT_COORD_TYPE qreal;
466 #elif defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE)
467 typedef float qreal;
468 #else
469 typedef double qreal;
470 #endif
471
472 /*
473    Utility macros and inline functions
474 */
475
476 template <typename T>
477 Q_DECL_CONSTEXPR inline T qAbs(const T &t) { return t >= 0 ? t : -t; }
478
479 Q_DECL_CONSTEXPR inline int qRound(double d)
480 { return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); }
481 Q_DECL_CONSTEXPR inline int qRound(float d)
482 { return d >= 0.0f ? int(d + 0.5f) : int(d - int(d-1) + 0.5f) + int(d-1); }
483 #ifdef Q_QDOC
484 /*
485     Just for documentation generation
486 */
487 int qRound(qreal d);
488 #endif
489
490 Q_DECL_CONSTEXPR inline qint64 qRound64(double d)
491 { return d >= 0.0 ? qint64(d + 0.5) : qint64(d - double(qint64(d-1)) + 0.5) + qint64(d-1); }
492 Q_DECL_CONSTEXPR inline qint64 qRound64(float d)
493 { return d >= 0.0f ? qint64(d + 0.5f) : qint64(d - float(qint64(d-1)) + 0.5f) + qint64(d-1); }
494 #ifdef Q_QDOC
495 /*
496     Just for documentation generation
497 */
498 qint64 qRound64(qreal d);
499 #endif
500
501 template <typename T>
502 Q_DECL_CONSTEXPR inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; }
503 template <typename T>
504 Q_DECL_CONSTEXPR inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; }
505 template <typename T>
506 Q_DECL_CONSTEXPR inline const T &qBound(const T &min, const T &val, const T &max)
507 { return qMax(min, qMin(max, val)); }
508
509 /*
510    Data stream functions are provided by many classes (defined in qdatastream.h)
511 */
512
513 class QDataStream;
514
515 #if !defined(QT_NO_COP)
516 #  define QT_NO_COP
517 #endif
518
519 #if defined(Q_OS_VXWORKS)
520 #  define QT_NO_CRASHHANDLER     // no popen
521 #  define QT_NO_PROCESS          // no exec*, no fork
522 #  define QT_NO_LPR
523 #  define QT_NO_SHAREDMEMORY     // only POSIX, no SysV and in the end...
524 #  define QT_NO_SYSTEMSEMAPHORE  // not needed at all in a flat address space
525 #  define QT_NO_QWS_MULTIPROCESS // no processes
526 #endif
527
528 # include <QtCore/qfeatures.h>
529
530 #define QT_SUPPORTS(FEATURE) (!defined(QT_NO_##FEATURE))
531
532 #if defined(Q_OS_LINUX) && defined(Q_CC_RVCT)
533 #  define Q_DECL_EXPORT     __attribute__((visibility("default")))
534 #  define Q_DECL_IMPORT     __attribute__((visibility("default")))
535 #  define Q_DECL_HIDDEN     __attribute__((visibility("hidden")))
536 #endif
537
538 #ifndef Q_DECL_EXPORT
539 #  if defined(Q_OS_WIN) || defined(Q_CC_RVCT)
540 #    define Q_DECL_EXPORT __declspec(dllexport)
541 #  elif defined(QT_VISIBILITY_AVAILABLE)
542 #    define Q_DECL_EXPORT __attribute__((visibility("default")))
543 #    define Q_DECL_HIDDEN __attribute__((visibility("hidden")))
544 #  endif
545 #  ifndef Q_DECL_EXPORT
546 #    define Q_DECL_EXPORT
547 #  endif
548 #endif
549 #ifndef Q_DECL_IMPORT
550 #  if defined(Q_OS_WIN) || defined(Q_CC_RVCT)
551 #    define Q_DECL_IMPORT __declspec(dllimport)
552 #  else
553 #    define Q_DECL_IMPORT
554 #  endif
555 #endif
556 #ifndef Q_DECL_HIDDEN
557 #  define Q_DECL_HIDDEN
558 #endif
559
560
561 /*
562    Create Qt DLL if QT_DLL is defined (Windows only)
563 */
564
565 #if defined(Q_OS_WIN)
566 #  if defined(QT_NODLL)
567 #    undef QT_MAKEDLL
568 #    undef QT_DLL
569 #  elif defined(QT_MAKEDLL)        /* create a Qt DLL library */
570 #    if defined(QT_DLL)
571 #      undef QT_DLL
572 #    endif
573 #    if defined(QT_BUILD_CORE_LIB)
574 #      define Q_CORE_EXPORT Q_DECL_EXPORT
575 #    else
576 #      define Q_CORE_EXPORT Q_DECL_IMPORT
577 #    endif
578 #    if defined(QT_BUILD_GUI_LIB)
579 #      define Q_GUI_EXPORT Q_DECL_EXPORT
580 #    else
581 #      define Q_GUI_EXPORT Q_DECL_IMPORT
582 #    endif
583 #    if defined(QT_BUILD_WIDGETS_LIB)
584 #      define Q_WIDGETS_EXPORT Q_DECL_EXPORT
585 #    else
586 #      define Q_WIDGETS_EXPORT Q_DECL_IMPORT
587 #    endif
588 #    if defined(QT_BUILD_PLATFORMSUPPORT_LIB)
589 #      define Q_PLATFORMSUPPORT_EXPORT Q_DECL_EXPORT
590 #    else
591 #      define Q_PLATFORMSUPPORT_EXPORT Q_DECL_IMPORT
592 #    endif
593 #    if defined(QT_BUILD_PRINTSUPPORT_LIB)
594 #      define Q_PRINTSUPPORT_EXPORT Q_DECL_EXPORT
595 #    else
596 #      define Q_PRINTSUPPORT_EXPORT Q_DECL_IMPORT
597 #    endif
598 #    if defined(QT_BUILD_SQL_LIB)
599 #      define Q_SQL_EXPORT Q_DECL_EXPORT
600 #    else
601 #      define Q_SQL_EXPORT Q_DECL_IMPORT
602 #    endif
603 #    if defined(QT_BUILD_NETWORK_LIB)
604 #      define Q_NETWORK_EXPORT Q_DECL_EXPORT
605 #    else
606 #      define Q_NETWORK_EXPORT Q_DECL_IMPORT
607 #    endif
608 #    if defined(QT_BUILD_SVG_LIB)
609 #      define Q_SVG_EXPORT Q_DECL_EXPORT
610 #    else
611 #      define Q_SVG_EXPORT Q_DECL_IMPORT
612 #    endif
613 #    if defined(QT_BUILD_QTQUICK1_LIB)
614 #      define Q_QTQUICK1_EXPORT Q_DECL_EXPORT
615 #    else
616 #      define Q_QTQUICK1_EXPORT Q_DECL_IMPORT
617 #    endif
618 #    if defined(QT_BUILD_DECLARATIVE_LIB)
619 #      define Q_DECLARATIVE_EXPORT Q_DECL_EXPORT
620 #    else
621 #      define Q_DECLARATIVE_EXPORT Q_DECL_IMPORT
622 #    endif
623 #    if defined(QT_BUILD_OPENGL_LIB)
624 #      define Q_OPENGL_EXPORT Q_DECL_EXPORT
625 #    else
626 #      define Q_OPENGL_EXPORT Q_DECL_IMPORT
627 #    endif
628 #    if defined(QT_BUILD_MULTIMEDIA_LIB)
629 #      define Q_MULTIMEDIA_EXPORT Q_DECL_EXPORT
630 #    else
631 #      define Q_MULTIMEDIA_EXPORT Q_DECL_IMPORT
632 #    endif
633 #    if defined(QT_BUILD_OPENVG_LIB)
634 #      define Q_OPENVG_EXPORT Q_DECL_EXPORT
635 #    else
636 #      define Q_OPENVG_EXPORT Q_DECL_IMPORT
637 #    endif
638 #    if defined(QT_BUILD_XML_LIB)
639 #      define Q_XML_EXPORT Q_DECL_EXPORT
640 #    else
641 #      define Q_XML_EXPORT Q_DECL_IMPORT
642 #    endif
643 #    if defined(QT_BUILD_XMLPATTERNS_LIB)
644 #      define Q_XMLPATTERNS_EXPORT Q_DECL_EXPORT
645 #    else
646 #      define Q_XMLPATTERNS_EXPORT Q_DECL_IMPORT
647 #    endif
648 #    if defined(QT_BUILD_SCRIPT_LIB)
649 #      define Q_SCRIPT_EXPORT Q_DECL_EXPORT
650 #    else
651 #      define Q_SCRIPT_EXPORT Q_DECL_IMPORT
652 #    endif
653 #    if defined(QT_BUILD_SCRIPTTOOLS_LIB)
654 #      define Q_SCRIPTTOOLS_EXPORT Q_DECL_EXPORT
655 #    else
656 #      define Q_SCRIPTTOOLS_EXPORT Q_DECL_IMPORT
657 #    endif
658 #    if defined(QT_BUILD_CANVAS_LIB)
659 #      define Q_CANVAS_EXPORT Q_DECL_EXPORT
660 #    else
661 #      define Q_CANVAS_EXPORT Q_DECL_IMPORT
662 #    endif
663 #    if defined(QT_BUILD_COMPAT_LIB)
664 #      define Q_COMPAT_EXPORT Q_DECL_EXPORT
665 #    else
666 #      define Q_COMPAT_EXPORT Q_DECL_IMPORT
667 #    endif
668 #    if defined(QT_BUILD_DBUS_LIB)
669 #      define Q_DBUS_EXPORT Q_DECL_EXPORT
670 #    else
671 #      define Q_DBUS_EXPORT Q_DECL_IMPORT
672 #    endif
673 #    define Q_TEMPLATEDLL
674 #    if defined(QT_BUILD_CONCURRENT_LIB)
675 #      define Q_CONCURRENT_EXPORT Q_DECL_EXPORT
676 #    else
677 #      define Q_CONCURRENT_EXPORT Q_DECL_IMPORT
678 #    endif
679 #  elif defined(QT_DLL) /* use a Qt DLL library */
680 #    define Q_CORE_EXPORT Q_DECL_IMPORT
681 #    define Q_GUI_EXPORT Q_DECL_IMPORT
682 #    define Q_WIDGETS_EXPORT Q_DECL_IMPORT
683 #    define Q_PLATFORMSUPPORT_EXPORT Q_DECL_IMPORT
684 #    define Q_PRINTSUPPORT_EXPORT Q_DECL_IMPORT
685 #    define Q_SQL_EXPORT Q_DECL_IMPORT
686 #    define Q_NETWORK_EXPORT Q_DECL_IMPORT
687 #    define Q_SVG_EXPORT Q_DECL_IMPORT
688 #    define Q_DECLARATIVE_EXPORT Q_DECL_IMPORT
689 #    define Q_QTQUICK1_EXPORT Q_DECL_IMPORT
690 #    define Q_CANVAS_EXPORT Q_DECL_IMPORT
691 #    define Q_OPENGL_EXPORT Q_DECL_IMPORT
692 #    define Q_MULTIMEDIA_EXPORT Q_DECL_IMPORT
693 #    define Q_OPENVG_EXPORT Q_DECL_IMPORT
694 #    define Q_XML_EXPORT Q_DECL_IMPORT
695 #    define Q_XMLPATTERNS_EXPORT Q_DECL_IMPORT
696 #    define Q_SCRIPT_EXPORT Q_DECL_IMPORT
697 #    define Q_SCRIPTTOOLS_EXPORT Q_DECL_IMPORT
698 #    define Q_COMPAT_EXPORT Q_DECL_IMPORT
699 #    define Q_DBUS_EXPORT Q_DECL_IMPORT
700 #    define Q_CONCURRENT_EXPORT Q_DECL_IMPORT
701 #    define Q_TEMPLATEDLL
702 #  endif
703 #  define Q_NO_DECLARED_NOT_DEFINED
704 #else
705 #  if defined(Q_OS_LINUX) && defined(Q_CC_BOR)
706 #    define Q_TEMPLATEDLL
707 #    define Q_NO_DECLARED_NOT_DEFINED
708 #  endif
709 #  undef QT_MAKEDLL /* ignore these for other platforms */
710 #  undef QT_DLL
711 #endif
712
713 #if !defined(Q_CORE_EXPORT)
714 #  if defined(QT_SHARED)
715 #    define Q_CORE_EXPORT Q_DECL_EXPORT
716 #    define Q_GUI_EXPORT Q_DECL_EXPORT
717 #    define Q_WIDGETS_EXPORT Q_DECL_EXPORT
718 #    define Q_PLATFORMSUPPORT_EXPORT Q_DECL_EXPORT
719 #    define Q_PRINTSUPPORT_EXPORT Q_DECL_EXPORT
720 #    define Q_SQL_EXPORT Q_DECL_EXPORT
721 #    define Q_NETWORK_EXPORT Q_DECL_EXPORT
722 #    define Q_SVG_EXPORT Q_DECL_EXPORT
723 #    define Q_DECLARATIVE_EXPORT Q_DECL_EXPORT
724 #    define Q_QTQUICK1_EXPORT Q_DECL_EXPORT
725 #    define Q_OPENGL_EXPORT Q_DECL_EXPORT
726 #    define Q_MULTIMEDIA_EXPORT Q_DECL_EXPORT
727 #    define Q_OPENVG_EXPORT Q_DECL_EXPORT
728 #    define Q_XML_EXPORT Q_DECL_EXPORT
729 #    define Q_XMLPATTERNS_EXPORT Q_DECL_EXPORT
730 #    define Q_SCRIPT_EXPORT Q_DECL_EXPORT
731 #    define Q_SCRIPTTOOLS_EXPORT Q_DECL_EXPORT
732 #    define Q_COMPAT_EXPORT Q_DECL_EXPORT
733 #    define Q_DBUS_EXPORT Q_DECL_EXPORT
734 #    define Q_CONCURRENT_EXPORT Q_DECL_EXPORT
735 #  else
736 #    define Q_CORE_EXPORT
737 #    define Q_GUI_EXPORT
738 #    define Q_WIDGETS_EXPORT
739 #    define Q_PLATFORMSUPPORT_EXPORT
740 #    define Q_PRINTSUPPORT_EXPORT
741 #    define Q_SQL_EXPORT
742 #    define Q_NETWORK_EXPORT
743 #    define Q_SVG_EXPORT
744 #    define Q_DECLARATIVE_EXPORT
745 #    define Q_QTQUICK1_EXPORT
746 #    define Q_OPENGL_EXPORT
747 #    define Q_MULTIMEDIA_EXPORT
748 #    define Q_OPENVG_EXPORT
749 #    define Q_XML_EXPORT
750 #    define Q_XMLPATTERNS_EXPORT
751 #    define Q_SCRIPT_EXPORT
752 #    define Q_SCRIPTTOOLS_EXPORT
753 #    define Q_COMPAT_EXPORT
754 #    define Q_DBUS_EXPORT
755 #    define Q_CONCURRENT_EXPORT
756 #  endif
757 #endif
758
759 // Functions marked as Q_GUI_EXPORT_INLINE were exported and inlined by mistake.
760 // Compilers like MinGW complain that the import attribute is ignored.
761 #if defined(Q_CC_MINGW)
762 #    if defined(QT_BUILD_CORE_LIB)
763 #      define Q_CORE_EXPORT_INLINE Q_CORE_EXPORT inline
764 #    else
765 #      define Q_CORE_EXPORT_INLINE inline
766 #    endif
767 #    if defined(QT_BUILD_GUI_LIB)
768 #      define Q_GUI_EXPORT_INLINE Q_GUI_EXPORT inline
769 #    else
770 #      define Q_GUI_EXPORT_INLINE inline
771 #    endif
772 #    if defined(QT_BUILD_WIDGETS_LIB)
773 #      define Q_WIDGETS_EXPORT_INLINE Q_WIDGETS_EXPORT inline
774 #    else
775 #      define Q_WIDGETS_EXPORT_INLINE inline
776 #    endif
777 #    if defined(QT_BUILD_PLATFORMSUPPORT_LIB)
778 #      define Q_PLATFORMSUPPORT_EXPORT_INLINE Q_PLATFORMSUPPORT_EXPORT inline
779 #    else
780 #      define Q_PLATFORMSUPPORT_EXPORT_INLINE inline
781 #    endif
782 #    if defined(QT_BUILD_PRINTSUPPORT_LIB)
783 #      define Q_PRINTSUPPORT_EXPORT_INLINE Q_PRINTSUPPORT_EXPORT inline
784 #    else
785 #      define Q_PRINTSUPPORT_EXPORT_INLINE inline
786 #    endif
787 #    if defined(QT_BUILD_COMPAT_LIB)
788 #      define Q_COMPAT_EXPORT_INLINE Q_COMPAT_EXPORT inline
789 #    else
790 #      define Q_COMPAT_EXPORT_INLINE inline
791 #    endif
792 #elif defined(Q_CC_RVCT)
793 // we force RVCT not to export inlines by passing --visibility_inlines_hidden
794 // so we need to just inline it, rather than exporting and inlining
795 // note: this affects the contents of the DEF files (ie. these functions do not appear)
796 #    define Q_CORE_EXPORT_INLINE inline
797 #    define Q_GUI_EXPORT_INLINE inline
798 #    define Q_WIDGETS_EXPORT_INLINE inline
799 #    define Q_PLATFORMSUPPORT_EXPORT_INLINE inline
800 #    define Q_PRINTSUPPORT_EXPORT_INLINE inline
801 #    define Q_COMPAT_EXPORT_INLINE inline
802 #else
803 #    define Q_CORE_EXPORT_INLINE Q_CORE_EXPORT inline
804 #    define Q_GUI_EXPORT_INLINE Q_GUI_EXPORT inline
805 #    define Q_WIDGETS_EXPORT_INLINE Q_WIDGETS_EXPORT inline
806 #    define Q_PLATFORMSUPPORT_EXPORT_INLINE Q_PLATFORMSUPPORT_EXPORT inline
807 #    define Q_PRINTSUPPORT_EXPORT_INLINE Q_PRINTSUPPORT_EXPORT inline
808 #    define Q_COMPAT_EXPORT_INLINE Q_COMPAT_EXPORT inline
809 #endif
810
811 /*
812    No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols
813    for Qt's internal unit tests. If you want slower loading times and more
814    symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL.
815 */
816 #if defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN) && defined(QT_MAKEDLL)
817 #    define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
818 #elif defined(QT_BUILD_INTERNAL) && defined(Q_OS_WIN) && defined(QT_DLL)
819 #    define Q_AUTOTEST_EXPORT Q_DECL_IMPORT
820 #elif defined(QT_BUILD_INTERNAL) && !defined(Q_OS_WIN) && defined(QT_SHARED)
821 #    define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
822 #else
823 #    define Q_AUTOTEST_EXPORT
824 #endif
825
826 inline void qt_noop(void) {}
827
828 /* These wrap try/catch so we can switch off exceptions later.
829
830    Beware - do not use more than one QT_CATCH per QT_TRY, and do not use
831    the exception instance in the catch block.
832    If you can't live with those constraints, don't use these macros.
833    Use the QT_NO_EXCEPTIONS macro to protect your code instead.
834 */
835
836 #ifdef QT_BOOTSTRAPPED
837 #  define QT_NO_EXCEPTIONS
838 #endif
839 #if !defined(QT_NO_EXCEPTIONS) && defined(Q_CC_GNU) && !defined (__EXCEPTIONS) && !defined(Q_MOC_RUN)
840 #  define QT_NO_EXCEPTIONS
841 #endif
842
843 #ifdef QT_NO_EXCEPTIONS
844 #  define QT_TRY if (true)
845 #  define QT_CATCH(A) else
846 #  define QT_THROW(A) qt_noop()
847 #  define QT_RETHROW qt_noop()
848 #else
849 #  define QT_TRY try
850 #  define QT_CATCH(A) catch (A)
851 #  define QT_THROW(A) throw A
852 #  define QT_RETHROW throw
853 #endif
854
855 /*
856    System information
857 */
858
859 class QString;
860 class Q_CORE_EXPORT QSysInfo {
861 public:
862     enum Sizes {
863         WordSize = (sizeof(void *)<<3)
864     };
865
866 #if defined(QT_BUILD_QMAKE)
867     enum Endian {
868         BigEndian,
869         LittleEndian
870     };
871     /* needed to bootstrap qmake */
872     static const int ByteOrder;
873 #elif defined(Q_BYTE_ORDER)
874     enum Endian {
875         BigEndian,
876         LittleEndian
877
878 #  ifdef qdoc
879         , ByteOrder = <platform-dependent>
880 #  elif Q_BYTE_ORDER == Q_BIG_ENDIAN
881         , ByteOrder = BigEndian
882 #  elif Q_BYTE_ORDER == Q_LITTLE_ENDIAN
883         , ByteOrder = LittleEndian
884 #  else
885 #    error "Undefined byte order"
886 #  endif
887     };
888 #else
889 #  error "Qt not configured correctly, please run configure"
890 #endif
891 #if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
892     enum WinVersion {
893         WV_32s      = 0x0001,
894         WV_95       = 0x0002,
895         WV_98       = 0x0003,
896         WV_Me       = 0x0004,
897         WV_DOS_based= 0x000f,
898
899         /* codenames */
900         WV_NT       = 0x0010,
901         WV_2000     = 0x0020,
902         WV_XP       = 0x0030,
903         WV_2003     = 0x0040,
904         WV_VISTA    = 0x0080,
905         WV_WINDOWS7 = 0x0090,
906         WV_NT_based = 0x00f0,
907
908         /* version numbers */
909         WV_4_0      = WV_NT,
910         WV_5_0      = WV_2000,
911         WV_5_1      = WV_XP,
912         WV_5_2      = WV_2003,
913         WV_6_0      = WV_VISTA,
914         WV_6_1      = WV_WINDOWS7,
915
916         WV_CE       = 0x0100,
917         WV_CENET    = 0x0200,
918         WV_CE_5     = 0x0300,
919         WV_CE_6     = 0x0400,
920         WV_CE_based = 0x0f00
921     };
922     static const WinVersion WindowsVersion;
923     static WinVersion windowsVersion();
924
925 #endif
926 #ifdef Q_OS_MAC
927     enum MacVersion {
928         MV_Unknown = 0x0000,
929
930         /* version */
931         MV_9 = 0x0001,
932         MV_10_0 = 0x0002,
933         MV_10_1 = 0x0003,
934         MV_10_2 = 0x0004,
935         MV_10_3 = 0x0005,
936         MV_10_4 = 0x0006,
937         MV_10_5 = 0x0007,
938         MV_10_6 = 0x0008,
939         MV_10_7 = 0x0009,
940
941         /* codenames */
942         MV_CHEETAH = MV_10_0,
943         MV_PUMA = MV_10_1,
944         MV_JAGUAR = MV_10_2,
945         MV_PANTHER = MV_10_3,
946         MV_TIGER = MV_10_4,
947         MV_LEOPARD = MV_10_5,
948         MV_SNOWLEOPARD = MV_10_6,
949         MV_LION = MV_10_7
950     };
951     static const MacVersion MacintoshVersion;
952 #endif
953 };
954
955 Q_CORE_EXPORT const char *qVersion();
956 Q_CORE_EXPORT bool qSharedBuild();
957
958 #if defined(Q_OS_MAC)
959 inline int qMacVersion() { return QSysInfo::MacintoshVersion; }
960 #endif
961
962 #ifndef Q_OUTOFLINE_TEMPLATE
963 #  define Q_OUTOFLINE_TEMPLATE
964 #endif
965 #ifndef Q_INLINE_TEMPLATE
966 #  define Q_INLINE_TEMPLATE inline
967 #endif
968
969 /*
970    Avoid "unused parameter" warnings
971 */
972
973 #if defined(Q_CC_INTEL) && !defined(Q_OS_WIN) || defined(Q_CC_RVCT)
974 template <typename T>
975 inline void qUnused(T &x) { (void)x; }
976 #  define Q_UNUSED(x) qUnused(x);
977 #else
978 #  define Q_UNUSED(x) (void)x;
979 #endif
980
981 /*
982    Debugging and error handling
983 */
984
985 #if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG)
986 #  define QT_DEBUG
987 #endif
988
989 #ifndef qPrintable
990 #  define qPrintable(string) QString(string).toLocal8Bit().constData()
991 #endif
992
993 class QString;
994 Q_CORE_EXPORT QString qt_error_string(int errorCode = -1);
995 Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line);
996
997 #if !defined(Q_ASSERT)
998 #  if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
999 #    define Q_ASSERT(cond) qt_noop()
1000 #  else
1001 #    define Q_ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop())
1002 #  endif
1003 #endif
1004
1005 #if defined(QT_NO_DEBUG) && !defined(QT_PAINT_DEBUG)
1006 #define QT_NO_PAINT_DEBUG
1007 #endif
1008
1009 Q_CORE_EXPORT void qt_assert_x(const char *where, const char *what, const char *file, int line);
1010
1011 #if !defined(Q_ASSERT_X)
1012 #  if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS)
1013 #    define Q_ASSERT_X(cond, where, what) qt_noop()
1014 #  else
1015 #    define Q_ASSERT_X(cond, where, what) ((!(cond)) ? qt_assert_x(where, what,__FILE__,__LINE__) : qt_noop())
1016 #  endif
1017 #endif
1018
1019
1020 #ifdef Q_COMPILER_STATIC_ASSERT
1021 #define Q_STATIC_ASSERT(Condition) static_assert(bool(Condition), #Condition)
1022 #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
1023 #else
1024 // Intentionally undefined
1025 template <bool Test> class QStaticAssertFailure;
1026 template <> class QStaticAssertFailure<true> {};
1027
1028 #define Q_STATIC_ASSERT_PRIVATE_JOIN(A, B) Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B)
1029 #define Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) A ## B
1030 #define Q_STATIC_ASSERT(Condition) \
1031     enum {Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) = sizeof(QStaticAssertFailure<!!(Condition)>)}
1032 #define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition)
1033 #endif
1034
1035 Q_CORE_EXPORT void qt_check_pointer(const char *, int);
1036 Q_CORE_EXPORT void qBadAlloc();
1037
1038 #ifdef QT_NO_EXCEPTIONS
1039 #  if defined(QT_NO_DEBUG)
1040 #    define Q_CHECK_PTR(p) qt_noop()
1041 #  else
1042 #    define Q_CHECK_PTR(p) do {if(!(p))qt_check_pointer(__FILE__,__LINE__);} while (0)
1043 #  endif
1044 #else
1045 #  define Q_CHECK_PTR(p) do { if (!(p)) qBadAlloc(); } while (0)
1046 #endif
1047
1048 template <typename T>
1049 inline T *q_check_ptr(T *p) { Q_CHECK_PTR(p); return p; }
1050
1051 #if (defined(Q_CC_GNU) && !defined(Q_OS_SOLARIS)) || defined(Q_CC_HPACC) || defined(Q_CC_DIAB)
1052 #  define Q_FUNC_INFO __PRETTY_FUNCTION__
1053 #elif defined(_MSC_VER)
1054 #  define Q_FUNC_INFO __FUNCSIG__
1055 #else
1056 #   if defined(Q_OS_SOLARIS) || defined(Q_CC_XLC)
1057 #      define Q_FUNC_INFO __FILE__ "(line number unavailable)"
1058 #   else
1059         /* These two macros makes it possible to turn the builtin line expander into a
1060          * string literal. */
1061 #       define QT_STRINGIFY2(x) #x
1062 #       define QT_STRINGIFY(x) QT_STRINGIFY2(x)
1063 #       define Q_FUNC_INFO __FILE__ ":" QT_STRINGIFY(__LINE__)
1064 #   endif
1065     /* The MIPSpro and RVCT compilers postpones macro expansion,
1066        and therefore macros must be in scope when being used. */
1067 #   if !defined(Q_CC_MIPS) && !defined(Q_CC_RVCT)
1068 #       undef QT_STRINGIFY2
1069 #       undef QT_STRINGIFY
1070 #   endif
1071 #endif
1072
1073
1074 typedef void (*QFunctionPointer)();
1075
1076 #if !defined(Q_UNIMPLEMENTED)
1077 #  define Q_UNIMPLEMENTED() qWarning("%s:%d: %s: Unimplemented code.", __FILE__, __LINE__, Q_FUNC_INFO)
1078 #endif
1079
1080 #if defined(QT_NO_THREAD)
1081
1082 template <typename T>
1083 class QGlobalStatic
1084 {
1085 public:
1086     T *pointer;
1087     inline QGlobalStatic(T *p) : pointer(p) { }
1088     inline ~QGlobalStatic() { pointer = 0; }
1089 };
1090
1091 #define Q_GLOBAL_STATIC(TYPE, NAME)                                  \
1092     static TYPE *NAME()                                              \
1093     {                                                                \
1094         static TYPE thisVariable;                                    \
1095         static QGlobalStatic<TYPE > thisGlobalStatic(&thisVariable); \
1096         return thisGlobalStatic.pointer;                             \
1097     }
1098
1099 #define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)                  \
1100     static TYPE *NAME()                                              \
1101     {                                                                \
1102         static TYPE thisVariable ARGS;                               \
1103         static QGlobalStatic<TYPE > thisGlobalStatic(&thisVariable); \
1104         return thisGlobalStatic.pointer;                             \
1105     }
1106
1107 #define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER)    \
1108     static TYPE *NAME()                                              \
1109     {                                                                \
1110         static TYPE thisVariable;                                    \
1111         static QGlobalStatic<TYPE > thisGlobalStatic(0);             \
1112         if (!thisGlobalStatic.pointer) {                             \
1113             TYPE *x = thisGlobalStatic.pointer = &thisVariable;      \
1114             INITIALIZER;                                             \
1115         }                                                            \
1116         return thisGlobalStatic.pointer;                             \
1117     }
1118
1119 #else
1120
1121 // forward declaration, since qatomic.h needs qglobal.h
1122 template <typename T> class QBasicAtomicPointer;
1123
1124 // POD for Q_GLOBAL_STATIC
1125 template <typename T>
1126 class QGlobalStatic
1127 {
1128 public:
1129     QBasicAtomicPointer<T> pointer;
1130     bool destroyed;
1131 };
1132
1133 // Created as a function-local static to delete a QGlobalStatic<T>
1134 template <typename T>
1135 class QGlobalStaticDeleter
1136 {
1137 public:
1138     QGlobalStatic<T> &globalStatic;
1139     QGlobalStaticDeleter(QGlobalStatic<T> &_globalStatic)
1140         : globalStatic(_globalStatic)
1141     { }
1142
1143     inline ~QGlobalStaticDeleter()
1144     {
1145         delete globalStatic.pointer.load();
1146         globalStatic.pointer.store(0);
1147         globalStatic.destroyed = true;
1148     }
1149 };
1150
1151 #define Q_GLOBAL_STATIC(TYPE, NAME)                                           \
1152     static TYPE *NAME()                                                       \
1153     {                                                                         \
1154         static QGlobalStatic<TYPE > thisGlobalStatic                          \
1155                             = { Q_BASIC_ATOMIC_INITIALIZER(0), false };       \
1156         if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { \
1157             TYPE *x = new TYPE;                                               \
1158             if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x))            \
1159                 delete x;                                                     \
1160             else                                                              \
1161                 static QGlobalStaticDeleter<TYPE > cleanup(thisGlobalStatic); \
1162         }                                                                     \
1163         return thisGlobalStatic.pointer.load();                               \
1164     }
1165
1166 #define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)                           \
1167     static TYPE *NAME()                                                       \
1168     {                                                                         \
1169         static QGlobalStatic<TYPE > thisGlobalStatic                          \
1170                             = { Q_BASIC_ATOMIC_INITIALIZER(0), false };       \
1171         if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) {       \
1172             TYPE *x = new TYPE ARGS;                                          \
1173             if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x))            \
1174                 delete x;                                                     \
1175             else                                                              \
1176                 static QGlobalStaticDeleter<TYPE > cleanup(thisGlobalStatic); \
1177         }                                                                     \
1178         return thisGlobalStatic.pointer.load();                               \
1179     }
1180
1181 #define Q_GLOBAL_STATIC_WITH_INITIALIZER(TYPE, NAME, INITIALIZER)             \
1182     static TYPE *NAME()                                                       \
1183     {                                                                         \
1184         static QGlobalStatic<TYPE > thisGlobalStatic                          \
1185                             = { Q_BASIC_ATOMIC_INITIALIZER(0), false };       \
1186         if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) {       \
1187             QScopedPointer<TYPE > x(new TYPE);                                \
1188             INITIALIZER;                                                      \
1189             if (thisGlobalStatic.pointer.testAndSetOrdered(0, x.data())) {    \
1190                 static QGlobalStaticDeleter<TYPE > cleanup(thisGlobalStatic); \
1191                 x.take();                                                     \
1192             }                                                                 \
1193         }                                                                     \
1194         return thisGlobalStatic.pointer.load();                               \
1195     }
1196
1197 #endif
1198
1199 Q_DECL_CONSTEXPR static inline bool qFuzzyCompare(double p1, double p2)
1200 {
1201     return (qAbs(p1 - p2) <= 0.000000000001 * qMin(qAbs(p1), qAbs(p2)));
1202 }
1203
1204 Q_DECL_CONSTEXPR static inline bool qFuzzyCompare(float p1, float p2)
1205 {
1206     return (qAbs(p1 - p2) <= 0.00001f * qMin(qAbs(p1), qAbs(p2)));
1207 }
1208
1209 /*!
1210   \internal
1211 */
1212 Q_DECL_CONSTEXPR static inline bool qFuzzyIsNull(double d)
1213 {
1214     return qAbs(d) <= 0.000000000001;
1215 }
1216
1217 /*!
1218   \internal
1219 */
1220 Q_DECL_CONSTEXPR static inline bool qFuzzyIsNull(float f)
1221 {
1222     return qAbs(f) <= 0.00001f;
1223 }
1224
1225 /*
1226    This function tests a double for a null value. It doesn't
1227    check whether the actual value is 0 or close to 0, but whether
1228    it is binary 0.
1229 */
1230 static inline bool qIsNull(double d)
1231 {
1232     union U {
1233         double d;
1234         quint64 u;
1235     };
1236     U val;
1237     val.d = d;
1238     return val.u == quint64(0);
1239 }
1240
1241 /*
1242    This function tests a float for a null value. It doesn't
1243    check whether the actual value is 0 or close to 0, but whether
1244    it is binary 0.
1245 */
1246 static inline bool qIsNull(float f)
1247 {
1248     union U {
1249         float f;
1250         quint32 u;
1251     };
1252     U val;
1253     val.f = f;
1254     return val.u == 0u;
1255 }
1256
1257 /*
1258    Compilers which follow outdated template instantiation rules
1259    require a class to have a comparison operator to exist when
1260    a QList of this type is instantiated. It's not actually
1261    used in the list, though. Hence the dummy implementation.
1262    Just in case other code relies on it we better trigger a warning
1263    mandating a real implementation.
1264 */
1265
1266 #ifdef Q_FULL_TEMPLATE_INSTANTIATION
1267 #  define Q_DUMMY_COMPARISON_OPERATOR(C) \
1268     bool operator==(const C&) const { \
1269         qWarning(#C"::operator==(const "#C"&) was called"); \
1270         return false; \
1271     }
1272 #else
1273
1274 #  define Q_DUMMY_COMPARISON_OPERATOR(C)
1275 #endif
1276
1277
1278 /*
1279    QTypeInfo     - type trait functionality
1280    qIsDetached   - data sharing functionality
1281 */
1282
1283 /*
1284   The catch-all template.
1285 */
1286
1287 template <typename T> inline bool qIsDetached(T &) { return true; }
1288
1289 template <typename T>
1290 class QTypeInfo
1291 {
1292 public:
1293     enum {
1294         isPointer = false,
1295         isComplex = true,
1296         isStatic = true,
1297         isLarge = (sizeof(T)>sizeof(void*)),
1298         isDummy = false,
1299         sizeOf = sizeof(T)
1300     };
1301 };
1302
1303 template<>
1304 class QTypeInfo<void>
1305 {
1306 public:
1307     enum {
1308         isPointer = false,
1309         isComplex = false,
1310         isStatic = false,
1311         isLarge = false,
1312         isDummy = false,
1313         sizeOf = 0
1314     };
1315 };
1316
1317 template <typename T>
1318 class QTypeInfo<T*>
1319 {
1320 public:
1321     enum {
1322         isPointer = true,
1323         isComplex = false,
1324         isStatic = false,
1325         isLarge = false,
1326         isDummy = false,
1327         sizeOf = sizeof(T*)
1328     };
1329 };
1330
1331
1332 #define Q_DECLARE_MOVABLE_CONTAINER(CONTAINER) \
1333 template <typename T> class CONTAINER; \
1334 template <typename T> \
1335 class QTypeInfo< CONTAINER<T> > \
1336 { \
1337 public: \
1338     enum { \
1339         isPointer = false, \
1340         isComplex = true, \
1341         isStatic = false, \
1342         isLarge = (sizeof(CONTAINER<T>) > sizeof(void*)), \
1343         isDummy = false, \
1344         sizeOf = sizeof(CONTAINER<T>) \
1345     }; \
1346 };
1347
1348 Q_DECLARE_MOVABLE_CONTAINER(QList)
1349 Q_DECLARE_MOVABLE_CONTAINER(QVector)
1350 Q_DECLARE_MOVABLE_CONTAINER(QQueue)
1351 Q_DECLARE_MOVABLE_CONTAINER(QStack)
1352 Q_DECLARE_MOVABLE_CONTAINER(QLinkedList)
1353 Q_DECLARE_MOVABLE_CONTAINER(QSet)
1354
1355 #undef Q_DECLARE_MOVABLE_CONTAINER
1356
1357 /*
1358    Specialize a specific type with:
1359
1360      Q_DECLARE_TYPEINFO(type, flags);
1361
1362    where 'type' is the name of the type to specialize and 'flags' is
1363    logically-OR'ed combination of the flags below.
1364 */
1365 enum { /* TYPEINFO flags */
1366     Q_COMPLEX_TYPE = 0,
1367     Q_PRIMITIVE_TYPE = 0x1,
1368     Q_STATIC_TYPE = 0,
1369     Q_MOVABLE_TYPE = 0x2,
1370     Q_DUMMY_TYPE = 0x4
1371 };
1372
1373 #define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS) \
1374 class QTypeInfo<TYPE > \
1375 { \
1376 public: \
1377     enum { \
1378         isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \
1379         isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \
1380         isLarge = (sizeof(TYPE)>sizeof(void*)), \
1381         isPointer = false, \
1382         isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0), \
1383         sizeOf = sizeof(TYPE) \
1384     }; \
1385     static inline const char *name() { return #TYPE; } \
1386 }
1387
1388 #define Q_DECLARE_TYPEINFO(TYPE, FLAGS) \
1389 template<> \
1390 Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS)
1391
1392
1393 template <typename T>
1394 inline void qSwap(T &value1, T &value2)
1395 {
1396 #ifdef QT_NO_STL
1397     const T t = value1;
1398     value1 = value2;
1399     value2 = t;
1400 #else
1401     using std::swap;
1402     swap(value1, value2);
1403 #endif
1404 }
1405
1406 /*
1407    Specialize a shared type with:
1408
1409      Q_DECLARE_SHARED(type);
1410
1411    where 'type' is the name of the type to specialize.  NOTE: shared
1412    types must declare a 'bool isDetached(void) const;' member for this
1413    to work.
1414 */
1415 #ifdef QT_NO_STL
1416 #define Q_DECLARE_SHARED_STL(TYPE)
1417 #else
1418 #define Q_DECLARE_SHARED_STL(TYPE) \
1419 QT_END_NAMESPACE \
1420 namespace std { \
1421     template<> inline void swap<QT_PREPEND_NAMESPACE(TYPE)>(QT_PREPEND_NAMESPACE(TYPE) &value1, QT_PREPEND_NAMESPACE(TYPE) &value2) \
1422     { swap(value1.data_ptr(), value2.data_ptr()); } \
1423 } \
1424 QT_BEGIN_NAMESPACE
1425 #endif
1426
1427 #define Q_DECLARE_SHARED(TYPE)                                          \
1428 template <> inline bool qIsDetached<TYPE>(TYPE &t) { return t.isDetached(); } \
1429 template <> inline void qSwap<TYPE>(TYPE &value1, TYPE &value2) \
1430 { qSwap(value1.data_ptr(), value2.data_ptr()); } \
1431 Q_DECLARE_SHARED_STL(TYPE)
1432
1433 /*
1434    QTypeInfo primitive specializations
1435 */
1436 Q_DECLARE_TYPEINFO(bool, Q_PRIMITIVE_TYPE);
1437 Q_DECLARE_TYPEINFO(char, Q_PRIMITIVE_TYPE);
1438 Q_DECLARE_TYPEINFO(signed char, Q_PRIMITIVE_TYPE);
1439 Q_DECLARE_TYPEINFO(uchar, Q_PRIMITIVE_TYPE);
1440 Q_DECLARE_TYPEINFO(short, Q_PRIMITIVE_TYPE);
1441 Q_DECLARE_TYPEINFO(ushort, Q_PRIMITIVE_TYPE);
1442 Q_DECLARE_TYPEINFO(int, Q_PRIMITIVE_TYPE);
1443 Q_DECLARE_TYPEINFO(uint, Q_PRIMITIVE_TYPE);
1444 Q_DECLARE_TYPEINFO(long, Q_PRIMITIVE_TYPE);
1445 Q_DECLARE_TYPEINFO(ulong, Q_PRIMITIVE_TYPE);
1446 Q_DECLARE_TYPEINFO(qint64, Q_PRIMITIVE_TYPE);
1447 Q_DECLARE_TYPEINFO(quint64, Q_PRIMITIVE_TYPE);
1448 Q_DECLARE_TYPEINFO(float, Q_PRIMITIVE_TYPE);
1449 Q_DECLARE_TYPEINFO(double, Q_PRIMITIVE_TYPE);
1450 #ifndef Q_OS_DARWIN
1451 Q_DECLARE_TYPEINFO(long double, Q_PRIMITIVE_TYPE);
1452 #endif
1453
1454 /*
1455    These functions make it possible to use standard C++ functions with
1456    a similar name from Qt header files (especially template classes).
1457 */
1458 Q_CORE_EXPORT void *qMalloc(size_t size) Q_ALLOC_SIZE(1);
1459 Q_CORE_EXPORT void qFree(void *ptr);
1460 Q_CORE_EXPORT void *qRealloc(void *ptr, size_t size) Q_ALLOC_SIZE(2);
1461 Q_CORE_EXPORT void *qMallocAligned(size_t size, size_t alignment) Q_ALLOC_SIZE(1);
1462 Q_CORE_EXPORT void *qReallocAligned(void *ptr, size_t size, size_t oldsize, size_t alignment) Q_ALLOC_SIZE(2);
1463 Q_CORE_EXPORT void qFreeAligned(void *ptr);
1464 Q_CORE_EXPORT void *qMemCopy(void *dest, const void *src, size_t n);
1465 Q_CORE_EXPORT void *qMemSet(void *dest, int c, size_t n);
1466
1467
1468 /*
1469    Avoid some particularly useless warnings from some stupid compilers.
1470    To get ALL C++ compiler warnings, define QT_CC_WARNINGS or comment out
1471    the line "#define QT_NO_WARNINGS".
1472 */
1473 #if !defined(QT_CC_WARNINGS)
1474 #  define QT_NO_WARNINGS
1475 #endif
1476 #if defined(QT_NO_WARNINGS)
1477 #  if defined(Q_CC_MSVC)
1478 #    pragma warning(disable: 4251) /* class 'A' needs to have dll interface for to be used by clients of class 'B'. */
1479 #    pragma warning(disable: 4244) /* 'conversion' conversion from 'type1' to 'type2', possible loss of data */
1480 #    pragma warning(disable: 4275) /* non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' */
1481 #    pragma warning(disable: 4514) /* unreferenced inline/local function has been removed */
1482 #    pragma warning(disable: 4800) /* 'type' : forcing value to bool 'true' or 'false' (performance warning) */
1483 #    pragma warning(disable: 4097) /* typedef-name 'identifier1' used as synonym for class-name 'identifier2' */
1484 #    pragma warning(disable: 4706) /* assignment within conditional expression */
1485 #    pragma warning(disable: 4786) /* truncating debug info after 255 characters */
1486 #    pragma warning(disable: 4660) /* template-class specialization 'identifier' is already instantiated */
1487 #    pragma warning(disable: 4355) /* 'this' : used in base member initializer list */
1488 #    pragma warning(disable: 4231) /* nonstandard extension used : 'extern' before template explicit instantiation */
1489 #    pragma warning(disable: 4710) /* function not inlined */
1490 #    pragma warning(disable: 4530) /* C++ exception handler used, but unwind semantics are not enabled. Specify -GX */
1491 #  elif defined(Q_CC_BOR)
1492 #    pragma option -w-inl
1493 #    pragma option -w-aus
1494 #    pragma warn -inl
1495 #    pragma warn -pia
1496 #    pragma warn -ccc
1497 #    pragma warn -rch
1498 #    pragma warn -sig
1499 #  endif
1500 #endif
1501
1502 class Q_CORE_EXPORT QFlag
1503 {
1504     int i;
1505 public:
1506     inline QFlag(int i);
1507     inline operator int() const { return i; }
1508 };
1509
1510 inline QFlag::QFlag(int ai) : i(ai) {}
1511
1512 class Q_CORE_EXPORT QIncompatibleFlag
1513 {
1514     int i;
1515 public:
1516     inline explicit QIncompatibleFlag(int i);
1517     inline operator int() const { return i; }
1518 };
1519
1520 inline QIncompatibleFlag::QIncompatibleFlag(int ai) : i(ai) {}
1521
1522
1523 #ifndef Q_NO_TYPESAFE_FLAGS
1524
1525 template<typename Enum>
1526 class QFlags
1527 {
1528     typedef void **Zero;
1529     int i;
1530 public:
1531     typedef Enum enum_type;
1532     Q_DECL_CONSTEXPR inline QFlags(const QFlags &f) : i(f.i) {}
1533     Q_DECL_CONSTEXPR inline QFlags(Enum f) : i(f) {}
1534     Q_DECL_CONSTEXPR inline QFlags(Zero = 0) : i(0) {}
1535     inline QFlags(QFlag f) : i(f) {}
1536
1537     inline QFlags &operator=(const QFlags &f) { i = f.i; return *this; }
1538     inline QFlags &operator&=(int mask) { i &= mask; return *this; }
1539     inline QFlags &operator&=(uint mask) { i &= mask; return *this; }
1540     inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; }
1541     inline QFlags &operator|=(Enum f) { i |= f; return *this; }
1542     inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; }
1543     inline QFlags &operator^=(Enum f) { i ^= f; return *this; }
1544
1545     Q_DECL_CONSTEXPR  inline operator int() const { return i; }
1546
1547     Q_DECL_CONSTEXPR inline QFlags operator|(QFlags f) const { return QFlags(Enum(i | f.i)); }
1548     Q_DECL_CONSTEXPR inline QFlags operator|(Enum f) const { return QFlags(Enum(i | f)); }
1549     Q_DECL_CONSTEXPR inline QFlags operator^(QFlags f) const { return QFlags(Enum(i ^ f.i)); }
1550     Q_DECL_CONSTEXPR inline QFlags operator^(Enum f) const { return QFlags(Enum(i ^ f)); }
1551     Q_DECL_CONSTEXPR inline QFlags operator&(int mask) const { return QFlags(Enum(i & mask)); }
1552     Q_DECL_CONSTEXPR inline QFlags operator&(uint mask) const { return QFlags(Enum(i & mask)); }
1553     Q_DECL_CONSTEXPR inline QFlags operator&(Enum f) const { return QFlags(Enum(i & f)); }
1554     Q_DECL_CONSTEXPR inline QFlags operator~() const { return QFlags(Enum(~i)); }
1555
1556     Q_DECL_CONSTEXPR inline bool operator!() const { return !i; }
1557
1558     inline bool testFlag(Enum f) const { return (i & f) == f && (f != 0 || i == int(f) ); }
1559 };
1560
1561 #define Q_DECLARE_FLAGS(Flags, Enum)\
1562 typedef QFlags<Enum> Flags;
1563
1564 #define Q_DECLARE_INCOMPATIBLE_FLAGS(Flags) \
1565 inline QIncompatibleFlag operator|(Flags::enum_type f1, int f2) \
1566 { return QIncompatibleFlag(int(f1) | f2); }
1567
1568 #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \
1569 Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
1570 { return QFlags<Flags::enum_type>(f1) | f2; } \
1571 Q_DECL_CONSTEXPR inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
1572 { return f2 | f1; } Q_DECLARE_INCOMPATIBLE_FLAGS(Flags)
1573
1574
1575 #else /* Q_NO_TYPESAFE_FLAGS */
1576
1577 #define Q_DECLARE_FLAGS(Flags, Enum)\
1578 typedef uint Flags;
1579 #define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
1580
1581 #endif /* Q_NO_TYPESAFE_FLAGS */
1582
1583 #if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && !defined(Q_CC_RVCT)
1584 /* make use of typeof-extension */
1585 template <typename T>
1586 class QForeachContainer {
1587 public:
1588     inline QForeachContainer(const T& t) : c(t), brk(0), i(c.begin()), e(c.end()) { }
1589     const T c;
1590     int brk;
1591     typename T::const_iterator i, e;
1592 };
1593
1594 #define Q_FOREACH(variable, container)                                \
1595 for (QForeachContainer<__typeof__(container)> _container_(container); \
1596      !_container_.brk && _container_.i != _container_.e;              \
1597      __extension__  ({ ++_container_.brk; ++_container_.i; }))                       \
1598     for (variable = *_container_.i;; __extension__ ({--_container_.brk; break;}))
1599
1600 #else
1601
1602 struct QForeachContainerBase {};
1603
1604 template <typename T>
1605 class QForeachContainer : public QForeachContainerBase {
1606 public:
1607     inline QForeachContainer(const T& t): c(t), brk(0), i(c.begin()), e(c.end()){}
1608     const T c;
1609     mutable int brk;
1610     mutable typename T::const_iterator i, e;
1611     inline bool condition() const { return (!brk++ && i != e); }
1612 };
1613
1614 template <typename T> inline T *qForeachPointer(const T &) { return 0; }
1615
1616 template <typename T> inline QForeachContainer<T> qForeachContainerNew(const T& t)
1617 { return QForeachContainer<T>(t); }
1618
1619 template <typename T>
1620 inline const QForeachContainer<T> *qForeachContainer(const QForeachContainerBase *base, const T *)
1621 { return static_cast<const QForeachContainer<T> *>(base); }
1622
1623 #if defined(Q_CC_MIPS)
1624 /*
1625    Proper for-scoping in MIPSpro CC
1626 */
1627 #  define Q_FOREACH(variable,container)                                                             \
1628     if(0){}else                                                                                     \
1629     for (const QForeachContainerBase &_container_ = qForeachContainerNew(container);                \
1630          qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->condition();       \
1631          ++qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i)               \
1632         for (variable = *qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i; \
1633              qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk;           \
1634              --qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk)
1635
1636 #elif defined(Q_CC_DIAB)
1637 // VxWorks DIAB generates unresolvable symbols, if container is a function call
1638 #  define Q_FOREACH(variable,container)                                                             \
1639     if(0){}else                                                                                     \
1640     for (const QForeachContainerBase &_container_ = qForeachContainerNew(container);                \
1641          qForeachContainer(&_container_, (__typeof__(container) *) 0)->condition();       \
1642          ++qForeachContainer(&_container_, (__typeof__(container) *) 0)->i)               \
1643         for (variable = *qForeachContainer(&_container_, (__typeof__(container) *) 0)->i; \
1644              qForeachContainer(&_container_, (__typeof__(container) *) 0)->brk;           \
1645              --qForeachContainer(&_container_, (__typeof__(container) *) 0)->brk)
1646
1647 #else
1648 #  define Q_FOREACH(variable, container) \
1649     for (const QForeachContainerBase &_container_ = qForeachContainerNew(container); \
1650          qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->condition();       \
1651          ++qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i)               \
1652         for (variable = *qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->i; \
1653              qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk;           \
1654              --qForeachContainer(&_container_, true ? 0 : qForeachPointer(container))->brk)
1655 #endif // MSVC6 || MIPSpro
1656
1657 #endif
1658
1659 #define Q_FOREVER for(;;)
1660 #ifndef QT_NO_KEYWORDS
1661 #  ifndef foreach
1662 #    define foreach Q_FOREACH
1663 #  endif
1664 #  ifndef forever
1665 #    define forever Q_FOREVER
1666 #  endif
1667 #endif
1668
1669 #if 0
1670 /* tell gcc to use its built-in methods for some common functions */
1671 #if defined(QT_NO_DEBUG) && defined(Q_CC_GNU)
1672 #  define qMemCopy __builtin_memcpy
1673 #  define qMemSet __builtin_memset
1674 #endif
1675 #endif
1676
1677 template <typename T> static inline T *qGetPtrHelper(T *ptr) { return ptr; }
1678 template <typename Wrapper> static inline typename Wrapper::pointer qGetPtrHelper(const Wrapper &p) { return p.data(); }
1679
1680 #define Q_DECLARE_PRIVATE(Class) \
1681     inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \
1682     inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \
1683     friend class Class##Private;
1684
1685 #define Q_DECLARE_PRIVATE_D(Dptr, Class) \
1686     inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(Dptr); } \
1687     inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(Dptr); } \
1688     friend class Class##Private;
1689
1690 #define Q_DECLARE_PUBLIC(Class)                                    \
1691     inline Class* q_func() { return static_cast<Class *>(q_ptr); } \
1692     inline const Class* q_func() const { return static_cast<const Class *>(q_ptr); } \
1693     friend class Class;
1694
1695 #define Q_D(Class) Class##Private * const d = d_func()
1696 #define Q_Q(Class) Class * const q = q_func()
1697
1698 #define QT_TR_NOOP(x) x
1699 #define QT_TR_NOOP_UTF8(x) x
1700 #define QT_TRANSLATE_NOOP(scope, x) x
1701 #define QT_TRANSLATE_NOOP_UTF8(scope, x) x
1702 #define QT_TRANSLATE_NOOP3(scope, x, comment) {x, comment}
1703 #define QT_TRANSLATE_NOOP3_UTF8(scope, x, comment) {x, comment}
1704
1705 #ifndef QT_NO_TRANSLATION // ### This should enclose the NOOPs above
1706
1707 // Defined in qcoreapplication.cpp
1708 // The better name qTrId() is reserved for an upcoming function which would
1709 // return a much more powerful QStringFormatter instead of a QString.
1710 Q_CORE_EXPORT QString qtTrId(const char *id, int n = -1);
1711
1712 #define QT_TRID_NOOP(id) id
1713
1714 #endif // QT_NO_TRANSLATION
1715
1716 #define QDOC_PROPERTY(text)
1717
1718 /*
1719    When RTTI is not available, define this macro to force any uses of
1720    dynamic_cast to cause a compile failure.
1721 */
1722
1723 #ifdef QT_NO_DYNAMIC_CAST
1724 #  define dynamic_cast QT_PREPEND_NAMESPACE(qt_dynamic_cast_check)
1725
1726   template<typename T, typename X>
1727   T qt_dynamic_cast_check(X, T* = 0)
1728   { return T::dynamic_cast_will_always_fail_because_rtti_is_disabled; }
1729 #endif
1730
1731 /*
1732    Some classes do not permit copies to be made of an object. These
1733    classes contains a private copy constructor and assignment
1734    operator to disable copying (the compiler gives an error message).
1735 */
1736 #define Q_DISABLE_COPY(Class) \
1737     Class(const Class &) Q_DECL_EQ_DELETE;\
1738     Class &operator=(const Class &) Q_DECL_EQ_DELETE;
1739
1740 class QByteArray;
1741 Q_CORE_EXPORT QByteArray qgetenv(const char *varName);
1742 Q_CORE_EXPORT bool qputenv(const char *varName, const QByteArray& value);
1743
1744 inline int qIntCast(double f) { return int(f); }
1745 inline int qIntCast(float f) { return int(f); }
1746
1747 /*
1748   Reentrant versions of basic rand() functions for random number generation
1749 */
1750 Q_CORE_EXPORT void qsrand(uint seed);
1751 Q_CORE_EXPORT int qrand();
1752
1753 #define QT_MODULE(x)
1754
1755 #ifdef QT_NO_CONCURRENT
1756 #  define QT_NO_QFUTURE
1757 #endif
1758
1759 // gcc 3 version has problems with some of the
1760 // map/filter overloads.
1761 #if defined(Q_CC_GNU) && (__GNUC__ < 4)
1762 #  define QT_NO_CONCURRENT_MAP
1763 #  define QT_NO_CONCURRENT_FILTER
1764 #endif
1765
1766 #ifdef Q_OS_QNX
1767 // QNX doesn't have SYSV style shared memory. Multiprocess QWS apps,
1768 // shared fonts and QSystemSemaphore + QSharedMemory are not available
1769 #  define QT_NO_QWS_MULTIPROCESS
1770 #  define QT_NO_QWS_SHARE_FONTS
1771 #  define QT_NO_SYSTEMSEMAPHORE
1772 #  define QT_NO_SHAREDMEMORY
1773 // QNX currently doesn't support forking in a thread, so disable QProcess
1774 #  define QT_NO_PROCESS
1775 #endif
1776
1777 #if defined (__ELF__)
1778 #  if defined (Q_OS_LINUX) || defined (Q_OS_SOLARIS) || defined (Q_OS_FREEBSD) || defined (Q_OS_OPENBSD) || defined (Q_OS_IRIX)
1779 #    define Q_OF_ELF
1780 #  endif
1781 #endif
1782
1783 #if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && !defined(__PIC__)
1784 #  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
1785          "Compile your code with -fPIC or -fPIE."
1786 #endif
1787
1788 namespace QtPrivate {
1789 //like std::enable_if
1790 template <bool B, typename T = void> struct QEnableIf;
1791 template <typename T> struct QEnableIf<true, T> { typedef T Type; };
1792 }
1793
1794 QT_END_NAMESPACE
1795 QT_END_HEADER
1796
1797 // qDebug and friends
1798 #include <QtCore/qlogging.h>
1799
1800 #endif /* __cplusplus */
1801
1802 #endif /* QGLOBAL_H */