1 /*=========================================================================
4 Module: $RCSfile: gdcmDebug.h,v $
6 Date: $Date: 2005/01/07 21:09:42 $
7 Version: $Revision: 1.15 $
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...
60 #ifdef GDCM_COMPILER_HAS_FUNCTION
61 // Handle particular case for GNU C++ which also defines __PRETTY_FUNCTION__
62 // which is a lot nice in C++
64 # define GDCM_FUNCTION __PRETTY_FUNCTION__
66 # define GDCM_FUNCTION __FUNCTION__
69 # define GDCM_FUNCTION "<unknow>"
70 #endif //GDCM_COMPILER_HAS_FUNCTION
74 * @param msg message part
76 #define gdcmDebugMacro(msg) \
78 if( gdcm::Debug::GetDebugFlag() ) \
80 std::ostringstream osmacro; \
81 osmacro << "Debug: In " __FILE__ ", line " << __LINE__ \
82 << ", function " << GDCM_FUNCTION << '\n' \
84 std::cerr << osmacro.str() << std::endl; \
90 * @param msg message part
92 #define gdcmVerboseMacro(msg) \
94 if( gdcm::Debug::GetDebugFlag() ) \
96 std::ostringstream osmacro; \
97 osmacro << "Verbose: In " __FILE__ ", line " << __LINE__ \
98 << ", function " << GDCM_FUNCTION << "\n" \
100 std::cerr << osmacro.str() << std::endl; \
106 * @param msg second message part
108 #define gdcmErrorMacro(msg) \
110 if( gdcm::Debug::GetDebugFlag() ) \
112 std::ostringstream osmacro; \
113 osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
114 << ", function " << GDCM_FUNCTION << '\n' \
116 std::cerr << osmacro.str() << std::endl; \
123 * @param arg argument to test
124 * An easy solution to pass also a message is to do:
125 * gdcmAssertMacro( "my message" && 2 < 3 )
127 #define gdcmAssertMacro(arg) \
131 std::ostringstream osmacro; \
132 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
133 << ", function " << GDCM_FUNCTION \
135 std::cerr << osmacro.str() << std::endl; \