Reshuffle code between qglobal, qlogging
[profile/ivi/qtbase.git] / src / corelib / global / qglobal.cpp
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 #include "qplatformdefs.h"
43 #include "qstring.h"
44 #include "qvector.h"
45 #include "qlist.h"
46 #include "qthreadstorage.h"
47 #include "qdir.h"
48 #include "qdatetime.h"
49
50 #ifndef QT_NO_QOBJECT
51 #include <private/qthread_p.h>
52 #endif
53
54 #include <stdlib.h>
55 #include <limits.h>
56 #include <stdarg.h>
57 #include <string.h>
58
59 #ifndef QT_NO_EXCEPTIONS
60 #  include <string>
61 #  include <exception>
62 #endif
63
64 #if !defined(Q_OS_WINCE)
65 #  include <errno.h>
66 #  if defined(Q_CC_MSVC)
67 #    include <crtdbg.h>
68 #  endif
69 #endif
70
71 #if defined(Q_OS_VXWORKS)
72 #  include <envLib.h>
73 #endif
74
75 #if defined(Q_OS_MACX) && !defined(QT_NO_CORESERVICES)
76 #include <CoreServices/CoreServices.h>
77 #endif
78
79 QT_BEGIN_NAMESPACE
80
81
82 /*!
83     \class QFlag
84     \brief The QFlag class is a helper data type for QFlags.
85
86     It is equivalent to a plain \c int, except with respect to
87     function overloading and type conversions. You should never need
88     to use this class in your applications.
89
90     \sa QFlags
91 */
92
93 /*!
94     \fn QFlag::QFlag(int value)
95
96     Constructs a QFlag object that stores the given \a value.
97 */
98
99 /*!
100     \fn QFlag::operator int() const
101
102     Returns the value stored by the QFlag object.
103 */
104
105 /*!
106     \class QFlags
107     \brief The QFlags class provides a type-safe way of storing
108     OR-combinations of enum values.
109
110
111     \ingroup tools
112
113     The QFlags<Enum> class is a template class, where Enum is an enum
114     type. QFlags is used throughout Qt for storing combinations of
115     enum values.
116
117     The traditional C++ approach for storing OR-combinations of enum
118     values is to use an \c int or \c uint variable. The inconvenience
119     with this approach is that there's no type checking at all; any
120     enum value can be OR'd with any other enum value and passed on to
121     a function that takes an \c int or \c uint.
122
123     Qt uses QFlags to provide type safety. For example, the
124     Qt::Alignment type is simply a typedef for
125     QFlags<Qt::AlignmentFlag>. QLabel::setAlignment() takes a
126     Qt::Alignment parameter, which means that any combination of
127     Qt::AlignmentFlag values,or 0, is legal:
128
129     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 0
130
131     If you try to pass a value from another enum or just a plain
132     integer other than 0, the compiler will report an error. If you
133     need to cast integer values to flags in a untyped fashion, you can
134     use the explicit QFlags constructor as cast operator.
135
136     If you want to use QFlags for your own enum types, use
137     the Q_DECLARE_FLAGS() and Q_DECLARE_OPERATORS_FOR_FLAGS().
138
139     Example:
140
141     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 1
142
143     You can then use the \c MyClass::Options type to store
144     combinations of \c MyClass::Option values.
145
146     \section1 Flags and the Meta-Object System
147
148     The Q_DECLARE_FLAGS() macro does not expose the flags to the meta-object
149     system, so they cannot be used by Qt Script or edited in Qt Designer.
150     To make the flags available for these purposes, the Q_FLAGS() macro must
151     be used:
152
153     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp meta-object flags
154
155     \section1 Naming Convention
156
157     A sensible naming convention for enum types and associated QFlags
158     types is to give a singular name to the enum type (e.g., \c
159     Option) and a plural name to the QFlags type (e.g., \c Options).
160     When a singular name is desired for the QFlags type (e.g., \c
161     Alignment), you can use \c Flag as the suffix for the enum type
162     (e.g., \c AlignmentFlag).
163
164     \sa QFlag
165 */
166
167 /*!
168     \typedef QFlags::enum_type
169
170     Typedef for the Enum template type.
171 */
172
173 /*!
174     \fn QFlags::QFlags(const QFlags &other)
175
176     Constructs a copy of \a other.
177 */
178
179 /*!
180     \fn QFlags::QFlags(Enum flag)
181
182     Constructs a QFlags object storing the given \a flag.
183 */
184
185 /*!
186     \fn QFlags::QFlags(Zero zero)
187
188     Constructs a QFlags object with no flags set. \a zero must be a
189     literal 0 value.
190 */
191
192 /*!
193     \fn QFlags::QFlags(QFlag value)
194
195     Constructs a QFlags object initialized with the given integer \a
196     value.
197
198     The QFlag type is a helper type. By using it here instead of \c
199     int, we effectively ensure that arbitrary enum values cannot be
200     cast to a QFlags, whereas untyped enum values (i.e., \c int
201     values) can.
202 */
203
204 /*!
205     \fn QFlags &QFlags::operator=(const QFlags &other)
206
207     Assigns \a other to this object and returns a reference to this
208     object.
209 */
210
211 /*!
212     \fn QFlags &QFlags::operator&=(int mask)
213
214     Performs a bitwise AND operation with \a mask and stores the
215     result in this QFlags object. Returns a reference to this object.
216
217     \sa operator&(), operator|=(), operator^=()
218 */
219
220 /*!
221     \fn QFlags &QFlags::operator&=(uint mask)
222
223     \overload
224 */
225
226 /*!
227     \fn QFlags &QFlags::operator|=(QFlags other)
228
229     Performs a bitwise OR operation with \a other and stores the
230     result in this QFlags object. Returns a reference to this object.
231
232     \sa operator|(), operator&=(), operator^=()
233 */
234
235 /*!
236     \fn QFlags &QFlags::operator|=(Enum other)
237
238     \overload
239 */
240
241 /*!
242     \fn QFlags &QFlags::operator^=(QFlags other)
243
244     Performs a bitwise XOR operation with \a other and stores the
245     result in this QFlags object. Returns a reference to this object.
246
247     \sa operator^(), operator&=(), operator|=()
248 */
249
250 /*!
251     \fn QFlags &QFlags::operator^=(Enum other)
252
253     \overload
254 */
255
256 /*!
257     \fn QFlags::operator int() const
258
259     Returns the value stored in the QFlags object as an integer.
260 */
261
262 /*!
263     \fn QFlags QFlags::operator|(QFlags other) const
264
265     Returns a QFlags object containing the result of the bitwise OR
266     operation on this object and \a other.
267
268     \sa operator|=(), operator^(), operator&(), operator~()
269 */
270
271 /*!
272     \fn QFlags QFlags::operator|(Enum other) const
273
274     \overload
275 */
276
277 /*!
278     \fn QFlags QFlags::operator^(QFlags other) const
279
280     Returns a QFlags object containing the result of the bitwise XOR
281     operation on this object and \a other.
282
283     \sa operator^=(), operator&(), operator|(), operator~()
284 */
285
286 /*!
287     \fn QFlags QFlags::operator^(Enum other) const
288
289     \overload
290 */
291
292 /*!
293     \fn QFlags QFlags::operator&(int mask) const
294
295     Returns a QFlags object containing the result of the bitwise AND
296     operation on this object and \a mask.
297
298     \sa operator&=(), operator|(), operator^(), operator~()
299 */
300
301 /*!
302     \fn QFlags QFlags::operator&(uint mask) const
303
304     \overload
305 */
306
307 /*!
308     \fn QFlags QFlags::operator&(Enum mask) const
309
310     \overload
311 */
312
313 /*!
314     \fn QFlags QFlags::operator~() const
315
316     Returns a QFlags object that contains the bitwise negation of
317     this object.
318
319     \sa operator&(), operator|(), operator^()
320 */
321
322 /*!
323     \fn bool QFlags::operator!() const
324
325     Returns true if no flag is set (i.e., if the value stored by the
326     QFlags object is 0); otherwise returns false.
327 */
328
329 /*!
330     \fn bool QFlags::testFlag(Enum flag) const
331     \since 4.2
332
333     Returns true if the \a flag is set, otherwise false.
334 */
335
336 /*!
337   \macro Q_DISABLE_COPY(Class)
338   \relates QObject
339
340   Disables the use of copy constructors and assignment operators
341   for the given \a Class.
342
343   Instances of subclasses of QObject should not be thought of as
344   values that can be copied or assigned, but as unique identities.
345   This means that when you create your own subclass of QObject
346   (director or indirect), you should \e not give it a copy constructor
347   or an assignment operator.  However, it may not enough to simply
348   omit them from your class, because, if you mistakenly write some code
349   that requires a copy constructor or an assignment operator (it's easy
350   to do), your compiler will thoughtfully create it for you. You must
351   do more.
352
353   The curious user will have seen that the Qt classes derived
354   from QObject typically include this macro in a private section:
355
356   \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 43
357
358   It declares a copy constructor and an assignment operator in the
359   private section, so that if you use them by mistake, the compiler
360   will report an error.
361
362   \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 44
363
364   But even this might not catch absolutely every case. You might be
365   tempted to do something like this:
366
367   \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 45
368
369   First of all, don't do that. Most compilers will generate code that
370   uses the copy constructor, so the privacy violation error will be
371   reported, but your C++ compiler is not required to generate code for
372   this statement in a specific way. It could generate code using
373   \e{neither} the copy constructor \e{nor} the assignment operator we
374   made private. In that case, no error would be reported, but your
375   application would probably crash when you called a member function
376   of \c{w}.
377 */
378
379 /*!
380     \macro Q_DECLARE_FLAGS(Flags, Enum)
381     \relates QFlags
382
383     The Q_DECLARE_FLAGS() macro expands to
384
385     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 2
386
387     \a Enum is the name of an existing enum type, whereas \a Flags is
388     the name of the QFlags<\e{Enum}> typedef.
389
390     See the QFlags documentation for details.
391
392     \sa Q_DECLARE_OPERATORS_FOR_FLAGS()
393 */
394
395 /*!
396     \macro Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
397     \relates QFlags
398
399     The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global \c
400     operator|() functions for \a Flags, which is of type QFlags<T>.
401
402     See the QFlags documentation for details.
403
404     \sa Q_DECLARE_FLAGS()
405 */
406
407 /*!
408     \headerfile <QtGlobal>
409     \title Global Qt Declarations
410     \ingroup funclists
411
412     \brief The <QtGlobal> header file includes the fundamental global
413     declarations. It is included by most other Qt header files.
414
415     The global declarations include \l{types}, \l{functions} and
416     \l{macros}.
417
418     The type definitions are partly convenience definitions for basic
419     types (some of which guarantee certain bit-sizes on all platforms
420     supported by Qt), partly types related to Qt message handling. The
421     functions are related to generating messages, Qt version handling
422     and comparing and adjusting object values. And finally, some of
423     the declared macros enable programmers to add compiler or platform
424     specific code to their applications, while others are convenience
425     macros for larger operations.
426
427     \section1 Types
428
429     The header file declares several type definitions that guarantee a
430     specified bit-size on all platforms supported by Qt for various
431     basic types, for example \l qint8 which is a signed char
432     guaranteed to be 8-bit on all platforms supported by Qt. The
433     header file also declares the \l qlonglong type definition for \c
434     {long long int } (\c __int64 on Windows).
435
436     Several convenience type definitions are declared: \l qreal for \c
437     double, \l uchar for \c unsigned char, \l uint for \c unsigned
438     int, \l ulong for \c unsigned long and \l ushort for \c unsigned
439     short.
440
441     Finally, the QtMsgType definition identifies the various messages
442     that can be generated and sent to a Qt message handler;
443     QMessageHandler is a type definition for a pointer to a function with
444     the signature
445     \c {void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *)}.
446     QMessageLogContext class contains the line, file, and function the
447     message was logged at. This information is created by the QMessageLogger
448     class.
449
450     \section1 Functions
451
452     The <QtGlobal> header file contains several functions comparing
453     and adjusting an object's value. These functions take a template
454     type as argument: You can retrieve the absolute value of an object
455     using the qAbs() function, and you can bound a given object's
456     value by given minimum and maximum values using the qBound()
457     function. You can retrieve the minimum and maximum of two given
458     objects using qMin() and qMax() respectively. All these functions
459     return a corresponding template type; the template types can be
460     replaced by any other type.
461
462     Example:
463
464     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 3
465
466     <QtGlobal> also contains functions that generate messages from the
467     given string argument: qCritical(), qDebug(), qFatal() and
468     qWarning(). These functions call the message handler with the
469     given message.
470
471     Example:
472
473     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 4
474
475     The remaining functions are qRound() and qRound64(), which both
476     accept a \l qreal value as their argument returning the value
477     rounded up to the nearest integer and 64-bit integer respectively,
478     the qInstallMessageHandler() function which installs the given
479     QMessageHandler, and the qVersion() function which returns the
480     version number of Qt at run-time as a string.
481
482     \section1 Macros
483
484     The <QtGlobal> header file provides a range of macros (Q_CC_*)
485     that are defined if the application is compiled using the
486     specified platforms. For example, the Q_CC_SUN macro is defined if
487     the application is compiled using Forte Developer, or Sun Studio
488     C++.  The header file also declares a range of macros (Q_OS_*)
489     that are defined for the specified platforms. For example,
490     Q_OS_X11 which is defined for the X Window System.
491
492     The purpose of these macros is to enable programmers to add
493     compiler or platform specific code to their application.
494
495     The remaining macros are convenience macros for larger operations:
496     The QT_TRANSLATE_NOOP() and QT_TR_NOOP() macros provide the
497     possibility of marking text for dynamic translation,
498     i.e. translation without changing the stored source text. The
499     Q_ASSERT() and Q_ASSERT_X() enables warning messages of various
500     level of refinement. The Q_FOREACH() and foreach() macros
501     implement Qt's foreach loop.
502
503     The Q_INT64_C() and Q_UINT64_C() macros wrap signed and unsigned
504     64-bit integer literals in a platform-independent way. The
505     Q_CHECK_PTR() macro prints a warning containing the source code's
506     file name and line number, saying that the program ran out of
507     memory, if the pointer is 0. The qPrintable() macro represent an
508     easy way of printing text.
509
510     Finally, the QT_POINTER_SIZE macro expands to the size of a
511     pointer in bytes, and the QT_VERSION and QT_VERSION_STR macros
512     expand to a numeric value or a string, respectively, specifying
513     Qt's version number, i.e the version the application is compiled
514     against.
515
516     \sa <QtAlgorithms>, QSysInfo
517 */
518
519 /*!
520     \typedef qreal
521     \relates <QtGlobal>
522
523     Typedef for \c double on all platforms except for those using CPUs with
524     ARM architectures.
525     On ARM-based platforms, \c qreal is a typedef for \c float for performance
526     reasons.
527 */
528
529 /*! \typedef uchar
530     \relates <QtGlobal>
531
532     Convenience typedef for \c{unsigned char}.
533 */
534
535 /*!
536     \fn qt_set_sequence_auto_mnemonic(bool on)
537     \relates <QtGlobal>
538
539     Enables automatic mnemonics on Mac if \a on is true; otherwise
540     this feature is disabled.
541
542     Note that this function is only available on Mac where mnemonics
543     are disabled by default.
544
545     To access to this function, use an extern declaration:
546     extern void qt_set_sequence_auto_mnemonic(bool b);
547
548     \sa {QShortcut#mnemonic}{QShortcut}
549 */
550
551 /*! \typedef ushort
552     \relates <QtGlobal>
553
554     Convenience typedef for \c{unsigned short}.
555 */
556
557 /*! \typedef uint
558     \relates <QtGlobal>
559
560     Convenience typedef for \c{unsigned int}.
561 */
562
563 /*! \typedef ulong
564     \relates <QtGlobal>
565
566     Convenience typedef for \c{unsigned long}.
567 */
568
569 /*! \typedef qint8
570     \relates <QtGlobal>
571
572     Typedef for \c{signed char}. This type is guaranteed to be 8-bit
573     on all platforms supported by Qt.
574 */
575
576 /*!
577     \typedef quint8
578     \relates <QtGlobal>
579
580     Typedef for \c{unsigned char}. This type is guaranteed to
581     be 8-bit on all platforms supported by Qt.
582 */
583
584 /*! \typedef qint16
585     \relates <QtGlobal>
586
587     Typedef for \c{signed short}. This type is guaranteed to be
588     16-bit on all platforms supported by Qt.
589 */
590
591 /*!
592     \typedef quint16
593     \relates <QtGlobal>
594
595     Typedef for \c{unsigned short}. This type is guaranteed to
596     be 16-bit on all platforms supported by Qt.
597 */
598
599 /*! \typedef qint32
600     \relates <QtGlobal>
601
602     Typedef for \c{signed int}. This type is guaranteed to be 32-bit
603     on all platforms supported by Qt.
604 */
605
606 /*!
607     \typedef quint32
608     \relates <QtGlobal>
609
610     Typedef for \c{unsigned int}. This type is guaranteed to
611     be 32-bit on all platforms supported by Qt.
612 */
613
614 /*! \typedef qint64
615     \relates <QtGlobal>
616
617     Typedef for \c{long long int} (\c __int64 on Windows). This type
618     is guaranteed to be 64-bit on all platforms supported by Qt.
619
620     Literals of this type can be created using the Q_INT64_C() macro:
621
622     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 5
623
624     \sa Q_INT64_C(), quint64, qlonglong
625 */
626
627 /*!
628     \typedef quint64
629     \relates <QtGlobal>
630
631     Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
632     Windows). This type is guaranteed to be 64-bit on all platforms
633     supported by Qt.
634
635     Literals of this type can be created using the Q_UINT64_C()
636     macro:
637
638     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 6
639
640     \sa Q_UINT64_C(), qint64, qulonglong
641 */
642
643 /*!
644     \typedef quintptr
645     \relates <QtGlobal>
646
647     Integral type for representing a pointers (useful for hashing,
648     etc.).
649
650     Typedef for either quint32 or quint64. This type is guaranteed to
651     be the same size as a pointer on all platforms supported by Qt. On
652     a system with 32-bit pointers, quintptr is a typedef for quint32;
653     on a system with 64-bit pointers, quintptr is a typedef for
654     quint64.
655
656     Note that quintptr is unsigned. Use qptrdiff for signed values.
657
658     \sa qptrdiff, quint32, quint64
659 */
660
661 /*!
662     \typedef qptrdiff
663     \relates <QtGlobal>
664
665     Integral type for representing pointer differences.
666
667     Typedef for either qint32 or qint64. This type is guaranteed to be
668     the same size as a pointer on all platforms supported by Qt. On a
669     system with 32-bit pointers, quintptr is a typedef for quint32; on
670     a system with 64-bit pointers, quintptr is a typedef for quint64.
671
672     Note that qptrdiff is signed. Use quintptr for unsigned values.
673
674     \sa quintptr, qint32, qint64
675 */
676
677 /*!
678     \enum QtMsgType
679     \relates <QtGlobal>
680
681     This enum describes the messages that can be sent to a message
682     handler (QtMsgHandler). You can use the enum to identify and
683     associate the various message types with the appropriate
684     actions.
685
686     \value QtDebugMsg
687            A message generated by the qDebug() function.
688     \value QtWarningMsg
689            A message generated by the qWarning() function.
690     \value QtCriticalMsg
691            A message generated by the qCritical() function.
692     \value QtFatalMsg
693            A message generated by the qFatal() function.
694     \value QtSystemMsg
695
696
697     \sa QMessageHandler, qInstallMessageHandler()
698 */
699
700 /*! \typedef QFunctionPointer
701     \relates <QtGlobal>
702
703     This is a typedef for \c{void (*)()}, a pointer to a function that takes
704     no arguments and returns void.
705 */
706
707 /*! \macro qint64 Q_INT64_C(literal)
708     \relates <QtGlobal>
709
710     Wraps the signed 64-bit integer \a literal in a
711     platform-independent way.
712
713     Example:
714
715     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 8
716
717     \sa qint64, Q_UINT64_C()
718 */
719
720 /*! \macro quint64 Q_UINT64_C(literal)
721     \relates <QtGlobal>
722
723     Wraps the unsigned 64-bit integer \a literal in a
724     platform-independent way.
725
726     Example:
727
728     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 9
729
730     \sa quint64, Q_INT64_C()
731 */
732
733 /*! \typedef qlonglong
734     \relates <QtGlobal>
735
736     Typedef for \c{long long int} (\c __int64 on Windows). This is
737     the same as \l qint64.
738
739     \sa qulonglong, qint64
740 */
741
742 /*!
743     \typedef qulonglong
744     \relates <QtGlobal>
745
746     Typedef for \c{unsigned long long int} (\c{unsigned __int64} on
747     Windows). This is the same as \l quint64.
748
749     \sa quint64, qlonglong
750 */
751
752 /*! \fn const T &qAbs(const T &value)
753     \relates <QtGlobal>
754
755     Compares \a value to the 0 of type T and returns the absolute
756     value. Thus if T is \e {double}, then \a value is compared to
757     \e{(double) 0}.
758
759     Example:
760
761     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 10
762 */
763
764 /*! \fn int qRound(qreal value)
765     \relates <QtGlobal>
766
767     Rounds \a value to the nearest integer.
768
769     Example:
770
771     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 11
772 */
773
774 /*! \fn qint64 qRound64(qreal value)
775     \relates <QtGlobal>
776
777     Rounds \a value to the nearest 64-bit integer.
778
779     Example:
780
781     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 12
782 */
783
784 /*! \fn const T &qMin(const T &value1, const T &value2)
785     \relates <QtGlobal>
786
787     Returns the minimum of \a value1 and \a value2.
788
789     Example:
790
791     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 13
792
793     \sa qMax(), qBound()
794 */
795
796 /*! \fn const T &qMax(const T &value1, const T &value2)
797     \relates <QtGlobal>
798
799     Returns the maximum of \a value1 and \a value2.
800
801     Example:
802
803     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 14
804
805     \sa qMin(), qBound()
806 */
807
808 /*! \fn const T &qBound(const T &min, const T &value, const T &max)
809     \relates <QtGlobal>
810
811     Returns \a value bounded by \a min and \a max. This is equivalent
812     to qMax(\a min, qMin(\a value, \a max)).
813
814     Example:
815
816     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 15
817
818     \sa qMin(), qMax()
819 */
820
821 /*!
822     \fn int qMacVersion()
823     \relates <QtGlobal>
824
825     Use QSysInfo::MacintoshVersion instead.
826
827     \sa QSysInfo
828 */
829
830 /*!
831     \macro QT_VERSION_CHECK
832     \relates <QtGlobal>
833
834     Turns the major, minor and patch numbers of a version into an
835     integer, 0xMMNNPP (MM = major, NN = minor, PP = patch). This can
836     be compared with another similarly processed version id.
837
838     \sa QT_VERSION
839 */
840
841 /*!
842     \macro QT_VERSION
843     \relates <QtGlobal>
844
845     This macro expands a numeric value of the form 0xMMNNPP (MM =
846     major, NN = minor, PP = patch) that specifies Qt's version
847     number. For example, if you compile your application against Qt
848     4.1.2, the QT_VERSION macro will expand to 0x040102.
849
850     You can use QT_VERSION to use the latest Qt features where
851     available.
852
853     Example:
854
855     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 16
856
857     \sa QT_VERSION_STR, qVersion()
858 */
859
860 /*!
861     \macro QT_VERSION_STR
862     \relates <QtGlobal>
863
864     This macro expands to a string that specifies Qt's version number
865     (for example, "4.1.2"). This is the version against which the
866     application is compiled.
867
868     \sa qVersion(), QT_VERSION
869 */
870
871 /*!
872     \relates <QtGlobal>
873
874     Returns the version number of Qt at run-time as a string (for
875     example, "4.1.2"). This may be a different version than the
876     version the application was compiled against.
877
878     \sa QT_VERSION_STR
879 */
880
881 const char *qVersion()
882 {
883     return QT_VERSION_STR;
884 }
885
886 bool qSharedBuild()
887 {
888 #ifdef QT_SHARED
889     return true;
890 #else
891     return false;
892 #endif
893 }
894
895 /*****************************************************************************
896   System detection routines
897  *****************************************************************************/
898
899 /*!
900     \class QSysInfo
901     \brief The QSysInfo class provides information about the system.
902
903     \list
904     \o \l WordSize specifies the size of a pointer for the platform
905        on which the application is compiled.
906     \o \l ByteOrder specifies whether the platform is big-endian or
907        little-endian.
908     \o \l WindowsVersion specifies the version of the Windows operating
909        system on which the application is run (Windows only)
910     \o \l MacintoshVersion specifies the version of the Macintosh
911        operating system on which the application is run (Mac only).
912     \endlist
913
914     Some constants are defined only on certain platforms. You can use
915     the preprocessor symbols Q_OS_WIN and Q_OS_MAC to test that
916     the application is compiled under Windows or Mac.
917
918     \sa QLibraryInfo
919 */
920
921 /*!
922     \enum QSysInfo::Sizes
923
924     This enum provides platform-specific information about the sizes of data
925     structures used by the underlying architecture.
926
927     \value WordSize The size in bits of a pointer for the platform on which
928            the application is compiled (32 or 64).
929 */
930
931 /*!
932     \variable QSysInfo::WindowsVersion
933     \brief the version of the Windows operating system on which the
934            application is run (Windows only)
935 */
936
937 /*!
938     \fn QSysInfo::WindowsVersion QSysInfo::windowsVersion()
939     \since 4.4
940
941     Returns the version of the Windows operating system on which the
942     application is run (Windows only).
943 */
944
945 /*!
946     \variable QSysInfo::MacintoshVersion
947     \brief the version of the Macintosh operating system on which
948            the application is run (Mac only).
949 */
950
951 /*!
952     \enum QSysInfo::Endian
953
954     \value BigEndian  Big-endian byte order (also called Network byte order)
955     \value LittleEndian  Little-endian byte order
956     \value ByteOrder  Equals BigEndian or LittleEndian, depending on
957                       the platform's byte order.
958 */
959
960 /*!
961     \enum QSysInfo::WinVersion
962
963     This enum provides symbolic names for the various versions of the
964     Windows operating system. On Windows, the
965     QSysInfo::WindowsVersion variable gives the version of the system
966     on which the application is run.
967
968     MS-DOS-based versions:
969
970     \value WV_32s   Windows 3.1 with Win 32s
971     \value WV_95    Windows 95
972     \value WV_98    Windows 98
973     \value WV_Me    Windows Me
974
975     NT-based versions (note that each operating system version is only represented once rather than each Windows edition):
976
977     \value WV_NT    Windows NT (operating system version 4.0)
978     \value WV_2000  Windows 2000 (operating system version 5.0)
979     \value WV_XP    Windows XP (operating system version 5.1)
980     \value WV_2003  Windows Server 2003, Windows Server 2003 R2, Windows Home Server, Windows XP Professional x64 Edition (operating system version 5.2)
981     \value WV_VISTA Windows Vista, Windows Server 2008 (operating system version 6.0)
982     \value WV_WINDOWS7 Windows 7, Windows Server 2008 R2 (operating system version 6.1)
983
984     Alternatively, you may use the following macros which correspond directly to the Windows operating system version number:
985
986     \value WV_4_0   Operating system version 4.0, corresponds to Windows NT
987     \value WV_5_0   Operating system version 5.0, corresponds to Windows 2000
988     \value WV_5_1   Operating system version 5.1, corresponds to Windows XP
989     \value WV_5_2   Operating system version 5.2, corresponds to Windows Server 2003, Windows Server 2003 R2, Windows Home Server, and Windows XP Professional x64 Edition
990     \value WV_6_0   Operating system version 6.0, corresponds to Windows Vista and Windows Server 2008
991     \value WV_6_1   Operating system version 6.1, corresponds to Windows 7 and Windows Server 2008 R2
992
993     CE-based versions:
994
995     \value WV_CE    Windows CE
996     \value WV_CENET Windows CE .NET
997     \value WV_CE_5  Windows CE 5.x
998     \value WV_CE_6  Windows CE 6.x
999
1000     The following masks can be used for testing whether a Windows
1001     version is MS-DOS-based, NT-based, or CE-based:
1002
1003     \value WV_DOS_based MS-DOS-based version of Windows
1004     \value WV_NT_based  NT-based version of Windows
1005     \value WV_CE_based  CE-based version of Windows
1006
1007     \sa MacVersion
1008 */
1009
1010 /*!
1011     \enum QSysInfo::MacVersion
1012
1013     This enum provides symbolic names for the various versions of the
1014     Macintosh operating system. On Mac, the
1015     QSysInfo::MacintoshVersion variable gives the version of the
1016     system on which the application is run.
1017
1018     \value MV_9        Mac OS 9 (unsupported)
1019     \value MV_10_0     Mac OS X 10.0 (unsupported)
1020     \value MV_10_1     Mac OS X 10.1 (unsupported)
1021     \value MV_10_2     Mac OS X 10.2 (unsupported)
1022     \value MV_10_3     Mac OS X 10.3
1023     \value MV_10_4     Mac OS X 10.4
1024     \value MV_10_5     Mac OS X 10.5
1025     \value MV_10_6     Mac OS X 10.6
1026     \value MV_10_7     Mac OS X 10.7
1027     \value MV_Unknown  An unknown and currently unsupported platform
1028
1029     \value MV_CHEETAH  Apple codename for MV_10_0
1030     \value MV_PUMA     Apple codename for MV_10_1
1031     \value MV_JAGUAR   Apple codename for MV_10_2
1032     \value MV_PANTHER  Apple codename for MV_10_3
1033     \value MV_TIGER    Apple codename for MV_10_4
1034     \value MV_LEOPARD  Apple codename for MV_10_5
1035     \value MV_SNOWLEOPARD  Apple codename for MV_10_6
1036     \value MV_LION     Apple codename for MV_10_7
1037
1038     \sa WinVersion
1039 */
1040
1041 /*!
1042     \macro Q_OS_DARWIN
1043     \relates <QtGlobal>
1044
1045     Defined on Darwin OS (synonym for Q_OS_MAC).
1046 */
1047
1048 /*!
1049     \macro Q_OS_WIN32
1050     \relates <QtGlobal>
1051
1052     Defined on all supported versions of Windows.
1053 */
1054
1055 /*!
1056     \macro Q_OS_WINCE
1057     \relates <QtGlobal>
1058
1059     Defined on Windows CE.
1060 */
1061
1062 /*!
1063     \macro Q_OS_CYGWIN
1064     \relates <QtGlobal>
1065
1066     Defined on Cygwin.
1067 */
1068
1069 /*!
1070     \macro Q_OS_SOLARIS
1071     \relates <QtGlobal>
1072
1073     Defined on Sun Solaris.
1074 */
1075
1076 /*!
1077     \macro Q_OS_HPUX
1078     \relates <QtGlobal>
1079
1080     Defined on HP-UX.
1081 */
1082
1083 /*!
1084     \macro Q_OS_ULTRIX
1085     \relates <QtGlobal>
1086
1087     Defined on DEC Ultrix.
1088 */
1089
1090 /*!
1091     \macro Q_OS_LINUX
1092     \relates <QtGlobal>
1093
1094     Defined on Linux.
1095 */
1096
1097 /*!
1098     \macro Q_OS_FREEBSD
1099     \relates <QtGlobal>
1100
1101     Defined on FreeBSD.
1102 */
1103
1104 /*!
1105     \macro Q_OS_NETBSD
1106     \relates <QtGlobal>
1107
1108     Defined on NetBSD.
1109 */
1110
1111 /*!
1112     \macro Q_OS_OPENBSD
1113     \relates <QtGlobal>
1114
1115     Defined on OpenBSD.
1116 */
1117
1118 /*!
1119     \macro Q_OS_BSDI
1120     \relates <QtGlobal>
1121
1122     Defined on BSD/OS.
1123 */
1124
1125 /*!
1126     \macro Q_OS_IRIX
1127     \relates <QtGlobal>
1128
1129     Defined on SGI Irix.
1130 */
1131
1132 /*!
1133     \macro Q_OS_OSF
1134     \relates <QtGlobal>
1135
1136     Defined on HP Tru64 UNIX.
1137 */
1138
1139 /*!
1140     \macro Q_OS_SCO
1141     \relates <QtGlobal>
1142
1143     Defined on SCO OpenServer 5.
1144 */
1145
1146 /*!
1147     \macro Q_OS_UNIXWARE
1148     \relates <QtGlobal>
1149
1150     Defined on UnixWare 7, Open UNIX 8.
1151 */
1152
1153 /*!
1154     \macro Q_OS_AIX
1155     \relates <QtGlobal>
1156
1157     Defined on AIX.
1158 */
1159
1160 /*!
1161     \macro Q_OS_HURD
1162     \relates <QtGlobal>
1163
1164     Defined on GNU Hurd.
1165 */
1166
1167 /*!
1168     \macro Q_OS_DGUX
1169     \relates <QtGlobal>
1170
1171     Defined on DG/UX.
1172 */
1173
1174 /*!
1175     \macro Q_OS_RELIANT
1176     \relates <QtGlobal>
1177
1178     Defined on Reliant UNIX.
1179 */
1180
1181 /*!
1182     \macro Q_OS_DYNIX
1183     \relates <QtGlobal>
1184
1185     Defined on DYNIX/ptx.
1186 */
1187
1188 /*!
1189     \macro Q_OS_QNX
1190     \relates <QtGlobal>
1191
1192     Defined on QNX Neutrino.
1193 */
1194
1195 /*!
1196     \macro Q_OS_LYNX
1197     \relates <QtGlobal>
1198
1199     Defined on LynxOS.
1200 */
1201
1202 /*!
1203     \macro Q_OS_BSD4
1204     \relates <QtGlobal>
1205
1206     Defined on Any BSD 4.4 system.
1207 */
1208
1209 /*!
1210     \macro Q_OS_UNIX
1211     \relates <QtGlobal>
1212
1213     Defined on Any UNIX BSD/SYSV system.
1214 */
1215
1216 /*!
1217     \macro Q_CC_SYM
1218     \relates <QtGlobal>
1219
1220     Defined if the application is compiled using Digital Mars C/C++
1221     (used to be Symantec C++).
1222 */
1223
1224 /*!
1225     \macro Q_CC_MSVC
1226     \relates <QtGlobal>
1227
1228     Defined if the application is compiled using Microsoft Visual
1229     C/C++, Intel C++ for Windows.
1230 */
1231
1232 /*!
1233     \macro Q_CC_BOR
1234     \relates <QtGlobal>
1235
1236     Defined if the application is compiled using Borland/Turbo C++.
1237 */
1238
1239 /*!
1240     \macro Q_CC_WAT
1241     \relates <QtGlobal>
1242
1243     Defined if the application is compiled using Watcom C++.
1244 */
1245
1246 /*!
1247     \macro Q_CC_GNU
1248     \relates <QtGlobal>
1249
1250     Defined if the application is compiled using GNU C++.
1251 */
1252
1253 /*!
1254     \macro Q_CC_COMEAU
1255     \relates <QtGlobal>
1256
1257     Defined if the application is compiled using Comeau C++.
1258 */
1259
1260 /*!
1261     \macro Q_CC_EDG
1262     \relates <QtGlobal>
1263
1264     Defined if the application is compiled using Edison Design Group
1265     C++.
1266 */
1267
1268 /*!
1269     \macro Q_CC_OC
1270     \relates <QtGlobal>
1271
1272     Defined if the application is compiled using CenterLine C++.
1273 */
1274
1275 /*!
1276     \macro Q_CC_SUN
1277     \relates <QtGlobal>
1278
1279     Defined if the application is compiled using Forte Developer, or
1280     Sun Studio C++.
1281 */
1282
1283 /*!
1284     \macro Q_CC_MIPS
1285     \relates <QtGlobal>
1286
1287     Defined if the application is compiled using MIPSpro C++.
1288 */
1289
1290 /*!
1291     \macro Q_CC_DEC
1292     \relates <QtGlobal>
1293
1294     Defined if the application is compiled using DEC C++.
1295 */
1296
1297 /*!
1298     \macro Q_CC_HPACC
1299     \relates <QtGlobal>
1300
1301     Defined if the application is compiled using HP aC++.
1302 */
1303
1304 /*!
1305     \macro Q_CC_USLC
1306     \relates <QtGlobal>
1307
1308     Defined if the application is compiled using SCO OUDK and UDK.
1309 */
1310
1311 /*!
1312     \macro Q_CC_CDS
1313     \relates <QtGlobal>
1314
1315     Defined if the application is compiled using Reliant C++.
1316 */
1317
1318 /*!
1319     \macro Q_CC_KAI
1320     \relates <QtGlobal>
1321
1322     Defined if the application is compiled using KAI C++.
1323 */
1324
1325 /*!
1326     \macro Q_CC_INTEL
1327     \relates <QtGlobal>
1328
1329     Defined if the application is compiled using Intel C++ for Linux,
1330     Intel C++ for Windows.
1331 */
1332
1333 /*!
1334     \macro Q_CC_HIGHC
1335     \relates <QtGlobal>
1336
1337     Defined if the application is compiled using MetaWare High C/C++.
1338 */
1339
1340 /*!
1341     \macro Q_CC_PGI
1342     \relates <QtGlobal>
1343
1344     Defined if the application is compiled using Portland Group C++.
1345 */
1346
1347 /*!
1348     \macro Q_CC_GHS
1349     \relates <QtGlobal>
1350
1351     Defined if the application is compiled using Green Hills
1352     Optimizing C++ Compilers.
1353 */
1354
1355 /*!
1356   \macro Q_OS_MAC
1357   \relates <QtGlobal>
1358
1359   Defined on MAC OS (synonym for Darwin).
1360  */
1361
1362 /*!
1363   \macro QT_DISABLE_DEPRECATED_BEFORE
1364   \relates <QtGlobal>
1365
1366   This macro can be defined in the project file to disable functions deprecated in
1367   a specified version of Qt or any earlier version. The default version number is 5.0,
1368   meaning that functions deprecated in or before Qt 5.0 will not be included.
1369
1370   Examples:
1371   When using a future release of Qt 5, set QT_DISABLE_DEPRECATED_BEFORE=0x050100 to
1372   disable functions deprecated in Qt 5.1 and earlier. In any release, set
1373   QT_DISABLE_DEPRECATED_BEFORE=0x000000 to enable any functions, including the ones
1374   deprecated in Qt 5.0
1375  */
1376
1377 #if defined(QT_BUILD_QMAKE)
1378 // needed to bootstrap qmake
1379 static const unsigned int qt_one = 1;
1380 const int QSysInfo::ByteOrder = ((*((unsigned char *) &qt_one) == 0) ? BigEndian : LittleEndian);
1381 #endif
1382
1383 #if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
1384
1385 QT_BEGIN_INCLUDE_NAMESPACE
1386 #include "private/qcore_mac_p.h"
1387 #include "qnamespace.h"
1388 QT_END_INCLUDE_NAMESPACE
1389
1390 Q_CORE_EXPORT OSErr qt_mac_create_fsref(const QString &file, FSRef *fsref)
1391 {
1392     return FSPathMakeRef(reinterpret_cast<const UInt8 *>(file.toUtf8().constData()), fsref, 0);
1393 }
1394
1395 Q_CORE_EXPORT void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding=0, int len=-1)
1396 {
1397     Q_UNUSED(encoding);
1398     Q_UNUSED(len);
1399     CFStringGetPascalString(QCFString(s), str, 256, CFStringGetSystemEncoding());
1400 }
1401
1402 Q_CORE_EXPORT QString qt_mac_from_pascal_string(const Str255 pstr) {
1403     return QCFString(CFStringCreateWithPascalString(0, pstr, CFStringGetSystemEncoding()));
1404 }
1405 #endif // defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
1406
1407 #if defined(Q_OS_MAC)
1408
1409 static QSysInfo::MacVersion macVersion()
1410 {
1411 #ifndef QT_NO_CORESERVICES
1412     SInt32 gestalt_version;
1413     if (Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) {
1414         return QSysInfo::MacVersion(((gestalt_version & 0x00F0) >> 4) + 2);
1415     }
1416 #endif
1417     return QSysInfo::MV_Unknown;
1418 }
1419 const QSysInfo::MacVersion QSysInfo::MacintoshVersion = macVersion();
1420
1421 #elif defined(Q_OS_WIN) || defined(Q_OS_CYGWIN) || defined(Q_OS_WINCE)
1422
1423 QT_BEGIN_INCLUDE_NAMESPACE
1424 #include "qt_windows.h"
1425 QT_END_INCLUDE_NAMESPACE
1426
1427 QSysInfo::WinVersion QSysInfo::windowsVersion()
1428 {
1429 #ifndef VER_PLATFORM_WIN32s
1430 #define VER_PLATFORM_WIN32s            0
1431 #endif
1432 #ifndef VER_PLATFORM_WIN32_WINDOWS
1433 #define VER_PLATFORM_WIN32_WINDOWS  1
1434 #endif
1435 #ifndef VER_PLATFORM_WIN32_NT
1436 #define VER_PLATFORM_WIN32_NT            2
1437 #endif
1438 #ifndef VER_PLATFORM_WIN32_CE
1439 #define VER_PLATFORM_WIN32_CE            3
1440 #endif
1441
1442     static QSysInfo::WinVersion winver;
1443     if (winver)
1444         return winver;
1445     winver = QSysInfo::WV_NT;
1446     OSVERSIONINFO osver;
1447     osver.dwOSVersionInfoSize = sizeof(osver);
1448     GetVersionEx(&osver);
1449 #ifdef Q_OS_WINCE
1450     DWORD qt_cever = 0;
1451     qt_cever = osver.dwMajorVersion * 100;
1452     qt_cever += osver.dwMinorVersion * 10;
1453 #endif
1454     switch (osver.dwPlatformId) {
1455     case VER_PLATFORM_WIN32s:
1456         winver = QSysInfo::WV_32s;
1457         break;
1458     case VER_PLATFORM_WIN32_WINDOWS:
1459         // We treat Windows Me (minor 90) the same as Windows 98
1460         if (osver.dwMinorVersion == 90)
1461             winver = QSysInfo::WV_Me;
1462         else if (osver.dwMinorVersion == 10)
1463             winver = QSysInfo::WV_98;
1464         else
1465             winver = QSysInfo::WV_95;
1466         break;
1467 #ifdef Q_OS_WINCE
1468     case VER_PLATFORM_WIN32_CE:
1469         if (qt_cever >= 600)
1470             winver = QSysInfo::WV_CE_6;
1471         if (qt_cever >= 500)
1472             winver = QSysInfo::WV_CE_5;
1473         else if (qt_cever >= 400)
1474             winver = QSysInfo::WV_CENET;
1475         else
1476             winver = QSysInfo::WV_CE;
1477         break;
1478 #endif
1479     default: // VER_PLATFORM_WIN32_NT
1480         if (osver.dwMajorVersion < 5) {
1481             winver = QSysInfo::WV_NT;
1482         } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0) {
1483             winver = QSysInfo::WV_2000;
1484         } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 1) {
1485             winver = QSysInfo::WV_XP;
1486         } else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 2) {
1487             winver = QSysInfo::WV_2003;
1488         } else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 0) {
1489             winver = QSysInfo::WV_VISTA;
1490         } else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 1) {
1491             winver = QSysInfo::WV_WINDOWS7;
1492         } else {
1493             qWarning("Qt: Untested Windows version %d.%d detected!",
1494                      int(osver.dwMajorVersion), int(osver.dwMinorVersion));
1495             winver = QSysInfo::WV_NT_based;
1496         }
1497     }
1498
1499 #ifdef QT_DEBUG
1500     {
1501         QByteArray override = qgetenv("QT_WINVER_OVERRIDE");
1502         if (override.isEmpty())
1503             return winver;
1504
1505         if (override == "Me")
1506             winver = QSysInfo::WV_Me;
1507         if (override == "95")
1508             winver = QSysInfo::WV_95;
1509         else if (override == "98")
1510             winver = QSysInfo::WV_98;
1511         else if (override == "NT")
1512             winver = QSysInfo::WV_NT;
1513         else if (override == "2000")
1514             winver = QSysInfo::WV_2000;
1515         else if (override == "2003")
1516             winver = QSysInfo::WV_2003;
1517         else if (override == "XP")
1518             winver = QSysInfo::WV_XP;
1519         else if (override == "VISTA")
1520             winver = QSysInfo::WV_VISTA;
1521         else if (override == "WINDOWS7")
1522             winver = QSysInfo::WV_WINDOWS7;
1523     }
1524 #endif
1525
1526     return winver;
1527 }
1528
1529 const QSysInfo::WinVersion QSysInfo::WindowsVersion = QSysInfo::windowsVersion();
1530
1531 #endif
1532
1533 /*!
1534     \macro void Q_ASSERT(bool test)
1535     \relates <QtGlobal>
1536
1537     Prints a warning message containing the source code file name and
1538     line number if \a test is false.
1539
1540     Q_ASSERT() is useful for testing pre- and post-conditions
1541     during development. It does nothing if \c QT_NO_DEBUG was defined
1542     during compilation.
1543
1544     Example:
1545
1546     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 17
1547
1548     If \c b is zero, the Q_ASSERT statement will output the following
1549     message using the qFatal() function:
1550
1551     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 18
1552
1553     \sa Q_ASSERT_X(), qFatal(), {Debugging Techniques}
1554 */
1555
1556 /*!
1557     \macro void Q_ASSERT_X(bool test, const char *where, const char *what)
1558     \relates <QtGlobal>
1559
1560     Prints the message \a what together with the location \a where,
1561     the source file name and line number if \a test is false.
1562
1563     Q_ASSERT_X is useful for testing pre- and post-conditions during
1564     development. It does nothing if \c QT_NO_DEBUG was defined during
1565     compilation.
1566
1567     Example:
1568
1569     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 19
1570
1571     If \c b is zero, the Q_ASSERT_X statement will output the following
1572     message using the qFatal() function:
1573
1574     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 20
1575
1576     \sa Q_ASSERT(), qFatal(), {Debugging Techniques}
1577 */
1578
1579 /*!
1580     \macro void Q_CHECK_PTR(void *pointer)
1581     \relates <QtGlobal>
1582
1583     If \a pointer is 0, prints a warning message containing the source
1584     code's file name and line number, saying that the program ran out
1585     of memory.
1586
1587     Q_CHECK_PTR does nothing if \c QT_NO_DEBUG was defined during
1588     compilation.
1589
1590     Example:
1591
1592     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 21
1593
1594     \sa qWarning(), {Debugging Techniques}
1595 */
1596
1597 /*!
1598     \fn T *q_check_ptr(T *pointer)
1599     \relates <QtGlobal>
1600
1601     Users Q_CHECK_PTR on \a pointer, then returns \a pointer.
1602
1603     This can be used as an inline version of Q_CHECK_PTR.
1604 */
1605
1606 /*!
1607     \macro const char* Q_FUNC_INFO()
1608     \relates <QtGlobal>
1609
1610     Expands to a string that describe the function the macro resides in. How this string looks
1611     more specifically is compiler dependent. With GNU GCC it is typically the function signature,
1612     while with other compilers it might be the line and column number.
1613
1614     Q_FUNC_INFO can be conveniently used with qDebug(). For example, this function:
1615
1616     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 22
1617
1618     when instantiated with the integer type, will with the GCC compiler produce:
1619
1620     \tt{const TInputType& myMin(const TInputType&, const TInputType&) [with TInputType = int] was called with value1: 3 value2: 4}
1621
1622     If this macro is used outside a function, the behavior is undefined.
1623  */
1624
1625 /*
1626   The Q_CHECK_PTR macro calls this function if an allocation check
1627   fails.
1628 */
1629 void qt_check_pointer(const char *n, int l)
1630 {
1631     qFatal("In file %s, line %d: Out of memory", n, l);
1632 }
1633
1634 /* \internal
1635    Allows you to throw an exception without including <new>
1636    Called internally from Q_CHECK_PTR on certain OS combinations
1637 */
1638 void qBadAlloc()
1639 {
1640     QT_THROW(std::bad_alloc());
1641 }
1642
1643 /*
1644   The Q_ASSERT macro calls this function when the test fails.
1645 */
1646 void qt_assert(const char *assertion, const char *file, int line)
1647 {
1648     qFatal("ASSERT: \"%s\" in file %s, line %d", assertion, file, line);
1649 }
1650
1651 /*
1652   The Q_ASSERT_X macro calls this function when the test fails.
1653 */
1654 void qt_assert_x(const char *where, const char *what, const char *file, int line)
1655 {
1656     qFatal("ASSERT failure in %s: \"%s\", file %s, line %d", where, what, file, line);
1657 }
1658
1659
1660 /*
1661     Dijkstra's bisection algorithm to find the square root of an integer.
1662     Deliberately not exported as part of the Qt API, but used in both
1663     qsimplerichtext.cpp and qgfxraster_qws.cpp
1664 */
1665 Q_CORE_EXPORT unsigned int qt_int_sqrt(unsigned int n)
1666 {
1667     // n must be in the range 0...UINT_MAX/2-1
1668     if (n >= (UINT_MAX>>2)) {
1669         unsigned int r = 2 * qt_int_sqrt(n / 4);
1670         unsigned int r2 = r + 1;
1671         return (n >= r2 * r2) ? r2 : r;
1672     }
1673     uint h, p= 0, q= 1, r= n;
1674     while (q <= n)
1675         q <<= 2;
1676     while (q != 1) {
1677         q >>= 2;
1678         h= p + q;
1679         p >>= 1;
1680         if (r >= h) {
1681             p += q;
1682             r -= h;
1683         }
1684     }
1685     return p;
1686 }
1687
1688 #if defined(qMemCopy)
1689 #  undef qMemCopy
1690 #endif
1691 #if defined(qMemSet)
1692 #  undef qMemSet
1693 #endif
1694
1695 void *qMemCopy(void *dest, const void *src, size_t n) { return memcpy(dest, src, n); }
1696 void *qMemSet(void *dest, int c, size_t n) { return memset(dest, c, n); }
1697
1698 #if !defined(Q_OS_WIN) && !defined(QT_NO_THREAD) && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX) && \
1699     defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L
1700 namespace {
1701     // There are two incompatible versions of strerror_r:
1702     // a) the XSI/POSIX.1 version, which returns an int,
1703     //    indicating success or not
1704     // b) the GNU version, which returns a char*, which may or may not
1705     //    be the beginning of the buffer we used
1706     // The GNU libc manpage for strerror_r says you should use the the XSI
1707     // version in portable code. However, it's impossible to do that if
1708     // _GNU_SOURCE is defined so we use C++ overloading to decide what to do
1709     // depending on the return type
1710     static inline QString fromstrerror_helper(int, const QByteArray &buf)
1711     {
1712         return QString::fromLocal8Bit(buf);
1713     }
1714     static inline QString fromstrerror_helper(const char *str, const QByteArray &)
1715     {
1716         return QString::fromLocal8Bit(str);
1717     }
1718 }
1719 #endif
1720
1721 QString qt_error_string(int errorCode)
1722 {
1723     const char *s = 0;
1724     QString ret;
1725     if (errorCode == -1) {
1726 #if defined(Q_OS_WIN)
1727         errorCode = GetLastError();
1728 #else
1729         errorCode = errno;
1730 #endif
1731     }
1732     switch (errorCode) {
1733     case 0:
1734         break;
1735     case EACCES:
1736         s = QT_TRANSLATE_NOOP("QIODevice", "Permission denied");
1737         break;
1738     case EMFILE:
1739         s = QT_TRANSLATE_NOOP("QIODevice", "Too many open files");
1740         break;
1741     case ENOENT:
1742         s = QT_TRANSLATE_NOOP("QIODevice", "No such file or directory");
1743         break;
1744     case ENOSPC:
1745         s = QT_TRANSLATE_NOOP("QIODevice", "No space left on device");
1746         break;
1747     default: {
1748 #ifdef Q_OS_WIN
1749         wchar_t *string = 0;
1750         FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
1751                       NULL,
1752                       errorCode,
1753                       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1754                       (LPWSTR)&string,
1755                       0,
1756                       NULL);
1757         ret = QString::fromWCharArray(string);
1758         LocalFree((HLOCAL)string);
1759
1760         if (ret.isEmpty() && errorCode == ERROR_MOD_NOT_FOUND)
1761             ret = QString::fromLatin1("The specified module could not be found.");
1762 #elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && _POSIX_VERSION >= 200112L && !defined(Q_OS_INTEGRITY) && !defined(Q_OS_QNX)
1763         QByteArray buf(1024, '\0');
1764         ret = fromstrerror_helper(strerror_r(errorCode, buf.data(), buf.size()), buf);
1765 #else
1766         ret = QString::fromLocal8Bit(strerror(errorCode));
1767 #endif
1768     break; }
1769     }
1770     if (s)
1771         // ######## this breaks moc build currently
1772 //         ret = QCoreApplication::translate("QIODevice", s);
1773         ret = QString::fromLatin1(s);
1774     return ret.trimmed();
1775 }
1776
1777 // getenv is declared as deprecated in VS2005. This function
1778 // makes use of the new secure getenv function.
1779 /*!
1780     \relates <QtGlobal>
1781
1782     Returns the value of the environment variable with name \a
1783     varName. To get the variable string, use QByteArray::constData().
1784
1785     \note qgetenv() was introduced because getenv() from the standard
1786     C library was deprecated in VC2005 (and later versions). qgetenv()
1787     uses the new replacement function in VC, and calls the standard C
1788     library's implementation on all other platforms.
1789
1790     \sa qputenv()
1791 */
1792 QByteArray qgetenv(const char *varName)
1793 {
1794 #if defined(_MSC_VER) && _MSC_VER >= 1400
1795     size_t requiredSize = 0;
1796     QByteArray buffer;
1797     getenv_s(&requiredSize, 0, 0, varName);
1798     if (requiredSize == 0)
1799         return buffer;
1800     buffer.resize(int(requiredSize));
1801     getenv_s(&requiredSize, buffer.data(), requiredSize, varName);
1802     // requiredSize includes the terminating null, which we don't want.
1803     Q_ASSERT(buffer.endsWith('\0'));
1804     buffer.chop(1);
1805     return buffer;
1806 #else
1807     return QByteArray(::getenv(varName));
1808 #endif
1809 }
1810
1811 /*!
1812     \relates <QtGlobal>
1813
1814     This function sets the \a value of the environment variable named
1815     \a varName. It will create the variable if it does not exist. It
1816     returns 0 if the variable could not be set.
1817
1818     \note qputenv() was introduced because putenv() from the standard
1819     C library was deprecated in VC2005 (and later versions). qputenv()
1820     uses the replacement function in VC, and calls the standard C
1821     library's implementation on all other platforms.
1822
1823     \sa qgetenv()
1824 */
1825 bool qputenv(const char *varName, const QByteArray& value)
1826 {
1827 #if defined(_MSC_VER) && _MSC_VER >= 1400
1828     return _putenv_s(varName, value.constData()) == 0;
1829 #else
1830     QByteArray buffer(varName);
1831     buffer += '=';
1832     buffer += value;
1833     char* envVar = qstrdup(buffer.constData());
1834     int result = putenv(envVar);
1835     if (result != 0) // error. we have to delete the string.
1836         delete[] envVar;
1837     return result == 0;
1838 #endif
1839 }
1840
1841 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD)
1842
1843 #  if defined(Q_OS_INTEGRITY) && defined(__GHS_VERSION_NUMBER) && (__GHS_VERSION_NUMBER < 500)
1844 // older versions of INTEGRITY used a long instead of a uint for the seed.
1845 typedef long SeedStorageType;
1846 #  else
1847 typedef uint SeedStorageType;
1848 #  endif
1849
1850 typedef QThreadStorage<SeedStorageType *> SeedStorage;
1851 Q_GLOBAL_STATIC(SeedStorage, randTLS)  // Thread Local Storage for seed value
1852
1853 #endif
1854
1855 /*!
1856     \relates <QtGlobal>
1857     \since 4.2
1858
1859     Thread-safe version of the standard C++ \c srand() function.
1860
1861     Sets the argument \a seed to be used to generate a new random number sequence of
1862     pseudo random integers to be returned by qrand().
1863
1864     The sequence of random numbers generated is deterministic per thread. For example,
1865     if two threads call qsrand(1) and subsequently calls qrand(), the threads will get
1866     the same random number sequence.
1867
1868     \sa qrand()
1869 */
1870 void qsrand(uint seed)
1871 {
1872 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD)
1873     SeedStorage *seedStorage = randTLS();
1874     if (seedStorage) {
1875         SeedStorageType *pseed = seedStorage->localData();
1876         if (!pseed)
1877             seedStorage->setLocalData(pseed = new SeedStorageType);
1878         *pseed = seed;
1879     } else {
1880         //global static seed storage should always exist,
1881         //except after being deleted by QGlobalStaticDeleter.
1882         //But since it still can be called from destructor of another
1883         //global static object, fallback to srand(seed)
1884         srand(seed);
1885     }
1886 #else
1887     // On Windows srand() and rand() already use Thread-Local-Storage
1888     // to store the seed between calls
1889     // this is also valid for QT_NO_THREAD
1890     srand(seed);
1891 #endif
1892 }
1893
1894 /*!
1895     \relates <QtGlobal>
1896     \since 4.2
1897
1898     Thread-safe version of the standard C++ \c rand() function.
1899
1900     Returns a value between 0 and \c RAND_MAX (defined in \c <cstdlib> and
1901     \c <stdlib.h>), the next number in the current sequence of pseudo-random
1902     integers.
1903
1904     Use \c qsrand() to initialize the pseudo-random number generator with
1905     a seed value.
1906
1907     \sa qsrand()
1908 */
1909 int qrand()
1910 {
1911 #if defined(Q_OS_UNIX) && !defined(QT_NO_THREAD)
1912     SeedStorage *seedStorage = randTLS();
1913     if (seedStorage) {
1914         SeedStorageType *pseed = seedStorage->localData();
1915         if (!pseed) {
1916             seedStorage->setLocalData(pseed = new SeedStorageType);
1917             *pseed = 1;
1918         }
1919         return rand_r(pseed);
1920     } else {
1921         //global static seed storage should always exist,
1922         //except after being deleted by QGlobalStaticDeleter.
1923         //But since it still can be called from destructor of another
1924         //global static object, fallback to rand()
1925         return rand();
1926     }
1927 #else
1928     // On Windows srand() and rand() already use Thread-Local-Storage
1929     // to store the seed between calls
1930     // this is also valid for QT_NO_THREAD
1931     return rand();
1932 #endif
1933 }
1934
1935 /*!
1936     \macro forever
1937     \relates <QtGlobal>
1938
1939     This macro is provided for convenience for writing infinite
1940     loops.
1941
1942     Example:
1943
1944     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 31
1945
1946     It is equivalent to \c{for (;;)}.
1947
1948     If you're worried about namespace pollution, you can disable this
1949     macro by adding the following line to your \c .pro file:
1950
1951     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 32
1952
1953     \sa Q_FOREVER
1954 */
1955
1956 /*!
1957     \macro Q_FOREVER
1958     \relates <QtGlobal>
1959
1960     Same as \l{forever}.
1961
1962     This macro is available even when \c no_keywords is specified
1963     using the \c .pro file's \c CONFIG variable.
1964
1965     \sa foreach()
1966 */
1967
1968 /*!
1969     \macro foreach(variable, container)
1970     \relates <QtGlobal>
1971
1972     This macro is used to implement Qt's \c foreach loop. The \a
1973     variable parameter is a variable name or variable definition; the
1974     \a container parameter is a Qt container whose value type
1975     corresponds to the type of the variable. See \l{The foreach
1976     Keyword} for details.
1977
1978     If you're worried about namespace pollution, you can disable this
1979     macro by adding the following line to your \c .pro file:
1980
1981     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 33
1982
1983     \sa Q_FOREACH()
1984 */
1985
1986 /*!
1987     \macro Q_FOREACH(variable, container)
1988     \relates <QtGlobal>
1989
1990     Same as foreach(\a variable, \a container).
1991
1992     This macro is available even when \c no_keywords is specified
1993     using the \c .pro file's \c CONFIG variable.
1994
1995     \sa foreach()
1996 */
1997
1998 /*!
1999     \macro QT_TR_NOOP(sourceText)
2000     \relates <QtGlobal>
2001
2002     Marks the string literal \a sourceText for dynamic translation in
2003     the current context (class), i.e the stored \a sourceText will not
2004     be altered.
2005
2006     The macro expands to \a sourceText.
2007
2008     Example:
2009
2010     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 34
2011
2012     The macro QT_TR_NOOP_UTF8() is identical except that it tells lupdate
2013     that the source string is encoded in UTF-8. Corresponding variants
2014     exist in the QT_TRANSLATE_NOOP() family of macros, too. Note that
2015     using these macros is not required if \c CODECFORTR is already set to
2016     UTF-8 in the qmake project file.
2017
2018     \sa QT_TRANSLATE_NOOP(), {Internationalization with Qt}
2019 */
2020
2021 /*!
2022     \macro QT_TRANSLATE_NOOP(context, sourceText)
2023     \relates <QtGlobal>
2024
2025     Marks the string literal \a sourceText for dynamic translation in
2026     the given \a context; i.e, the stored \a sourceText will not be
2027     altered. The \a context is typically a class and also needs to
2028     be specified as string literal.
2029
2030     The macro expands to \a sourceText.
2031
2032     Example:
2033
2034     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 35
2035
2036     \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP3(), {Internationalization with Qt}
2037 */
2038
2039 /*!
2040     \macro QT_TRANSLATE_NOOP3(context, sourceText, comment)
2041     \relates <QtGlobal>
2042     \since 4.4
2043
2044     Marks the string literal \a sourceText for dynamic translation in the
2045     given \a context and with \a comment, i.e the stored \a sourceText will
2046     not be altered. The \a context is typically a class and also needs to
2047     be specified as string literal. The string literal \a comment
2048     will be available for translators using e.g. Qt Linguist.
2049
2050     The macro expands to anonymous struct of the two string
2051     literals passed as \a sourceText and \a comment.
2052
2053     Example:
2054
2055     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 36
2056
2057     \sa QT_TR_NOOP(), QT_TRANSLATE_NOOP(), {Internationalization with Qt}
2058 */
2059
2060 /*!
2061     \fn QString qtTrId(const char *id, int n = -1)
2062     \relates <QtGlobal>
2063     \reentrant
2064     \since 4.6
2065
2066     \brief The qtTrId function finds and returns a translated string.
2067
2068     Returns a translated string identified by \a id.
2069     If no matching string is found, the id itself is returned. This
2070     should not happen under normal conditions.
2071
2072     If \a n >= 0, all occurrences of \c %n in the resulting string
2073     are replaced with a decimal representation of \a n. In addition,
2074     depending on \a n's value, the translation text may vary.
2075
2076     Meta data and comments can be passed as documented for QObject::tr().
2077     In addition, it is possible to supply a source string template like that:
2078
2079     \tt{//% <C string>}
2080
2081     or
2082
2083     \tt{\begincomment% <C string> \endcomment}
2084
2085     Example:
2086
2087     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qttrid
2088
2089     Creating QM files suitable for use with this function requires passing
2090     the \c -idbased option to the \c lrelease tool.
2091
2092     \warning This method is reentrant only if all translators are
2093     installed \e before calling this method. Installing or removing
2094     translators while performing translations is not supported. Doing
2095     so will probably result in crashes or other undesirable behavior.
2096
2097     \sa QObject::tr(), QCoreApplication::translate(), {Internationalization with Qt}
2098 */
2099
2100 /*!
2101     \macro QT_TRID_NOOP(id)
2102     \relates <QtGlobal>
2103     \since 4.6
2104
2105     \brief The QT_TRID_NOOP macro marks an id for dynamic translation.
2106
2107     The only purpose of this macro is to provide an anchor for attaching
2108     meta data like to qtTrId().
2109
2110     The macro expands to \a id.
2111
2112     Example:
2113
2114     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qttrid_noop
2115
2116     \sa qtTrId(), {Internationalization with Qt}
2117 */
2118
2119 /*!
2120     \macro Q_LIKELY(expr)
2121     \relates <QtGlobal>
2122     \since 4.8
2123
2124     \brief Hints to the compiler that the enclosed condition, \a expr, is
2125     likely to evaluate to \c true.
2126
2127     Use of this macro can help the compiler to optimize the code.
2128
2129     Example:
2130
2131     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qlikely
2132
2133     \sa Q_UNLIKELY()
2134 */
2135
2136 /*!
2137     \macro Q_UNLIKELY(expr)
2138     \relates <QtGlobal>
2139     \since 4.8
2140
2141     \brief Hints to the compiler that the enclosed condition, \a expr, is
2142     likely to evaluate to \c false.
2143
2144     Use of this macro can help the compiler to optimize the code.
2145
2146     Example:
2147
2148     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp qunlikely
2149
2150     \sa Q_LIKELY()
2151 */
2152
2153 /*!
2154     \macro QT_POINTER_SIZE
2155     \relates <QtGlobal>
2156
2157     Expands to the size of a pointer in bytes (4 or 8). This is
2158     equivalent to \c sizeof(void *) but can be used in a preprocessor
2159     directive.
2160 */
2161
2162 /*!
2163     \macro TRUE
2164     \relates <QtGlobal>
2165     \obsolete
2166
2167     Synonym for \c true.
2168
2169     \sa FALSE
2170 */
2171
2172 /*!
2173     \macro FALSE
2174     \relates <QtGlobal>
2175     \obsolete
2176
2177     Synonym for \c false.
2178
2179     \sa TRUE
2180 */
2181
2182 /*!
2183     \macro QABS(n)
2184     \relates <QtGlobal>
2185     \obsolete
2186
2187     Use qAbs(\a n) instead.
2188
2189     \sa QMIN(), QMAX()
2190 */
2191
2192 /*!
2193     \macro QMIN(x, y)
2194     \relates <QtGlobal>
2195     \obsolete
2196
2197     Use qMin(\a x, \a y) instead.
2198
2199     \sa QMAX(), QABS()
2200 */
2201
2202 /*!
2203     \macro QMAX(x, y)
2204     \relates <QtGlobal>
2205     \obsolete
2206
2207     Use qMax(\a x, \a y) instead.
2208
2209     \sa QMIN(), QABS()
2210 */
2211
2212 /*!
2213     \macro const char *qPrintable(const QString &str)
2214     \relates <QtGlobal>
2215
2216     Returns \a str as a \c{const char *}. This is equivalent to
2217     \a{str}.toLocal8Bit().constData().
2218
2219     The char pointer will be invalid after the statement in which
2220     qPrintable() is used. This is because the array returned by
2221     toLocal8Bit() will fall out of scope.
2222
2223     Example:
2224
2225     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 37
2226
2227
2228     \sa qDebug(), qWarning(), qCritical(), qFatal()
2229 */
2230
2231 /*!
2232     \macro Q_DECLARE_TYPEINFO(Type, Flags)
2233     \relates <QtGlobal>
2234
2235     You can use this macro to specify information about a custom type
2236     \a Type. With accurate type information, Qt's \l{Container Classes}
2237     {generic containers} can choose appropriate storage methods and
2238     algorithms.
2239
2240     \a Flags can be one of the following:
2241
2242     \list
2243     \o \c Q_PRIMITIVE_TYPE specifies that \a Type is a POD (plain old
2244        data) type with no constructor or destructor.
2245     \o \c Q_MOVABLE_TYPE specifies that \a Type has a constructor
2246        and/or a destructor but can be moved in memory using \c
2247        memcpy().
2248     \o \c Q_COMPLEX_TYPE (the default) specifies that \a Type has
2249        constructors and/or a destructor and that it may not be moved
2250        in memory.
2251     \endlist
2252
2253     Example of a "primitive" type:
2254
2255     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 38
2256
2257     Example of a movable type:
2258
2259     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 39
2260 */
2261
2262 /*!
2263     \macro Q_UNUSED(name)
2264     \relates <QtGlobal>
2265
2266     Indicates to the compiler that the parameter with the specified
2267     \a name is not used in the body of a function. This can be used to
2268     suppress compiler warnings while allowing functions to be defined
2269     with meaningful parameter names in their signatures.
2270 */
2271
2272 struct QInternal_CallBackTable {
2273     QVector<QList<qInternalCallback> > callbacks;
2274 };
2275
2276 Q_GLOBAL_STATIC(QInternal_CallBackTable, global_callback_table)
2277
2278 bool QInternal::registerCallback(Callback cb, qInternalCallback callback)
2279 {
2280     if (cb >= 0 && cb < QInternal::LastCallback) {
2281         QInternal_CallBackTable *cbt = global_callback_table();
2282         cbt->callbacks.resize(cb + 1);
2283         cbt->callbacks[cb].append(callback);
2284         return true;
2285     }
2286     return false;
2287 }
2288
2289 bool QInternal::unregisterCallback(Callback cb, qInternalCallback callback)
2290 {
2291     if (cb >= 0 && cb < QInternal::LastCallback) {
2292         QInternal_CallBackTable *cbt = global_callback_table();
2293         return (bool) cbt->callbacks[cb].removeAll(callback);
2294     }
2295     return false;
2296 }
2297
2298 bool QInternal::activateCallbacks(Callback cb, void **parameters)
2299 {
2300     Q_ASSERT_X(cb >= 0, "QInternal::activateCallback()", "Callback id must be a valid id");
2301
2302     QInternal_CallBackTable *cbt = global_callback_table();
2303     if (cbt && cb < cbt->callbacks.size()) {
2304         QList<qInternalCallback> callbacks = cbt->callbacks[cb];
2305         bool ret = false;
2306         for (int i=0; i<callbacks.size(); ++i)
2307             ret |= (callbacks.at(i))(parameters);
2308         return ret;
2309     }
2310     return false;
2311 }
2312
2313 /*!
2314     \macro Q_BYTE_ORDER
2315     \relates <QtGlobal>
2316
2317     This macro can be used to determine the byte order your system
2318     uses for storing data in memory. i.e., whether your system is
2319     little-endian or big-endian. It is set by Qt to one of the macros
2320     Q_LITTLE_ENDIAN or Q_BIG_ENDIAN. You normally won't need to worry
2321     about endian-ness, but you might, for example if you need to know
2322     which byte of an integer or UTF-16 character is stored in the
2323     lowest address. Endian-ness is important in networking, where
2324     computers with different values for Q_BYTE_ORDER must pass data
2325     back and forth.
2326
2327     Use this macro as in the following examples.
2328
2329     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 40
2330
2331     \sa Q_BIG_ENDIAN, Q_LITTLE_ENDIAN
2332 */
2333
2334 /*!
2335     \macro Q_LITTLE_ENDIAN
2336     \relates <QtGlobal>
2337
2338     This macro represents a value you can compare to the macro
2339     Q_BYTE_ORDER to determine the endian-ness of your system.  In a
2340     little-endian system, the least significant byte is stored at the
2341     lowest address. The other bytes follow in increasing order of
2342     significance.
2343
2344     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 41
2345
2346     \sa Q_BYTE_ORDER, Q_BIG_ENDIAN
2347 */
2348
2349 /*!
2350     \macro Q_BIG_ENDIAN
2351     \relates <QtGlobal>
2352
2353     This macro represents a value you can compare to the macro
2354     Q_BYTE_ORDER to determine the endian-ness of your system.  In a
2355     big-endian system, the most significant byte is stored at the
2356     lowest address. The other bytes follow in decreasing order of
2357     significance.
2358
2359     \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 42
2360
2361     \sa Q_BYTE_ORDER, Q_LITTLE_ENDIAN
2362 */
2363
2364 /*!
2365     \macro Q_GLOBAL_STATIC(type, name)
2366     \internal
2367
2368     Declares a global static variable with the given \a type and \a name.
2369
2370     Use this macro to instantiate an object in a thread-safe way, creating
2371     a global pointer that can be used to refer to it.
2372
2373     \warning This macro is subject to a race condition that can cause the object
2374     to be constructed twice. However, if this occurs, the second instance will
2375     be immediately deleted.
2376
2377     See also
2378     \l{http://www.aristeia.com/publications.html}{"C++ and the perils of Double-Checked Locking"}
2379     by Scott Meyers and Andrei Alexandrescu.
2380 */
2381
2382 /*!
2383     \macro Q_GLOBAL_STATIC_WITH_ARGS(type, name, arguments)
2384     \internal
2385
2386     Declares a global static variable with the specified \a type and \a name.
2387
2388     Use this macro to instantiate an object using the \a arguments specified
2389     in a thread-safe way, creating a global pointer that can be used to refer
2390     to it.
2391
2392     \warning This macro is subject to a race condition that can cause the object
2393     to be constructed twice. However, if this occurs, the second instance will
2394     be immediately deleted.
2395
2396     See also
2397     \l{http://www.aristeia.com/publications.html}{"C++ and the perils of Double-Checked Locking"}
2398     by Scott Meyers and Andrei Alexandrescu.
2399 */
2400
2401 /*!
2402     \macro QT_NAMESPACE
2403     \internal
2404
2405     If this macro is defined to \c ns all Qt classes are put in a namespace
2406     called \c ns. Also, moc will output code putting metaobjects etc.
2407     into namespace \c ns.
2408
2409     \sa QT_BEGIN_NAMESPACE, QT_END_NAMESPACE,
2410     QT_PREPEND_NAMESPACE, QT_USE_NAMESPACE,
2411     QT_BEGIN_INCLUDE_NAMESPACE, QT_END_INCLUDE_NAMESPACE,
2412     QT_BEGIN_MOC_NAMESPACE, QT_END_MOC_NAMESPACE,
2413 */
2414
2415 /*!
2416     \macro QT_PREPEND_NAMESPACE(identifier)
2417     \internal
2418
2419     This macro qualifies \a identifier with the full namespace.
2420     It expands to \c{::QT_NAMESPACE::identifier} if \c QT_NAMESPACE is defined
2421     and only \a identifier otherwise.
2422
2423     \sa QT_NAMESPACE
2424 */
2425
2426 /*!
2427     \macro QT_USE_NAMESPACE
2428     \internal
2429
2430     This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined
2431     and nothing otherwise.
2432
2433     \sa QT_NAMESPACE
2434 */
2435
2436 /*!
2437     \macro QT_BEGIN_NAMESPACE
2438     \internal
2439
2440     This macro expands to
2441
2442     \snippet snippets/code/src_corelib_global_qglobal.cpp begin namespace macro
2443
2444     if \c QT_NAMESPACE is defined and nothing otherwise. If should always
2445     appear in the file-level scope and be followed by \c QT_END_NAMESPACE
2446     at the same logical level with respect to preprocessor conditionals
2447     in the same file.
2448
2449     As a rule of thumb, \c QT_BEGIN_NAMESPACE should appear in all Qt header
2450     and Qt source files after the last \c{#include} line and before the first
2451     declaration. In Qt headers using \c QT_BEGIN_HEADER, \c QT_BEGIN_NAMESPACE
2452     follows \c QT_BEGIN_HEADER immediately.
2453
2454     If that rule can't be followed because, e.g., \c{#include} lines and
2455     declarations are wildly mixed, place \c QT_BEGIN_NAMESPACE before
2456     the first declaration and wrap the \c{#include} lines in
2457     \c QT_BEGIN_INCLUDE_NAMESPACE and \c QT_END_INCLUDE_NAMESPACE.
2458
2459     When using the \c QT_NAMESPACE feature in user code
2460     (e.g., when building plugins statically linked to Qt) where
2461     the user code is not intended to go into the \c QT_NAMESPACE
2462     namespace, all forward declarations of Qt classes need to
2463     be wrapped in \c QT_BEGIN_NAMESPACE and \c QT_END_NAMESPACE.
2464     After that, a \c QT_USE_NAMESPACE should follow.
2465     No further changes should be needed.
2466
2467     \sa QT_NAMESPACE
2468 */
2469
2470 /*!
2471     \macro QT_END_NAMESPACE
2472     \internal
2473
2474     This macro expands to
2475
2476     \snippet snippets/code/src_corelib_global_qglobal.cpp end namespace macro
2477
2478     if \c QT_NAMESPACE is defined and nothing otherwise. It is used to cancel
2479     the effect of \c QT_BEGIN_NAMESPACE.
2480
2481     If a source file ends with a \c{#include} directive that includes a moc file,
2482     \c QT_END_NAMESPACE should be placed before that \c{#include}.
2483
2484     \sa QT_NAMESPACE
2485 */
2486
2487 /*!
2488     \macro QT_BEGIN_INCLUDE_NAMESPACE
2489     \internal
2490
2491     This macro is equivalent to \c QT_END_NAMESPACE.
2492     It only serves as syntactic sugar and is intended
2493     to be used before #include lines within a
2494     \c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
2495
2496     \sa QT_NAMESPACE
2497 */
2498
2499 /*!
2500     \macro QT_END_INCLUDE_NAMESPACE
2501     \internal
2502
2503     This macro is equivalent to \c QT_BEGIN_NAMESPACE.
2504     It only serves as syntactic sugar and is intended
2505     to be used after #include lines within a
2506     \c QT_BEGIN_NAMESPACE ... \c QT_END_NAMESPACE block.
2507
2508     \sa QT_NAMESPACE
2509 */
2510
2511 /*!
2512     \macro QT_BEGIN_MOC_NAMESPACE
2513     \internal
2514
2515     This macro is output by moc at the beginning of
2516     moc files. It is equivalent to \c QT_USE_NAMESPACE.
2517
2518     \sa QT_NAMESPACE
2519 */
2520
2521 /*!
2522     \macro QT_END_MOC_NAMESPACE
2523     \internal
2524
2525     This macro is output by moc at the beginning of
2526     moc files. It expands to nothing.
2527
2528     \sa QT_NAMESPACE
2529 */
2530
2531 /*!
2532  \fn bool qFuzzyCompare(double p1, double p2)
2533  \relates <QtGlobal>
2534  \since 4.4
2535  \threadsafe
2536
2537  Compares the floating point value \a p1 and \a p2 and
2538  returns \c true if they are considered equal, otherwise \c false.
2539
2540  Note that comparing values where either \a p1 or \a p2 is 0.0 will not work.
2541  The solution to this is to compare against values greater than or equal to 1.0.
2542
2543  \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 46
2544
2545  The two numbers are compared in a relative way, where the
2546  exactness is stronger the smaller the numbers are.
2547  */
2548
2549 /*!
2550  \fn bool qFuzzyCompare(float p1, float p2)
2551  \relates <QtGlobal>
2552  \since 4.4
2553  \threadsafe
2554
2555  Compares the floating point value \a p1 and \a p2 and
2556  returns \c true if they are considered equal, otherwise \c false.
2557
2558  The two numbers are compared in a relative way, where the
2559  exactness is stronger the smaller the numbers are.
2560  */
2561
2562 /*!
2563     \macro QT_REQUIRE_VERSION(int argc, char **argv, const char *version)
2564     \relates <QtGlobal>
2565
2566     This macro can be used to ensure that the application is run
2567     against a recent enough version of Qt. This is especially useful
2568     if your application depends on a specific bug fix introduced in a
2569     bug-fix release (e.g., 4.0.2).
2570
2571     The \a argc and \a argv parameters are the \c main() function's
2572     \c argc and \c argv parameters. The \a version parameter is a
2573     string literal that specifies which version of Qt the application
2574     requires (e.g., "4.0.2").
2575
2576     Example:
2577
2578     \snippet doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp 4
2579 */
2580
2581 /*!
2582     \macro Q_DECL_EXPORT
2583     \relates <QtGlobal>
2584
2585     This macro marks a symbol for shared library export (see
2586      \l{sharedlibrary.html}{Creating Shared Libraries}).
2587
2588     \sa Q_DECL_IMPORT
2589 */
2590
2591 /*!
2592     \macro Q_DECL_IMPORT
2593     \relates <QtGlobal>
2594
2595     This macro declares a symbol to be an import from a shared library (see
2596     \l{sharedlibrary.html}{Creating Shared Libraries}).
2597
2598     \sa Q_DECL_EXPORT
2599 */
2600
2601 /*!
2602     \macro Q_DECL_CONSTEXPR
2603     \relates <QtGlobal>
2604
2605     This macro can be used to declare variable that should be constructed at compile-time,
2606     or an inline function that can be computed at compile-time.
2607
2608     It expands to "constexpr" if your compiler supports that C++11 keyword, or to nothing
2609     otherwise.
2610 */
2611
2612 QT_END_NAMESPACE