1 /*=========================================================================
4 Module: $RCSfile: gdcmDebug.h,v $
6 Date: $Date: 2005/01/07 20:31:36 $
7 Version: $Revision: 1.14 $
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"
26 //-----------------------------------------------------------------------------
30 * \brief Debug is an object for debugging in program.
31 * It has 2 debugging modes :
32 * - error : for bad library use, seriously wrong DICOM
33 * - debug : for information/debug messages
34 * - warning : for warning about DICOM quality (kosher)
36 * A debugging message is only show if the flag is on (DebugFlag)
37 * This is static var and can be set at begining of code:
38 * gdcm::Debug::SetDebugOn();
40 class GDCM_EXPORT Debug
43 /// This is a global flag that controls whether any debug, warning
44 /// messages are displayed.
45 static int GetDebugFlag ();
46 static void SetDebugFlag (int flag);
47 static void SetDebugOn () { SetDebugFlag(1); };
48 static void SetDebugOff () { SetDebugFlag(0); };
51 } // end namespace gdcm
53 // Here we define function this is the only way to be able to pass
54 // stuff with indirection like:
55 // gdcmDebug( "my message:" << i << '\t' );
56 // You cannot use function unless you use vnsprintf ...
58 // __FUNCTION is not always defined by preprocessor
59 // In c++ we should use __PRETTY_FUNCTION__ instead...
61 # define __FUNCTION__ "<unknow>"
66 * @param msg message part
68 #define gdcmDebugMacro(msg) \
70 if( gdcm::Debug::GetDebugFlag() ) \
72 std::ostringstream osmacro; \
73 osmacro << "Debug: In " __FILE__ ", line " << __LINE__ \
74 << ", function " << __FUNCTION__ << '\n' \
76 std::cerr << osmacro.str() << std::endl; \
82 * @param msg message part
84 #define gdcmVerboseMacro(msg) \
86 if( gdcm::Debug::GetDebugFlag() ) \
88 std::ostringstream osmacro; \
89 osmacro << "Verbose: In " __FILE__ ", line " << __LINE__ \
90 << ", function " << __FUNCTION__ << "\n" \
92 std::cerr << osmacro.str() << std::endl; \
98 * @param msg second message part
100 #define gdcmErrorMacro(msg) \
102 if( gdcm::Debug::GetDebugFlag() ) \
104 std::ostringstream osmacro; \
105 osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
106 << ", function " << __FUNCTION__ << '\n' \
108 std::cerr << osmacro.str() << std::endl; \
115 * @param arg argument to test
116 * An easy solution to pass also a message is to do:
117 * gdcmAssertMacro( "my message" && 2 < 3 )
119 #define gdcmAssertMacro(arg) \
123 std::ostringstream osmacro; \
124 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
125 << ", function " << __FUNCTION__ \
127 std::cerr << osmacro.str() << std::endl; \