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 extern "C"
00035 {
00036 #include <stdarg.h>
00037 #include <unistd.h>
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <assert.h>
00041 }
00042
00043 #include <QtCore/QMutex>
00044 #include <QtCore/QString>
00045 #include "threadweaver/threadweaver_export.h"
00046
00047 namespace ThreadWeaver {
00048
00049 extern THREADWEAVER_EXPORT bool Debug;
00050 extern THREADWEAVER_EXPORT int DebugLevel;
00051 extern THREADWEAVER_EXPORT QMutex GlobalMutex;
00052
00056 extern inline void setDebugLevel (bool debug, int level);
00057
00073 inline void debug(int severity, const char * cformat, ...)
00074 #ifdef __GNUC__
00075 __attribute__ ( (format (printf, 2, 3 ) ) )
00076 #endif
00077 ;
00078
00080 inline void debug(bool condition, int severity, const char * cformat, ...)
00081 #ifdef __GNUC__
00082 __attribute__ ( (format (printf, 3, 4 ) ) )
00083 #endif
00084 ;
00085
00086
00089 #ifdef PROTECT
00090 #undef PROTECT
00091 #endif
00092 #define PROTECT(x) do { QMutexLocker l(&ThreadWeaver::GlobalMutex); (x); } while (0)
00093
00095 #ifdef P_ASSERT
00096 #undef P_ASSERT
00097 #endif
00098
00099 #define P_ASSERT(x) do { QMutexLocker l(&ThreadWeaver::GlobalMutex); Q_ASSERT(x); } while (0)
00100
00101 inline void setDebugLevel (bool debug, int level)
00102 {
00103 Debug = debug;
00104 DebugLevel = level;
00105 }
00106
00107 #ifndef QT_NO_DEBUG
00108 inline void debug(int severity, const char * cformat, ...)
00109 {
00110 if ( Debug == true && ( severity<=DebugLevel || severity == 0) )
00111 {
00112 QString text;
00113
00114 va_list ap;
00115 va_start( ap, cformat );
00116 PROTECT (vprintf (cformat, ap));
00117 va_end (ap);
00118 }
00119 }
00120
00121 inline void debug(bool condition, int severity, const char *cformat, ...)
00122 {
00123 if (condition && Debug == true && ( severity<=DebugLevel || severity == 0) )
00124 {
00125 QString text;
00126
00127 va_list ap;
00128 va_start( ap, cformat );
00129 PROTECT (vprintf (cformat, ap));
00130 va_end (ap);
00131 }
00132 }
00133 #else
00134 inline void debug(int, const char *, ...) {}
00135 inline void debug(bool, int, const char *, ...) {}
00136 #endif
00137
00138 inline bool invariant() { return true; }
00139
00140 #define INVARIANT Q_ASSERT_X (invariant(), __FILE__, "class invariant failed" );
00141
00142 #define REQUIRE(x) \
00143 INVARIANT \
00144 Q_ASSERT_X (x, Q_FUNC_INFO, "unfulfilled requirement " #x );
00145
00146 #define ENSURE(x) \
00147 INVARIANT \
00148 Q_ASSERT_X (x, Q_FUNC_INFO, "broken guarantee " #x );
00149
00150
00151 #ifdef QT_NO_DEBUG
00152 #define DEBUGONLY(x)
00153 #else
00154 #define DEBUGONLY(x) x
00155 #endif
00156
00157 }
00158
00159 #endif // DEBUGGINGAIDS_H