GDCM  2.4.5
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 
42 {
43 public :
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 "<unknow>"
110 #endif //GDCM_CXX_HAS_FUNCTION
111 
116 #if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
117 #define gdcmDebugMacro(msg) {}
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 #endif //NDEBUG
133 
138 #if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
139 #define gdcmWarningMacro(msg) {}
140 #else
141 #define gdcmWarningMacro(msg) \
142 { \
143  if( gdcm::Trace::GetWarningFlag() ) \
144  { \
145  std::ostringstream osmacro; \
146  osmacro << "Warning: In " __FILE__ ", line " << __LINE__ \
147  << ", function " << GDCM_FUNCTION << "\n" \
148  << msg << "\n\n"; \
149  std::ostream &_os = gdcm::Trace::GetWarningStream(); \
150  _os << osmacro.str() << std::endl; \
151  } \
152 }
153 #endif //NDEBUG
154 
160 #if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
161 #define gdcmErrorMacro(msg) {}
162 #else
163 #define gdcmErrorMacro(msg) \
164 { \
165  if( gdcm::Trace::GetErrorFlag() ) \
166  { \
167  std::ostringstream osmacro; \
168  osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
169  << ", function " << GDCM_FUNCTION << '\n' \
170  << msg << "\n\n"; \
171  std::ostream &_os = gdcm::Trace::GetErrorStream(); \
172  _os << osmacro.str() << std::endl; \
173  } \
174 }
175 #endif //NDEBUG
176 
183 #if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
184 #define gdcmAssertMacro(arg) {}
185 #else
186 #define gdcmAssertMacro(arg) \
187 { \
188  if( !(arg) ) \
189  { \
190  std::ostringstream osmacro; \
191  osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
192  << ", function " << GDCM_FUNCTION \
193  << "\n\n"; \
194  std::ostream &_os = gdcm::Trace::GetErrorStream(); \
195  _os << osmacro.str() << std::endl; \
196  assert ( arg ); \
197  } \
198 }
199 #endif //NDEBUG
200 
207 #if defined(NDEBUG) && !defined(GDCM_ALWAYS_TRACE_MACRO)
208 // User asked for release compilation, but still need to report
209 // if grave issue.
210 #define gdcmAssertAlwaysMacro(arg) \
211 { \
212  if( !(arg) ) \
213  { \
214  std::ostringstream osmacro; \
215  osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
216  << ", function " << GDCM_FUNCTION \
217  << "\n\n"; \
218  throw osmacro.str(); \
219  } \
220 }
221 #else
222 // Simply reproduce gdcmAssertMacro behavior:
223 #define gdcmAssertAlwaysMacro(arg) gdcmAssertMacro(arg)
224 #endif //NDEBUG
225 
226 } // end namespace gdcm
227 //-----------------------------------------------------------------------------
228 #endif //GDCMTRACE_H
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
Trace.
Definition: gdcmTrace.h:41
Definition: gdcmASN1.h:20

Generated on Fri Sep 25 2015 17:58:24 for GDCM by doxygen 1.8.9.1
SourceForge.net Logo