kviewshell
debug.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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifndef _DEBUG_H_
00058 #define _DEBUG_H_
00059
00060 #ifdef HAVE_CONFIG_H
00061 # include "config.h"
00062 #endif
00063 #if NEED_GNUG_PRAGMAS
00064 # pragma interface
00065 #endif
00066
00067 #include <stdio.h>
00068 #ifdef WIN32
00069 # include <atlbase.h>
00070 # include <windows.h>
00071 #endif
00072
00073
00074 #ifdef HAVE_NAMESPACES
00075 namespace DJVU {
00076 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00077 }
00078 # endif
00079 #endif
00080
00134
00135 #ifndef DEBUGLVL
00136 # ifdef NDEBUG
00137 # define DEBUGLVL 0
00138 # endif
00139 #endif
00140 #ifndef DEBUGLVL
00141 # ifdef NO_DEBUG
00142 # define DEBUGLVL 0
00143 # endif
00144 #endif
00145 #ifndef DEBUGLVL
00146 # ifdef RUNTIME_DEBUG_ONLY
00147 # define DEBUGLVL 1
00148 # endif
00149 #endif
00150 #ifndef DEBUGLVL
00151 # ifdef _DEBUG
00152 # define DEBUGLVL 1
00153 # endif
00154 #endif
00155 #ifndef DEBUGLVL
00156 # define DEBUGLVL 0
00157 #endif
00158
00159 #if DEBUGLVL <= 0
00160
00161 # ifndef NO_DEBUG
00162 # define NO_DEBUG
00163 # endif
00164 # ifndef NDEBUG
00165 # define NDEBUG
00166 # endif
00167 # ifdef _DEBUG
00168 # undef _DEBUG
00169 # endif
00170
00171 # define DEBUG_MAKE_INDENT(x)
00172 # define DEBUG_SET_LEVEL(level)
00173 # define DEBUG_MSG_LVL(level,x)
00174 # define DEBUG_MSGN_LVL(level,x)
00175
00176 #else
00177
00178 # ifdef NO_DEBUG
00179 # undef NO_DEBUG
00180 # endif
00181 # ifdef NDEBUG
00182 # undef NDEBUG
00183 # endif
00184 # ifndef _DEBUG
00185 # define _DEBUG
00186 # endif
00187
00188 class GUTF8String;
00189
00190
00191
00192 class DjVuDebug
00193 {
00194 private:
00195 int id;
00196 int block;
00197 int indent;
00198 void format(const char *fmt, ... );
00199 public:
00200
00201 DjVuDebug();
00202 ~DjVuDebug();
00203
00204 static void set_debug_level(int lvl);
00205 static void set_debug_file(FILE * file);
00206 void modify_indent(int rindent);
00207 static DjVuDebug& lock(int lvl, int noindent);
00208 void unlock();
00209
00210 DjVuDebug & operator<<(bool b);
00211 DjVuDebug & operator<<(char c);
00212 DjVuDebug & operator<<(unsigned char c);
00213 DjVuDebug & operator<<(int i);
00214 DjVuDebug & operator<<(unsigned int i);
00215 DjVuDebug & operator<<(short int i);
00216 DjVuDebug & operator<<(unsigned short int i);
00217 DjVuDebug & operator<<(long i);
00218 DjVuDebug & operator<<(unsigned long i);
00219 DjVuDebug & operator<<(const char * const ptr);
00220 DjVuDebug & operator<<(const unsigned char * const ptr);
00221 DjVuDebug& operator<<(const GUTF8String &ptr);
00222 DjVuDebug & operator<<(float f);
00223 DjVuDebug & operator<<(double d);
00224 DjVuDebug & operator<<(const void * const p);
00225 };
00226
00227 class DjVuDebugIndent
00228 {
00229 private:
00230 int inc;
00231 public:
00232 DjVuDebugIndent(int inc=2);
00233 ~DjVuDebugIndent();
00234
00235
00236 #define DEBUG_MAKE_INDENT_1(x, y) DjVuDebugIndent debug_indent ## y (x)
00237 };
00238
00239
00240
00241 # define DEBUG_MAKE_INDENT(x) DEBUG_MAKE_INDENT_1(x, __LINE__)
00242 # define DEBUG_SET_LEVEL(level) DjVuDebug::set_debug_level(level)
00243 # define DEBUG_MSG_LVL(level,x) { ( DjVuDebug::lock(level,0) << x ).unlock(); }
00244 # define DEBUG_MSGN_LVL(level,x) { ( DjVuDebug::lock(level,1) << x ).unlock(); }
00245 # define DEBUG_MSGF_LVL(level,x) { ( DjVuDebug::lock(level,1) << x ).unlock(); }
00246
00247 #endif
00248
00249
00250
00251
00252 #if ( DEBUGLVL >= 1 )
00253
00254 # define DEBUG1_MSG(x) DEBUG_MSG_LVL(1,x)
00255 # define DEBUG1_MSGF(x) DEBUG_MSGF_LVL(1,x)
00256 #else
00257 # define DEBUG1_MSG(x)
00258 # define DEBUG1_MSGF(x)
00259 #endif
00260 #if ( DEBUGLVL >= 2 )
00261
00262 # define DEBUG2_MSG(x) DEBUG_MSG_LVL(2,x)
00263 # define DEBUG2_MSGF(x) DEBUG_MSGF_LVL(2,x)
00264 #else
00265 # define DEBUG2_MSG(x)
00266 # define DEBUG2_MSGF(x)
00267 #endif
00268 #if ( DEBUGLVL >= 3 )
00269
00270 # define DEBUG3_MSG(x) DEBUG_MSG_LVL(3,x)
00271 # define DEBUG3_MSGF(x) DEBUG_MSGF_LVL(3,x)
00272 #else
00273 # define DEBUG3_MSG(x)
00274 # define DEBUG3_MSGF(x)
00275 #endif
00276 #if ( DEBUGLVL >= 4 )
00277
00278 # define DEBUG4_MSG(x) DEBUG_MSG_LVL(4,x)
00279 # define DEBUG4_MSGF(x) DEBUG_MSGF_LVL(4,x)
00280 #else
00281 # define DEBUG4_MSG(x)
00282 # define DEBUG4_MSGF(x)
00283 #endif
00284
00285 #define DEBUG_RUNTIME_SET_LEVEL(level) DEBUG_SET_LEVEL(level)
00286
00287 #define DEBUG_MSG(x) DEBUG1_MSG(x)
00288
00289 #define DEBUG_MSGF(x) DEBUG1_MSGF(x)
00290
00291 #define DEBUG_MSGN(x) DEBUG_MSG(x<<'\n')
00292
00294
00295
00296
00297 #ifdef HAVE_NAMESPACES
00298 }
00299 # ifndef NOT_USING_DJVU_NAMESPACE
00300 using namespace DJVU;
00301 # endif
00302 #endif
00303
00304 #endif // DEBUG_H