1 /*=========================================================================
4 Module: $RCSfile: gdcmDebug.h,v $
6 Date: $Date: 2005/01/11 17:54:10 $
7 Version: $Revision: 1.19 $
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"
29 //-----------------------------------------------------------------------------
33 * \brief Debug is an object for debugging in program.
34 * It has 2 debugging modes :
35 * - error : for bad library use, seriously wrong DICOM
36 * - debug : for information/debug messages
37 * - warning : for warning about DICOM quality (kosher)
39 * A debugging message is only show if the flag is on (DebugFlag)
40 * This is static var and can be set at begining of code:
41 * gdcm::Debug::SetDebugOn();
43 class GDCM_EXPORT Debug
46 /// This is a global flag that controls whether any debug, warning
47 /// messages are displayed.
48 static int GetDebugFlag ();
49 static void SetDebugFlag (int flag);
50 static void SetDebugOn () { SetDebugFlag(1); };
51 static void SetDebugOff () { SetDebugFlag(0); };
54 } // end namespace gdcm
56 // Here we define function this is the only way to be able to pass
57 // stuff with indirection like:
58 // gdcmDebug( "my message:" << i << '\t' );
59 // You cannot use function unless you use vnsprintf ...
61 // __FUNCTION is not always defined by preprocessor
62 // In c++ we should use __PRETTY_FUNCTION__ instead...
63 #ifdef GDCM_COMPILER_HAS_FUNCTION
64 // Handle particular case for GNU C++ which also defines __PRETTY_FUNCTION__
65 // which is a lot nice in C++
67 # define __FUNCTION__ __FUNC__
70 # define GDCM_FUNCTION __PRETTY_FUNCTION__
72 # define GDCM_FUNCTION __FUNCTION__
75 # define GDCM_FUNCTION "<unknow>"
76 #endif //GDCM_COMPILER_HAS_FUNCTION
80 * @param msg message part
82 #define gdcmDebugMacro(msg) \
84 if( gdcm::Debug::GetDebugFlag() ) \
86 std::ostringstream osmacro; \
87 osmacro << "Debug: In " __FILE__ ", line " << __LINE__ \
88 << ", function " << GDCM_FUNCTION << '\n' \
90 std::cerr << osmacro.str() << std::endl; \
96 * @param msg message part
98 #define gdcmVerboseMacro(msg) \
100 if( gdcm::Debug::GetDebugFlag() ) \
102 std::ostringstream osmacro; \
103 osmacro << "Verbose: In " __FILE__ ", line " << __LINE__ \
104 << ", function " << GDCM_FUNCTION << "\n" \
106 std::cerr << osmacro.str() << std::endl; \
112 * @param msg second message part
114 #define gdcmErrorMacro(msg) \
116 if( gdcm::Debug::GetDebugFlag() ) \
118 std::ostringstream osmacro; \
119 osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
120 << ", function " << GDCM_FUNCTION << '\n' \
122 std::cerr << osmacro.str() << std::endl; \
129 * @param arg argument to test
130 * An easy solution to pass also a message is to do:
131 * gdcmAssertMacro( "my message" && 2 < 3 )
133 #define gdcmAssertMacro(arg) \
137 std::ostringstream osmacro; \
138 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
139 << ", function " << GDCM_FUNCTION \
141 std::cerr << osmacro.str() << std::endl; \