00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _GDCMDEBUG_H_
00020 #define _GDCMDEBUG_H_
00021
00022 #include "gdcmCommon.h"
00023 #include "gdcmCommand.h"
00024
00025 #include <iostream>
00026 #include <sstream>
00027 #include <fstream>
00028 #include <assert.h>
00029 #include <errno.h>
00030
00031 namespace GDCM_NAME_SPACE
00032 {
00033
00034 class CommandManager;
00035
00036
00070 class GDCM_EXPORT Debug
00071 {
00072 public:
00073 Debug();
00074 ~Debug();
00075
00079 static void SetDebugFlag (bool flag);
00081 static bool GetDebugFlag () {return DebugFlag; }
00083 static void DebugOn () { SetDebugFlag(true); }
00085 static void DebugOff () { SetDebugFlag(false); }
00086
00089 static void SetLogFlag (bool flag);
00091 static bool GetLogFlag () {return LogFlag; }
00093 static void LogOn () { SetLogFlag(true); }
00095 static void LogOff () { SetLogFlag(false); }
00096
00099 static void SetWarningFlag (bool flag);
00101 static bool GetWarningFlag () {return WarningFlag; }
00103 static void WarningOn () { SetWarningFlag(true); }
00105 static void WarningOff () { SetWarningFlag(false); }
00106
00109 static void SetOutputToFile (bool flag);
00110 static bool GetOutputToFile ();
00112 static void OutputToFileOn () { SetOutputToFile(true); }
00114 static void OutputToFileOff () { SetOutputToFile(false); }
00115
00116 static void SetOutputFileName (std::string const &filename);
00117
00118 static std::ostream &GetOutput ();
00119
00120 static void SendToOutput(unsigned int type,std::string const &msg,
00121 const Base *object = NULL);
00122
00123 private:
00124 static bool WarningFlag;
00125 static bool LogFlag;
00126 static bool DebugFlag;
00127
00128 static bool OutputToFile;
00129
00130 static std::ofstream OutputFileStream;
00131 static std::ostream &StandardStream;
00132
00133 static const int LINE_LENGTH;
00134 };
00135
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145 #ifdef GDCM_COMPILER_HAS_FUNCTION
00146
00147
00148 #ifdef __BORLANDC__
00149 # define __FUNCTION__ __FUNC__
00150 #endif
00151 #ifdef __GNUC__
00152 # define GDCM_FUNCTION __PRETTY_FUNCTION__
00153 #else
00154 # define GDCM_FUNCTION __FUNCTION__
00155 #endif //__GNUC__
00156 #else
00157 # define GDCM_FUNCTION "<unknow>"
00158 #endif //GDCM_COMPILER_HAS_FUNCTION
00159
00167 #define gdcmMessageBodyMacro(type, obj, msg, adds) \
00168 { \
00169 std::ostringstream osmacro; \
00170 osmacro << "In " __FILE__ ", line " << __LINE__ \
00171 << ", function " << GDCM_FUNCTION << "\n" \
00172 << adds << msg << "\n\n"; \
00173 GDCM_NAME_SPACE::Debug::SendToOutput(type,osmacro.str(),obj);\
00174 }
00175
00176
00177
00183 #ifdef NDEBUG
00184 #define gdcmDebugBodyMacro(obj, msg) {}
00185 #define gdcmDebugMacro(msg) {}
00186 #define gdcmStaticDebugMacro(msg) {}
00187 #else
00188 #define gdcmDebugBodyMacro(obj, msg) \
00189 { \
00190 if( Debug::GetDebugFlag() ) \
00191 { \
00192 std::string adds=""; \
00193 if( errno ) \
00194 { \
00195 adds = "Last system error was: "; \
00196 adds += strerror(errno); \
00197 adds += "\n"; \
00198 } \
00199 gdcmMessageBodyMacro(GDCM_NAME_SPACE::CMD_DEBUG,obj,msg,adds);\
00200 } \
00201 }
00202 #define gdcmDebugMacro(msg) \
00203 gdcmDebugBodyMacro(NULL,msg)
00204 #define gdcmStaticDebugMacro(msg) \
00205 gdcmDebugBodyMacro(NULL,msg)
00206 #endif //NDEBUG
00207
00208
00209
00215
00216
00217 #define gdcmLogBodyMacro(obj, msg) \
00218 { \
00219 if( Debug::GetLogFlag() ) \
00220 gdcmMessageBodyMacro(GDCM_NAME_SPACE::CMD_LOG,obj,msg,"");\
00221 }
00222 #define gdcmLogMacro(msg) \
00223 gdcmLogBodyMacro(this,msg)
00224 #define gdcmStaticLogMacro(msg) \
00225 gdcmLogBodyMacro(NULL,msg)
00226
00227
00228
00234
00235
00236 #define gdcmWarningBodyMacro(obj, msg) \
00237 { \
00238 if( Debug::GetWarningFlag() ) \
00239 gdcmMessageBodyMacro(GDCM_NAME_SPACE::CMD_WARNING,obj,msg,"");\
00240 }
00241 #define gdcmWarningMacro(msg) \
00242 gdcmWarningBodyMacro(this,msg)
00243 #define gdcmStaticWarningMacro(msg) \
00244 gdcmWarningBodyMacro(NULL,msg)
00245
00246
00247
00254
00255
00256 #define gdcmErrorBodyMacro(obj, msg) \
00257 { \
00258 gdcmMessageBodyMacro(GDCM_NAME_SPACE::CMD_ERROR,obj,msg,"");\
00259 }
00260 #define gdcmErrorMacro(msg) \
00261 gdcmErrorBodyMacro(this,msg)
00262 #define gdcmStaticErrorMacro(msg) \
00263 gdcmErrorBodyMacro(NULL,msg)
00264
00265
00266
00276
00277
00278 #define gdcmAssertBodyMacro(obj, arg) \
00279 { \
00280 if( !(arg) ) \
00281 { \
00282 gdcmMessageBodyMacro(GDCM_NAME_SPACE::CMD_ASSERT,obj,"","");\
00283 assert ( arg ); \
00284 } \
00285 }
00286 #define gdcmAssertMacro(msg) \
00287 gdcmAssertBodyMacro(NULL,msg)
00288 #define gdcmStaticAssertMacro(msg) \
00289 gdcmAssertBodyMacro(NULL,msg)
00290
00291
00292 #endif