kmail

kmdebug.h
1 // -*- c++ -*- convenience wrappers around kdDebug/kdWarning/etc
2 
3 #ifndef __KMAIL_KMDEBUG_H__
4 #define __KMAIL_KMDEBUG_H__
5 
6 #include <kdebug.h>
7 
8 // Enable this to debug timing
9 // #define DEBUG_TIMING
10 
11 // return type of kmDebug() depends on NDEBUG define:
12 #ifdef NDEBUG
13 # define kmail_dbgstream kndbgstream
14 #else
15 # define kmail_dbgstream kdbgstream
16 #endif
17 
19 static const int kmail_debug_area = 5006;
20 
21 static inline kmail_dbgstream kmDebug() { return kdDebug( kmail_debug_area ); }
22 static inline kmail_dbgstream kmDebug( bool cond ) { return kdDebug( cond, kmail_debug_area ); }
23 
24 static inline kdbgstream kmWarning() { return kdWarning( kmail_debug_area ); }
25 static inline kdbgstream kmWarning( bool cond ) { return kdWarning( cond, kmail_debug_area ); }
26 
27 static inline kdbgstream kmError() { return kdError( kmail_debug_area ); }
28 static inline kdbgstream kmError( bool cond ) { return kdError( cond, kmail_debug_area ); }
29 
30 static inline kdbgstream kmFatal() { return kdFatal( kmail_debug_area ); }
31 static inline kdbgstream kmFatal( bool cond ) { return kdFatal( cond, kmail_debug_area ); }
32 
33 // timing utilities
34 #if !defined( NDEBUG ) && defined( DEBUG_TIMING )
35 #include <tqdatetime.h>
36 #define CREATE_TIMER(x) int x=0, x ## _tmp=0; TQTime x ## _tmp2
37 #define START_TIMER(x) x ## _tmp2 = TQTime::currentTime()
38 #define GRAB_TIMER(x) x ## _tmp2.msecsTo(TQTime::currentTime())
39 #define END_TIMER(x) x += GRAB_TIMER(x); x ## _tmp++
40 #define SHOW_TIMER(x) kdDebug(5006) << #x " == " << x << "(" << x ## _tmp << ")\n"
41 #else
42 #define CREATE_TIMER(x)
43 #define START_TIMER(x)
44 #define GRAB_TIMER(x)
45 #define END_TIMER(x)
46 #define SHOW_TIMER(x)
47 #endif
48 
49 // profiling utilities
50 #if !defined( NDEBUG )
51 #define CREATE_COUNTER(x) int x ## _cnt=0
52 #define RESET_COUNTER(x) x ## _cnt=0
53 #define INC_COUNTER(x) x ## _cnt++
54 #define SHOW_COUNTER(x) kdDebug(5006) << #x " == " << x ## _cnt << endl
55 #else
56 #define CREATE_COUNTER(x)
57 #define RESET_COUNTER(x)
58 #define INC_COUNTER(x)
59 #define SHOW_COUNTER(x)
60 #endif
61 
62 #endif // __KMAIL_KMDEBUG_H__