kmail

kmdebug.h

Go to the documentation of this file.
00001 // -*- c++ -*- convenience wrappers around kdDebug/kdWarning/etc
00002 
00003 #ifndef __KMAIL_KMDEBUG_H__
00004 #define __KMAIL_KMDEBUG_H__
00005 
00006 #include <kdebug.h>
00007 
00008 // Enable this to debug timing
00009 // #define DEBUG_TIMING
00010 
00011 // return type of kmDebug() depends on NDEBUG define:
00012 #ifdef NDEBUG
00013 # define kmail_dbgstream kndbgstream
00014 #else
00015 # define kmail_dbgstream kdbgstream
00016 #endif
00017 
00019 static const int kmail_debug_area = 5006;
00020 
00021 static inline kmail_dbgstream kmDebug() { return kdDebug( kmail_debug_area ); }
00022 static inline kmail_dbgstream kmDebug( bool cond ) { return kdDebug( cond, kmail_debug_area ); }
00023 
00024 static inline kdbgstream kmWarning() { return kdWarning( kmail_debug_area ); }
00025 static inline kdbgstream kmWarning( bool cond ) { return kdWarning( cond, kmail_debug_area ); }
00026 
00027 static inline kdbgstream kmError() { return kdError( kmail_debug_area ); }
00028 static inline kdbgstream kmError( bool cond ) { return kdError( cond, kmail_debug_area ); }
00029 
00030 static inline kdbgstream kmFatal() { return kdFatal( kmail_debug_area ); }
00031 static inline kdbgstream kmFatal( bool cond ) { return kdFatal( cond, kmail_debug_area ); }
00032 
00033 // timing utilities
00034 #if !defined( NDEBUG ) && defined( DEBUG_TIMING )
00035 #include <qdatetime.h>
00036 #define CREATE_TIMER(x) int x=0, x ## _tmp=0; QTime x ## _tmp2
00037 #define START_TIMER(x) x ## _tmp2 = QTime::currentTime()
00038 #define GRAB_TIMER(x) x ## _tmp2.msecsTo(QTime::currentTime())
00039 #define END_TIMER(x) x += GRAB_TIMER(x); x ## _tmp++
00040 #define SHOW_TIMER(x) kdDebug(5006) << #x " == " << x << "(" << x ## _tmp << ")\n"
00041 #else
00042 #define CREATE_TIMER(x)
00043 #define START_TIMER(x)
00044 #define GRAB_TIMER(x)
00045 #define END_TIMER(x)
00046 #define SHOW_TIMER(x)
00047 #endif
00048 
00049 // profiling utilities
00050 #if !defined( NDEBUG )
00051 #define CREATE_COUNTER(x) int x ## _cnt=0
00052 #define RESET_COUNTER(x) x ## _cnt=0
00053 #define INC_COUNTER(x) x ## _cnt++
00054 #define SHOW_COUNTER(x) kdDebug(5006) << #x " == " << x ## _cnt << endl
00055 #else
00056 #define CREATE_COUNTER(x)
00057 #define RESET_COUNTER(x)
00058 #define INC_COUNTER(x)
00059 #define SHOW_COUNTER(x)
00060 #endif
00061 
00062 #endif // __KMAIL_KMDEBUG_H__