GDCM 2.2.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

gdcmTrace.h
Go to the documentation of this file.

    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
    00057 protected:
    00058 private:
    00059 };
    00060
    00061 // Here we define function this is the only way to be able to pass
    00062 // stuff with indirection like:
    00063 // gdcmDebug( "my message:" << i << '\t' );
    00064 // You cannot use function unless you use vnsprintf ...
    00065
    00066 // __FUNCTION is not always defined by preprocessor
    00067 // In c++ we should use __PRETTY_FUNCTION__ instead...
    00068 #ifdef GDCM_CXX_HAS_FUNCTION
    00069 // Handle particular case for GNU C++ which also defines __PRETTY_FUNCTION__
    00070 // which is a lot nice in C++
    00071 #ifdef __BORLANDC__
    00072 #  define __FUNCTION__ __FUNC__
    00073 #endif
    00074 #ifdef __GNUC__
    00075 #  define GDCM_FUNCTION __PRETTY_FUNCTION__
    00076 #else
    00077 #  define GDCM_FUNCTION __FUNCTION__
    00078 #endif //__GNUC__
    00079 #else
    00080 #  define GDCM_FUNCTION "<unknow>"
    00081 #endif //GDCM_CXX_HAS_FUNCTION
    00082
    00087 #ifdef NDEBUG
    00088 #define gdcmDebugMacro(msg) {}
    00089 #else
    00090 #define gdcmDebugMacro(msg)                                       \
    00091 {                                                                 \
    00092    if( gdcm::Trace::GetDebugFlag() )                              \
    00093    {                                                              \
    00094    std::ostringstream osmacro;                                    \
    00095    osmacro << "Debug: In " __FILE__ ", line " << __LINE__         \
    00096            << ", function " << GDCM_FUNCTION << '\n'              \
    00097            << "Last system error was: "                           \
    00098            << gdcm::System::GetLastSystemError() << '\n' << msg;  \
    00099    std::ostream &_os = gdcm::Trace::GetStream();                   \
    00100    _os << osmacro.str() << "\n\n" << std::endl;                    \
    00101    }                                                              \
    00102 }
    00103 #endif //NDEBUG
    00104
    00109 #ifdef NDEBUG
    00110 #define gdcmWarningMacro(msg) {}
    00111 #else
    00112 #define gdcmWarningMacro(msg)                                     \
    00113 {                                                                 \
    00114    if( gdcm::Trace::GetWarningFlag() )                            \
    00115    {                                                              \
    00116    std::ostringstream osmacro;                                    \
    00117    osmacro << "Warning: In " __FILE__ ", line " << __LINE__       \
    00118            << ", function " << GDCM_FUNCTION << "\n"              \
    00119            << msg << "\n\n";                                      \
    00120    std::ostream &_os = gdcm::Trace::GetStream();                   \
    00121    _os << osmacro.str() << std::endl;                              \
    00122    }                                                              \
    00123 }
    00124 #endif //NDEBUG
    00125
    00131 #ifdef NDEBUG
    00132 #define gdcmErrorMacro(msg) {}
    00133 #else
    00134 #define gdcmErrorMacro(msg)                                       \
    00135 {                                                                 \
    00136    if( gdcm::Trace::GetErrorFlag() )                              \
    00137    {                                                              \
    00138    std::ostringstream osmacro;                                    \
    00139    osmacro << "Error: In " __FILE__ ", line " << __LINE__         \
    00140            << ", function " << GDCM_FUNCTION << '\n'              \
    00141            << msg << "\n\n";                                      \
    00142    std::ostream &_os = gdcm::Trace::GetStream();                   \
    00143    _os << osmacro.str() << std::endl;                              \
    00144    }                                                              \
    00145 }
    00146 #endif //NDEBUG
    00147
    00154 #ifdef NDEBUG
    00155 #define gdcmAssertMacro(arg) {}
    00156 #else
    00157 #define gdcmAssertMacro(arg)                                      \
    00158 {                                                                 \
    00159    if( !(arg) )                                                   \
    00160    {                                                              \
    00161    std::ostringstream osmacro;                                    \
    00162    osmacro << "Assert: In " __FILE__ ", line " << __LINE__        \
    00163            << ", function " << GDCM_FUNCTION                      \
    00164            << "\n\n";                                             \
    00165    std::ostream &_os = gdcm::Trace::GetStream();                   \
    00166    _os << osmacro.str() << std::endl;                              \
    00167    assert ( arg );                                                \
    00168    }                                                              \
    00169 }
    00170 #endif //NDEBUG
    00171
    00178 #ifdef NDEBUG
    00179 // User asked for release compilation, but still need to report
    00180 // if grave issue.
    00181 #define gdcmAssertAlwaysMacro(arg) \
    00182 {                                                                 \
    00183    if( !(arg) )                                                   \
    00184    {                                                              \
    00185    std::ostringstream osmacro;                                    \
    00186    osmacro << "Assert: In " __FILE__ ", line " << __LINE__        \
    00187            << ", function " << GDCM_FUNCTION                      \
    00188            << "\n\n";                                             \
    00189    throw osmacro.str();                                           \
    00190    }                                                              \
    00191 }
    00192 #else
    00193 // Simply reproduce gdcmAssertMacro behavior:
    00194 #define gdcmAssertAlwaysMacro(arg) gdcmAssertMacro(arg)
    00195 #endif //NDEBUG
    00196
    00197 } // end namespace gdcm
    00198 //-----------------------------------------------------------------------------
    00199 #endif //GDCMTRACE_H