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