Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef GDCMTRACE_H
00016 #define GDCMTRACE_H
00017
00018 #include "gdcmTypes.h"
00019
00020 #include <string>
00021 #include <vector>
00022 #include <iostream>
00023 #include <fstream>
00024 #include <sstream>
00025 #include <assert.h>
00026 #include <errno.h>
00027 #include <string.h>
00028
00029
00030 namespace gdcm
00031 {
00032
00037 class GDCM_EXPORT Trace
00038 {
00039 public :
00040 Trace();
00041 ~Trace();
00042
00043 static void SetDebug(bool debug);
00044 static void DebugOn();
00045 static void DebugOff();
00046 static bool GetDebugFlag();
00047
00048 static void SetWarning(bool debug);
00049 static void WarningOn();
00050 static void WarningOff();
00051 static bool GetWarningFlag();
00052
00053 static void SetError(bool debug);
00054 static void ErrorOn();
00055 static void ErrorOff();
00056 static bool GetErrorFlag();
00057
00058 static bool GetDebugToFile ();
00059 static std::ofstream &GetDebugFile ();
00060
00061 protected:
00062 private:
00063
00064
00065
00066 };
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifdef GDCM_CXX_HAS_FUNCTION
00076
00077
00078 #ifdef __BORLANDC__
00079 # define __FUNCTION__ __FUNC__
00080 #endif
00081 #ifdef __GNUC__
00082 # define GDCM_FUNCTION __PRETTY_FUNCTION__
00083 #else
00084 # define GDCM_FUNCTION __FUNCTION__
00085 #endif //__GNUC__
00086 #else
00087 # define GDCM_FUNCTION "<unknow>"
00088 #endif //GDCM_CXX_HAS_FUNCTION
00089
00094 #ifdef NDEBUG
00095 #define gdcmDebugMacro(msg) {}
00096 #else
00097 #define gdcmDebugMacro(msg) \
00098 { \
00099 if( gdcm::Trace::GetDebugFlag() ) \
00100 { \
00101 std::ostringstream osmacro; \
00102 osmacro << "Debug: In " __FILE__ ", line " << __LINE__ \
00103 << ", function " << GDCM_FUNCTION << '\n' \
00104 << "Last system error was: " << strerror(errno) \
00105 << '\n' << msg << "\n\n"; \
00106 if( gdcm::Trace::GetDebugToFile() ) \
00107 gdcm::Trace::GetDebugFile() << osmacro.str() << std::endl; \
00108 else \
00109 std::cerr << osmacro.str() << std::endl; \
00110 } \
00111 }
00112 #endif //NDEBUG
00113
00118 #ifdef NDEBUG
00119 #define gdcmWarningMacro(msg) {}
00120 #else
00121 #define gdcmWarningMacro(msg) \
00122 { \
00123 if( gdcm::Trace::GetWarningFlag() ) \
00124 { \
00125 std::ostringstream osmacro; \
00126 osmacro << "Warning: In " __FILE__ ", line " << __LINE__ \
00127 << ", function " << GDCM_FUNCTION << "\n" \
00128 << msg << "\n\n"; \
00129 if( gdcm::Trace::GetDebugToFile() ) \
00130 gdcm::Trace::GetDebugFile() << osmacro.str() << std::endl; \
00131 else \
00132 std::cerr << osmacro.str() << std::endl; \
00133 } \
00134 }
00135 #endif //NDEBUG
00136
00142 #ifdef NDEBUG
00143 #define gdcmErrorMacro(msg) {}
00144 #else
00145 #define gdcmErrorMacro(msg) \
00146 { \
00147 if( gdcm::Trace::GetErrorFlag() ) \
00148 { \
00149 std::ostringstream osmacro; \
00150 osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
00151 << ", function " << GDCM_FUNCTION << '\n' \
00152 << msg << "\n\n"; \
00153 if( gdcm::Trace::GetDebugToFile() ) \
00154 gdcm::Trace::GetDebugFile() << osmacro.str() << std::endl; \
00155 else \
00156 std::cerr << osmacro.str() << std::endl; \
00157 } \
00158 }
00159 #endif //NDEBUG
00160
00167 #ifdef NDEBUG
00168 #define gdcmAssertMacro(arg) {}
00169 #else
00170 #define gdcmAssertMacro(arg) \
00171 { \
00172 if( !(arg) ) \
00173 { \
00174 std::ostringstream osmacro; \
00175 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
00176 << ", function " << GDCM_FUNCTION \
00177 << "\n\n"; \
00178 if( gdcm::Trace::GetDebugToFile() ) \
00179 gdcm::Trace::GetDebugFile() << osmacro.str() << std::endl; \
00180 else \
00181 std::cerr << osmacro.str() << std::endl; \
00182 assert ( arg ); \
00183 } \
00184 }
00185 #endif //NDEBUG
00186
00193 #ifdef NDEBUG
00194
00195
00196 #define gdcmAssertAlwaysMacro(arg) \
00197 { \
00198 if( !(arg) ) \
00199 { \
00200 std::ostringstream osmacro; \
00201 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
00202 << ", function " << GDCM_FUNCTION \
00203 << "\n\n"; \
00204 throw osmacro.str(); \
00205 } \
00206 }
00207 #else
00208
00209 #define gdcmAssertAlwaysMacro(arg) gdcmAssertMacro(arg)
00210 #endif //NDEBUG
00211
00212 }
00213
00214 #endif //GDCMTRACE_H