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
00024 #include <sstream>
00025 #include <fstream>
00026 #include <assert.h>
00027 #include <errno.h>
00028
00029 namespace gdcm
00030 {
00031
00032
00044 class GDCM_EXPORT Debug
00045 {
00046 public:
00047 Debug();
00048 ~Debug();
00049
00052 static void SetDebugFlag (bool flag);
00053 static bool GetDebugFlag ();
00055 static void DebugOn () { SetDebugFlag(true); };
00057 static void DebugOff () { SetDebugFlag(false); };
00058
00061 static void SetDebugToFile (bool flag);
00062 static bool GetDebugToFile ();
00064 static void DebugToFileOn () { SetDebugToFile(true); };
00066 static void DebugToFileOff () { SetDebugToFile(false); };
00067
00068 static void SetDebugFilename (std::string const &filename);
00069
00070 static std::ofstream &GetDebugFile ();
00071 };
00072
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082 #ifdef GDCM_COMPILER_HAS_FUNCTION
00083
00084
00085 #ifdef __BORLANDC__
00086 # define __FUNCTION__ __FUNC__
00087 #endif
00088 #ifdef __GNUC__
00089 # define GDCM_FUNCTION __PRETTY_FUNCTION__
00090 #else
00091 # define GDCM_FUNCTION __FUNCTION__
00092 #endif //__GNUC__
00093 #else
00094 # define GDCM_FUNCTION "<unknow>"
00095 #endif //GDCM_COMPILER_HAS_FUNCTION
00096
00101 #ifdef NDEBUG
00102 #define gdcmDebugMacro(msg)
00103 #else
00104 #define gdcmDebugMacro(msg) \
00105 { \
00106 if( Debug::GetDebugFlag() ) \
00107 { \
00108 std::ostringstream osmacro; \
00109 osmacro << "Debug: In " __FILE__ ", line " << __LINE__ \
00110 << ", function " << GDCM_FUNCTION << '\n' \
00111 << "Last system error was: " << strerror(errno) \
00112 << '\n' << msg << "\n\n"; \
00113 if( Debug::GetDebugToFile() ) \
00114 Debug::GetDebugFile() << osmacro.str() << std::endl; \
00115 else \
00116 std::cerr << osmacro.str() << std::endl; \
00117 } \
00118 }
00119 #endif //NDEBUG
00120
00125 #ifdef NDEBUG
00126 #define gdcmWarningMacro(msg)
00127 #else
00128 #define gdcmWarningMacro(msg) \
00129 { \
00130 if( Debug::GetDebugFlag() ) \
00131 { \
00132 std::ostringstream osmacro; \
00133 osmacro << "Verbose: In " __FILE__ ", line " << __LINE__ \
00134 << ", function " << GDCM_FUNCTION << "\n" \
00135 << msg << "\n\n"; \
00136 if( Debug::GetDebugToFile() ) \
00137 Debug::GetDebugFile() << osmacro.str() << std::endl; \
00138 else \
00139 std::cerr << osmacro.str() << std::endl; \
00140 } \
00141 }
00142 #endif //NDEBUG
00143
00148 #ifdef NDEBUG
00149 #define gdcmErrorMacro(msg)
00150 #else
00151 #define gdcmErrorMacro(msg) \
00152 { \
00153 std::ostringstream osmacro; \
00154 osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
00155 << ", function " << GDCM_FUNCTION << '\n' \
00156 << msg << "\n\n"; \
00157 if( Debug::GetDebugToFile() ) \
00158 Debug::GetDebugFile() << osmacro.str() << std::endl; \
00159 else \
00160 std::cerr << osmacro.str() << std::endl; \
00161 }
00162 #endif //NDEBUG
00163
00170 #ifdef NDEBUG
00171 #define gdcmAssertMacro(arg)
00172 #else
00173 #define gdcmAssertMacro(arg) \
00174 { \
00175 if( !(arg) ) \
00176 { \
00177 std::ostringstream osmacro; \
00178 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
00179 << ", function " << GDCM_FUNCTION \
00180 << "\n\n"; \
00181 if( Debug::GetDebugToFile() ) \
00182 Debug::GetDebugFile() << osmacro.str() << std::endl; \
00183 else \
00184 std::cerr << osmacro.str() << std::endl; \
00185 assert ( arg ); \
00186 } \
00187 }
00188 #endif //NDEBUG
00189
00190 #endif