GDCM 3.2.1

gdcmTrace.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: GDCM (Grassroots DICOM). A DICOM library
4
5 Copyright (c) 2006-2011 Mathieu Malaterre
6 All rights reserved.
7 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13=========================================================================*/
14#ifndef GDCMTRACE_H
15#define GDCMTRACE_H
16
17#include "gdcmTypes.h"
18#include "gdcmSystem.h"
19
20#include <iosfwd>
21#include <cassert>
22
23 namespace gdcm
24{
25
41 class GDCM_EXPORT Trace
42{
43public :
44 Trace();
45 ~Trace();
46
49 static void SetStream(std::ostream &os);
50 static std::ostream &GetStream();
51
53 static void SetDebugStream(std::ostream &os);
54 static std::ostream &GetDebugStream();
55
57 static void SetWarningStream(std::ostream &os);
58 static std::ostream &GetWarningStream();
59
61 static void SetErrorStream(std::ostream &os);
62 static std::ostream &GetErrorStream();
63
66 static void SetStreamToFile( const char *filename );
67
69 static void SetDebug(bool debug);
70 static void DebugOn();
71 static void DebugOff();
72 static bool GetDebugFlag();
73
75 static void SetWarning(bool debug);
76 static void WarningOn();
77 static void WarningOff();
78 static bool GetWarningFlag();
79
81 static void SetError(bool debug);
82 static void ErrorOn();
83 static void ErrorOff();
84 static bool GetErrorFlag();
85
86 protected:
87 private:
88};
89
90// Here we define function this is the only way to be able to pass
91// stuff with indirection like:
92// gdcmDebug( "my message:" << i << '\t' );
93// You cannot use function unless you use vnsprintf ...
94
95// __FUNCTION is not always defined by preprocessor
96// In c++ we should use __PRETTY_FUNCTION__ instead...
97#ifdef GDCM_CXX_HAS_FUNCTION
98// Handle particular case for GNU C++ which also defines __PRETTY_FUNCTION__
99// which is a lot nice in C++
100#ifdef __BORLANDC__
101# define __FUNCTION__ __FUNC__
102#endif
103#ifdef __GNUC__
104# define GDCM_FUNCTION __PRETTY_FUNCTION__
105#else
106# define GDCM_FUNCTION __FUNCTION__
107#endif //__GNUC__
108#else
109# define GDCM_FUNCTION "<unknown>"
110#endif //GDCM_CXX_HAS_FUNCTION
111
116#if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
117#define gdcmDebugMacro(msg) GDCM_NOOP_STATEMENT
118#else
119#define gdcmDebugMacro(msg) \
120{ \
121 if( gdcm::Trace::GetDebugFlag() ) \
122 { \
123 std::ostringstream osmacro; \
124 osmacro << "Debug: In " __FILE__ ", line " << __LINE__ \
125 << ", function " << GDCM_FUNCTION << '\n' \
126 << "Last system error was: " \
127 << gdcm::System::GetLastSystemError() << '\n' << msg; \
128 std::ostream &_os = gdcm::Trace::GetDebugStream(); \
129 _os << osmacro.str() << "\n\n" << std::endl; \
130 } \
131} \
132 GDCM_NOOP_STATEMENT
133#endif //NDEBUG
134
139#if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
140#define gdcmWarningMacro(msg) GDCM_NOOP_STATEMENT
141#else
142#define gdcmWarningMacro(msg) \
143{ \
144 if( gdcm::Trace::GetWarningFlag() ) \
145 { \
146 std::ostringstream osmacro; \
147 osmacro << "Warning: In " __FILE__ ", line " << __LINE__ \
148 << ", function " << GDCM_FUNCTION << "\n" \
149 << msg << "\n\n"; \
150 std::ostream &_os = gdcm::Trace::GetWarningStream(); \
151 _os << osmacro.str() << std::endl; \
152 } \
153} \
154 GDCM_NOOP_STATEMENT
155#endif //NDEBUG
156
162#if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
163#define gdcmErrorMacro(msg) GDCM_NOOP_STATEMENT
164#else
165#define gdcmErrorMacro(msg) \
166{ \
167 if( gdcm::Trace::GetErrorFlag() ) \
168 { \
169 std::ostringstream osmacro; \
170 osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
171 << ", function " << GDCM_FUNCTION << '\n' \
172 << msg << "\n\n"; \
173 std::ostream &_os = gdcm::Trace::GetErrorStream(); \
174 _os << osmacro.str() << std::endl; \
175 } \
176} \
177 GDCM_NOOP_STATEMENT
178#endif //NDEBUG
179
186#if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
187#define gdcmAssertMacro(arg) GDCM_NOOP_STATEMENT
188#else
189#define gdcmAssertMacro(arg) \
190{ \
191 if( !(arg) ) \
192 { \
193 std::ostringstream osmacro; \
194 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
195 << ", function " << GDCM_FUNCTION \
196 << "\n\n"; \
197 std::ostream &_os = gdcm::Trace::GetErrorStream(); \
198 _os << osmacro.str() << std::endl; \
199 assert ( arg ); \
200 } \
201} \
202 GDCM_NOOP_STATEMENT
203#endif //NDEBUG
204
211#if defined(NDEBUG)
212// User asked for release compilation, but still need to report
213// if grave issue.
214#define gdcmAssertAlwaysMacro(arg) \
215{ \
216 if( !(arg) ) \
217 { \
218 std::ostringstream osmacro; \
219 osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
220 << ", function " << GDCM_FUNCTION \
221 << "\n\n"; \
222 throw osmacro.str(); \
223 } \
224} \
225 GDCM_NOOP_STATEMENT
226#else
227// Simply reproduce gdcmAssertMacro behavior:
228#define gdcmAssertAlwaysMacro(arg) gdcmAssertMacro(arg)
229#endif //NDEBUG
230
231} // end namespace gdcm
232//-----------------------------------------------------------------------------
233#endif //GDCMTRACE_H
gdcm::Trace::SetError
static void SetError(bool debug)
Turn error messages on (default: true)
gdcm::Trace::ErrorOn
static void ErrorOn()
gdcm::Trace::WarningOff
static void WarningOff()
gdcm::Trace::SetDebug
static void SetDebug(bool debug)
Turn debug messages on (default: false)
gdcm::Trace::SetDebugStream
static void SetDebugStream(std::ostream &os)
Explicitly set the stream which receive Debug messages:
gdcm::Trace::GetErrorStream
static std::ostream & GetErrorStream()
gdcm::Trace::WarningOn
static void WarningOn()
gdcm::Trace::SetStreamToFile
static void SetStreamToFile(const char *filename)
gdcm::Trace::SetWarningStream
static void SetWarningStream(std::ostream &os)
Explicitly set the stream which receive Warning messages:
gdcm::Trace::SetWarning
static void SetWarning(bool debug)
Turn warning messages on (default: true)
gdcm::Trace::ErrorOff
static void ErrorOff()
gdcm::Trace::GetDebugStream
static std::ostream & GetDebugStream()
gdcm::Trace::GetStream
static std::ostream & GetStream()
gdcm::Trace::DebugOn
static void DebugOn()
gdcm::Trace::~Trace
~Trace()
gdcm::Trace::SetStream
static void SetStream(std::ostream &os)
gdcm::Trace::GetDebugFlag
static bool GetDebugFlag()
gdcm::Trace::SetErrorStream
static void SetErrorStream(std::ostream &os)
Explicitly set the stream which receive Error messages:
gdcm::Trace::GetWarningFlag
static bool GetWarningFlag()
gdcm::Trace::Trace
Trace()
gdcm::Trace::DebugOff
static void DebugOff()
gdcm::Trace::GetWarningStream
static std::ostream & GetWarningStream()
gdcm::Trace::GetErrorFlag
static bool GetErrorFlag()
gdcmSystem.h
gdcmTypes.h
GDCM_EXPORT
#define GDCM_EXPORT
Definition gdcmWin32.h:34
gdcm
Definition gdcmASN1.h:21