1 /*=========================================================================
4 Module: $RCSfile: gdcmDebug.h,v $
6 Date: $Date: 2005/01/12 22:19:23 $
7 Version: $Revision: 1.21 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
22 #include "gdcmCommon.h"
30 //-----------------------------------------------------------------------------
34 * \brief Debug is an object for debugging in program.
35 * It has 2 debugging modes :
36 * - error : for bad library use, seriously wrong DICOM
37 * - debug : for information/debug messages
38 * - warning : for warning about DICOM quality (kosher)
40 * A debugging message is only show if the flag is on (DebugFlag)
41 * This is static var and can be set at begining of code:
42 * gdcm::Debug::SetDebugOn();
44 class GDCM_EXPORT Debug
47 /// This is a global flag that controls whether any debug, warning
48 /// messages are displayed.
49 static int GetDebugFlag ();
50 static void SetDebugFlag (int flag);
51 static void SetDebugOn () { SetDebugFlag(1); };
52 static void SetDebugOff () { SetDebugFlag(0); };
55 } // end namespace gdcm
57 // Here we define function this is the only way to be able to pass
58 // stuff with indirection like:
59 // gdcmDebug( "my message:" << i << '\t' );
60 // You cannot use function unless you use vnsprintf ...
62 // __FUNCTION is not always defined by preprocessor
63 // In c++ we should use __PRETTY_FUNCTION__ instead...
64 #ifdef GDCM_COMPILER_HAS_FUNCTION
65 // Handle particular case for GNU C++ which also defines __PRETTY_FUNCTION__
66 // which is a lot nice in C++
68 # define __FUNCTION__ __FUNC__
71 # define GDCM_FUNCTION __PRETTY_FUNCTION__
73 # define GDCM_FUNCTION __FUNCTION__
76 # define GDCM_FUNCTION "<unknow>"
77 #endif //GDCM_COMPILER_HAS_FUNCTION
81 * @param msg message part
83 #define gdcmDebugMacro(msg) \
85 if( gdcm::Debug::GetDebugFlag() ) \
87 std::ostringstream osmacro; \
88 osmacro << "Debug: In " __FILE__ ", line " << __LINE__ \
89 << ", function " << GDCM_FUNCTION << '\n' \
90 << "Last system error was: " << strerror(errno) \
91 << '\n' << msg << "\n\n"; \
92 std::cerr << osmacro.str() << std::endl; \
98 * @param msg message part
100 #define gdcmVerboseMacro(msg) \
102 if( gdcm::Debug::GetDebugFlag() ) \
104 std::ostringstream osmacro; \
105 osmacro << "Verbose: In " __FILE__ ", line " << __LINE__ \
106 << ", function " << GDCM_FUNCTION << "\n" \
108 std::cerr << osmacro.str() << std::endl; \
114 * @param msg second message part
116 #define gdcmErrorMacro(msg) \
118 if( gdcm::Debug::GetDebugFlag() ) \
120 std::ostringstream osmacro; \
121 osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
122 << ", function " << GDCM_FUNCTION << '\n' \
124 std::cerr << osmacro.str() << std::endl; \
131 * @param arg argument to test
132 * An easy solution to pass also a message is to do:
133 * gdcmAssertMacro( "my message" && 2 < 3 )
135 #define gdcmAssertMacro(arg) \
139 std::ostringstream osmacro; \
140 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
141 << ", function " << GDCM_FUNCTION \
143 std::cerr << osmacro.str() << std::endl; \