ThreadWeaver
DebuggingAids.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef DEBUGGINGAIDS_H
00032 #define DEBUGGINGAIDS_H
00033
00034 #include <QtCore/qglobal.h>
00035
00036 extern "C"
00037 {
00038 #include <stdarg.h>
00039 #ifndef Q_WS_WIN
00040 #include <unistd.h>
00041 #endif
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <assert.h>
00045 }
00046
00047 #include <QtCore/QMutex>
00048 #include <QtCore/QString>
00049 #include "threadweaver/threadweaver_export.h"
00050
00051 namespace ThreadWeaver {
00052
00053 extern THREADWEAVER_EXPORT bool Debug;
00054 extern THREADWEAVER_EXPORT int DebugLevel;
00055 extern THREADWEAVER_EXPORT QMutex GlobalMutex;
00056
00060 extern inline void setDebugLevel (bool debug, int level);
00061
00077 inline void debug(int severity, const char * cformat, ...)
00078 #ifdef __GNUC__
00079 __attribute__ ( (format (printf, 2, 3 ) ) )
00080 #endif
00081 ;
00082
00084 inline void debug(bool condition, int severity, const char * cformat, ...)
00085 #ifdef __GNUC__
00086 __attribute__ ( (format (printf, 3, 4 ) ) )
00087 #endif
00088 ;
00089
00090
00093 #ifdef PROTECT
00094 #undef PROTECT
00095 #endif
00096 #define PROTECT(x) do { QMutexLocker l(&ThreadWeaver::GlobalMutex); (x); } while (0)
00097
00099 #ifdef P_ASSERT
00100 #undef P_ASSERT
00101 #endif
00102
00103 #define P_ASSERT(x) do { QMutexLocker l(&ThreadWeaver::GlobalMutex); Q_ASSERT(x); } while (0)
00104
00105 inline void setDebugLevel (bool debug, int level)
00106 {
00107 Debug = debug;
00108 DebugLevel = level;
00109 }
00110
00111 #ifndef QT_NO_DEBUG
00112 inline void debug(int severity, const char * cformat, ...)
00113 {
00114 if ( Debug == true && ( severity<=DebugLevel || severity == 0) )
00115 {
00116 QString text;
00117
00118 va_list ap;
00119 va_start( ap, cformat );
00120 PROTECT (vprintf (cformat, ap));
00121 va_end (ap);
00122 }
00123 }
00124
00125 inline void debug(bool condition, int severity, const char *cformat, ...)
00126 {
00127 if (condition && Debug == true && ( severity<=DebugLevel || severity == 0) )
00128 {
00129 QString text;
00130
00131 va_list ap;
00132 va_start( ap, cformat );
00133 PROTECT (vprintf (cformat, ap));
00134 va_end (ap);
00135 }
00136 }
00137 #else
00138 inline void debug(int, const char *, ...) {}
00139 inline void debug(bool, int, const char *, ...) {}
00140 #endif
00141
00142 inline bool invariant() { return true; }
00143
00144 #define INVARIANT Q_ASSERT_X (invariant(), __FILE__, "class invariant failed" );
00145
00146 #define REQUIRE(x) \
00147 INVARIANT \
00148 Q_ASSERT_X (x, Q_FUNC_INFO, "unfulfilled requirement " #x );
00149
00150 #define ENSURE(x) \
00151 INVARIANT \
00152 Q_ASSERT_X (x, Q_FUNC_INFO, "broken guarantee " #x );
00153
00154
00155 #ifdef QT_NO_DEBUG
00156 #define DEBUGONLY(x)
00157 #else
00158 #define DEBUGONLY(x) x
00159 #endif
00160
00161 }
00162
00163 #endif // DEBUGGINGAIDS_H