1 /**
2 *  Copyright Mikael H�gdahl - triyana@users.sourceforge.net
3 *
4 *  This source is distributed under aa terms of aa Q Public License version 1.0,
5 *  created by Trolltech (www.trolltech.com).
6 */
7 
8 #ifndef MHDebug_h
9 #define MHDebug_h
10 
11 #include <stdio.h>
12 
13 #ifdef BUGG
14     #define DBG_OPTIONS(x)               MHDebug::Options (x);
15     #define DBG_WATCH(x)                 MHDebug::Watch (x);
16     #define DBG(x)                       MHDebug dbg (x, false);
17     #define DBG_TIME(x)                  MHDebug dbg (x, true);
18     #define DBG_LOG(a)                   dbg.Log (a);
19     #define DBG_LOG1(a,b)                dbg.Log (a,b);
20     #define DBG_LOG2(a,b,c)              dbg.Log (a,b,c);
21     #define DBG_LOG3(a,b,c,d)            dbg.Log (a,b,c,d);
22     #define DBG_LOG4(a,b,c,d,e)          dbg.Log (a,b,c,d,e);
23     #define DBG_LOG5(a,b,c,d,e,f)        dbg.Log (a,b,c,d,e,f);
24     #define DBG_LOG6(a,b,c,d,e,f,g)      dbg.Log (a,b,c,d,e,f,g);
25     #define DBG_LOG7(a,b,c,d,e,f,g,h)    dbg.Log (a,b,c,d,e,f,g,h);
26     #define DBG_LOG8(a,b,c,d,e,f,g,h,i)  dbg.Log (a,b,c,d,e,f,g,h,i);
27     #define DBG_PRINT                    MHDebug::PrintLog();
28     #define DBG_START                    MHDebug::Start();
29     #define DBG_STOP                     MHDebug::Stop();
30 #else
31     #define DBG_OPTIONS(x)
32     #define DBG_WATCH(x)
33     #define DBG(x)
34     #define DBG_TIME(x)
35     #define DBG_LOG(a)
36     #define DBG_LOG1(a,b)
37     #define DBG_LOG2(a,b,c)
38     #define DBG_LOG3(a,b,c,d)
39     #define DBG_LOG4(a,b,c,d,e)
40     #define DBG_LOG5(a,b,c,d,e,f)
41     #define DBG_LOG6(a,b,c,d,e,f,g)
42     #define DBG_LOG7(a,b,c,d,e,f,g,h)
43     #define DBG_LOG8(a,b,c,d,e,f,g,h,i)
44     #define DBG_PRINT
45     #define DBG_START
46     #define DBG_STOP
47 #endif
48 
49 class MHDate;
50 class MHString;
51 class MHVector;
52 
53 
54 
55 /**
56 *  A simple debug module. Define BUGG to use it.
57 *  Remove BUGG when you do a build release.
58 */
59 class MHDebug {
60 public:
61     enum {
62                                 BUFFER_SIZE = 100000,
63     };
64 
65                                 MHDebug (const char* pName, bool bTime = false);
66                                 ~MHDebug ();
67 
68     void                        Log (const char *Message, ...);
69     static void                 Options (const char* pString);
70     static void                 Print (const char* buffer);
71     static void                 PrintLog();
72     static void                 Start ();
73     static void                 Stop ();
74     static void                 Watch (const char* pString);
75 
76 private:
77     char                        aTab[30];
78     bool                        aWatch;
79     bool                        aTime;
80     MHString*                   aName;
81     MHDate*                     aDate;
82     double                      aSecs;
83     static bool                 aaTrace;
84     static bool                 aaLogStuff;
85     static bool                 aaFlush;
86     static int                  aaLevel;
87     static char                 aaBuffer[BUFFER_SIZE];
88     static char                 aaBuffer2[BUFFER_SIZE];
89     static MHVector*            aaLog;
90     static MHVector*            aaWatches;
91     static FILE*                aaFile;
92 };
93 
94 #endif
95