GDCM
2.0.18
|
00001 /*========================================================================= 00002 00003 Program: GDCM (Grassroots DICOM). A DICOM library 00004 00005 Copyright (c) 2006-2011 Mathieu Malaterre 00006 All rights reserved. 00007 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 #ifndef GDCMTRACE_H 00015 #define GDCMTRACE_H 00016 00017 #include "gdcmTypes.h" 00018 #include "gdcmSystem.h" 00019 00020 #include <iosfwd> 00021 #include <cassert> 00022 00023 namespace gdcm 00024 { 00025 00032 class GDCM_EXPORT Trace 00033 { 00034 public : 00035 Trace(); 00036 ~Trace(); 00037 00039 static void SetStream(std::ostream &os); 00040 static std::ostream &GetStream(); 00041 00042 static void SetDebug(bool debug); 00043 static void DebugOn(); 00044 static void DebugOff(); 00045 static bool GetDebugFlag(); 00046 00047 static void SetWarning(bool debug); 00048 static void WarningOn(); 00049 static void WarningOff(); 00050 static bool GetWarningFlag(); 00051 00052 static void SetError(bool debug); 00053 static void ErrorOn(); 00054 static void ErrorOff(); 00055 static bool GetErrorFlag(); 00056 00058 GDCM_LEGACY(static bool GetDebugToFile ()) 00059 GDCM_LEGACY(static std::ofstream &GetDebugFile ()) 00060 00061 protected: 00062 private: 00063 }; 00064 00065 // Here we define function this is the only way to be able to pass 00066 // stuff with indirection like: 00067 // gdcmDebug( "my message:" << i << '\t' ); 00068 // You cannot use function unless you use vnsprintf ... 00069 00070 // __FUNCTION is not always defined by preprocessor 00071 // In c++ we should use __PRETTY_FUNCTION__ instead... 00072 #ifdef GDCM_CXX_HAS_FUNCTION 00073 // Handle particular case for GNU C++ which also defines __PRETTY_FUNCTION__ 00074 // which is a lot nice in C++ 00075 #ifdef __BORLANDC__ 00076 # define __FUNCTION__ __FUNC__ 00077 #endif 00078 #ifdef __GNUC__ 00079 # define GDCM_FUNCTION __PRETTY_FUNCTION__ 00080 #else 00081 # define GDCM_FUNCTION __FUNCTION__ 00082 #endif //__GNUC__ 00083 #else 00084 # define GDCM_FUNCTION "<unknow>" 00085 #endif //GDCM_CXX_HAS_FUNCTION 00086 00091 #ifdef NDEBUG 00092 #define gdcmDebugMacro(msg) {} 00093 #else 00094 #define gdcmDebugMacro(msg) \ 00095 { \ 00096 if( gdcm::Trace::GetDebugFlag() ) \ 00097 { \ 00098 std::ostringstream osmacro; \ 00099 osmacro << "Debug: In " __FILE__ ", line " << __LINE__ \ 00100 << ", function " << GDCM_FUNCTION << '\n' \ 00101 << "Last system error was: " \ 00102 << gdcm::System::GetLastSystemError() << '\n' << msg; \ 00103 std::ostream &_os = gdcm::Trace::GetStream(); \ 00104 _os << osmacro.str() << "\n\n" << std::endl; \ 00105 } \ 00106 } 00107 #endif //NDEBUG 00108 00113 #ifdef NDEBUG 00114 #define gdcmWarningMacro(msg) {} 00115 #else 00116 #define gdcmWarningMacro(msg) \ 00117 { \ 00118 if( gdcm::Trace::GetWarningFlag() ) \ 00119 { \ 00120 std::ostringstream osmacro; \ 00121 osmacro << "Warning: In " __FILE__ ", line " << __LINE__ \ 00122 << ", function " << GDCM_FUNCTION << "\n" \ 00123 << msg << "\n\n"; \ 00124 std::ostream &_os = gdcm::Trace::GetStream(); \ 00125 _os << osmacro.str() << std::endl; \ 00126 } \ 00127 } 00128 #endif //NDEBUG 00129 00135 #ifdef NDEBUG 00136 #define gdcmErrorMacro(msg) {} 00137 #else 00138 #define gdcmErrorMacro(msg) \ 00139 { \ 00140 if( gdcm::Trace::GetErrorFlag() ) \ 00141 { \ 00142 std::ostringstream osmacro; \ 00143 osmacro << "Error: In " __FILE__ ", line " << __LINE__ \ 00144 << ", function " << GDCM_FUNCTION << '\n' \ 00145 << msg << "\n\n"; \ 00146 std::ostream &_os = gdcm::Trace::GetStream(); \ 00147 _os << osmacro.str() << std::endl; \ 00148 } \ 00149 } 00150 #endif //NDEBUG 00151 00158 #ifdef NDEBUG 00159 #define gdcmAssertMacro(arg) {} 00160 #else 00161 #define gdcmAssertMacro(arg) \ 00162 { \ 00163 if( !(arg) ) \ 00164 { \ 00165 std::ostringstream osmacro; \ 00166 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \ 00167 << ", function " << GDCM_FUNCTION \ 00168 << "\n\n"; \ 00169 std::ostream &_os = gdcm::Trace::GetStream(); \ 00170 _os << osmacro.str() << std::endl; \ 00171 assert ( arg ); \ 00172 } \ 00173 } 00174 #endif //NDEBUG 00175 00182 #ifdef NDEBUG 00183 // User asked for release compilation, but still need to report 00184 // if grave issue. 00185 #define gdcmAssertAlwaysMacro(arg) \ 00186 { \ 00187 if( !(arg) ) \ 00188 { \ 00189 std::ostringstream osmacro; \ 00190 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \ 00191 << ", function " << GDCM_FUNCTION \ 00192 << "\n\n"; \ 00193 throw osmacro.str(); \ 00194 } \ 00195 } 00196 #else 00197 // Simply reproduce gdcmAssertMacro behavior: 00198 #define gdcmAssertAlwaysMacro(arg) gdcmAssertMacro(arg) 00199 #endif //NDEBUG 00200 00201 } // end namespace gdcm 00202 //----------------------------------------------------------------------------- 00203 #endif //GDCMTRACE_H