Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gdcmDebug.h

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmDebug.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006/01/03 14:28:53 $
00007   Version:   $Revision: 1.53 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
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 
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 } // end namespace gdcm
00137 
00138 // Here we define function this is the only way to be able to pass
00139 // stuff with indirection like:
00140 // gdcmDebug( "my message:" << i << '\t' ); 
00141 // You cannot use function unless you use vnsprintf ...
00142 
00143 // __FUNCTION is not always defined by preprocessor
00144 // In c++ we should use __PRETTY_FUNCTION__ instead...
00145 #ifdef GDCM_COMPILER_HAS_FUNCTION
00146 // Handle particular case for GNU C++ which also defines __PRETTY_FUNCTION__
00147 // which is a lot nice in C++
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 
00164 #define gdcmMessageBodyMacro(type, obj, msg, adds)             \
00165 {                                                              \
00166    std::ostringstream osmacro;                                 \
00167    osmacro << "In " __FILE__ ", line " << __LINE__             \
00168            << ", function " << GDCM_FUNCTION << "\n"           \
00169            << adds << msg << "\n\n";                           \
00170    gdcm::Debug::SendToOutput(type,osmacro.str(),obj);          \
00171 }
00172 
00173 // ------------------------------------------------------------------------
00174 
00179 #ifdef NDEBUG
00180 #define gdcmDebugBodyMacro(obj, msg) {}
00181 #define gdcmDebugMacro(msg) {}
00182 #define gdcmStaticDebugMacro(msg) {}
00183 #else
00184 #define gdcmDebugBodyMacro(obj, msg)                           \
00185 {                                                              \
00186    if( Debug::GetDebugFlag() )                                 \
00187    {                                                           \
00188       std::string adds="";                                     \
00189       if( errno )                                              \
00190       {                                                        \
00191          adds = "Last system error was: ";                     \
00192          adds += strerror(errno);                              \
00193          adds += "\n";                                         \
00194       }                                                        \
00195       gdcmMessageBodyMacro(gdcm::CMD_DEBUG,obj,msg,adds);      \
00196    }                                                           \
00197 }
00198 #define gdcmDebugMacro(msg)                                    \
00199    gdcmDebugBodyMacro(NULL,msg)
00200 #define gdcmStaticDebugMacro(msg)                              \
00201    gdcmDebugBodyMacro(NULL,msg)
00202 #endif //NDEBUG
00203 
00204 // ------------------------------------------------------------------------
00205 
00210 // No NDEBUG test to always have a return of warnings !!!
00211 // -> Rien compris! JPRx
00212 #define gdcmLogBodyMacro(obj, msg)                         \
00213 {                                                              \
00214    if( Debug::GetLogFlag() )                               \
00215       gdcmMessageBodyMacro(gdcm::CMD_LOG,obj,msg,"");      \
00216 }
00217 #define gdcmLogMacro(msg)                                  \
00218    gdcmLogBodyMacro(this,msg)
00219 #define gdcmStaticLogMacro(msg)                            \
00220    gdcmLogBodyMacro(NULL,msg)
00221    
00222 // ------------------------------------------------------------------------
00223 
00228 // No NDEBUG test to always have a return of warnings !!!
00229 // -> Rien compris! JPRx
00230 #define gdcmWarningBodyMacro(obj, msg)                         \
00231 {                                                              \
00232    if( Debug::GetWarningFlag() )                               \
00233       gdcmMessageBodyMacro(gdcm::CMD_WARNING,obj,msg,"");      \
00234 }
00235 #define gdcmWarningMacro(msg)                                  \
00236    gdcmWarningBodyMacro(this,msg)
00237 #define gdcmStaticWarningMacro(msg)                            \
00238    gdcmWarningBodyMacro(NULL,msg)
00239 
00240 // ------------------------------------------------------------------------
00241 
00247 // No NDEBUG test to always have a return of errors !!!
00248 // -> Rien compris! JPRx
00249 #define gdcmErrorBodyMacro(obj, msg)                           \
00250 {                                                              \
00251    gdcmMessageBodyMacro(gdcm::CMD_ERROR,obj,msg,"");           \
00252 }
00253 #define gdcmErrorMacro(msg)                                    \
00254    gdcmErrorBodyMacro(this,msg)
00255 #define gdcmStaticErrorMacro(msg)                              \
00256    gdcmErrorBodyMacro(NULL,msg)
00257 
00258 // ------------------------------------------------------------------------
00259 
00268 // No NDEBUG test to always have a return of asserts !!!
00269 // -> Rien compris! JPRx
00270 #define gdcmAssertBodyMacro(obj, arg)                          \
00271 {                                                              \
00272    if( !(arg) )                                                \
00273    {                                                           \
00274       gdcmMessageBodyMacro(gdcm::CMD_ASSERT,obj,"","");        \
00275       assert ( arg );                                          \
00276    }                                                           \
00277 }
00278 #define gdcmAssertMacro(msg)                                   \
00279    gdcmAssertBodyMacro(NULL,msg)
00280 #define gdcmStaticAssertMacro(msg)                             \
00281    gdcmAssertBodyMacro(NULL,msg)
00282 
00283 //-----------------------------------------------------------------------------
00284 #endif

Generated on Fri Jan 20 10:14:24 2006 for gdcm by  doxygen 1.4.4