GDCM  2.2.0
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 
33 {
34 public :
35  Trace();
36  ~Trace();
37 
39  static void SetStream(std::ostream &os);
40  static std::ostream &GetStream();
41 
42  static void SetDebug(bool debug);
43  static void DebugOn();
44  static void DebugOff();
45  static bool GetDebugFlag();
46 
47  static void SetWarning(bool debug);
48  static void WarningOn();
49  static void WarningOff();
50  static bool GetWarningFlag();
51 
52  static void SetError(bool debug);
53  static void ErrorOn();
54  static void ErrorOff();
55  static bool GetErrorFlag();
56 
57 protected:
58 private:
59 };
60 
61 // Here we define function this is the only way to be able to pass
62 // stuff with indirection like:
63 // gdcmDebug( "my message:" << i << '\t' );
64 // You cannot use function unless you use vnsprintf ...
65 
66 // __FUNCTION is not always defined by preprocessor
67 // In c++ we should use __PRETTY_FUNCTION__ instead...
68 #ifdef GDCM_CXX_HAS_FUNCTION
69 // Handle particular case for GNU C++ which also defines __PRETTY_FUNCTION__
70 // which is a lot nice in C++
71 #ifdef __BORLANDC__
72 # define __FUNCTION__ __FUNC__
73 #endif
74 #ifdef __GNUC__
75 # define GDCM_FUNCTION __PRETTY_FUNCTION__
76 #else
77 # define GDCM_FUNCTION __FUNCTION__
78 #endif //__GNUC__
79 #else
80 # define GDCM_FUNCTION "<unknow>"
81 #endif //GDCM_CXX_HAS_FUNCTION
82 
87 #ifdef NDEBUG
88 #define gdcmDebugMacro(msg) {}
89 #else
90 #define gdcmDebugMacro(msg) \
91 { \
92  if( gdcm::Trace::GetDebugFlag() ) \
93  { \
94  std::ostringstream osmacro; \
95  osmacro << "Debug: In " __FILE__ ", line " << __LINE__ \
96  << ", function " << GDCM_FUNCTION << '\n' \
97  << "Last system error was: " \
98  << gdcm::System::GetLastSystemError() << '\n' << msg; \
99  std::ostream &_os = gdcm::Trace::GetStream(); \
100  _os << osmacro.str() << "\n\n" << std::endl; \
101  } \
102 }
103 #endif //NDEBUG
104 
109 #ifdef NDEBUG
110 #define gdcmWarningMacro(msg) {}
111 #else
112 #define gdcmWarningMacro(msg) \
113 { \
114  if( gdcm::Trace::GetWarningFlag() ) \
115  { \
116  std::ostringstream osmacro; \
117  osmacro << "Warning: In " __FILE__ ", line " << __LINE__ \
118  << ", function " << GDCM_FUNCTION << "\n" \
119  << msg << "\n\n"; \
120  std::ostream &_os = gdcm::Trace::GetStream(); \
121  _os << osmacro.str() << std::endl; \
122  } \
123 }
124 #endif //NDEBUG
125 
131 #ifdef NDEBUG
132 #define gdcmErrorMacro(msg) {}
133 #else
134 #define gdcmErrorMacro(msg) \
135 { \
136  if( gdcm::Trace::GetErrorFlag() ) \
137  { \
138  std::ostringstream osmacro; \
139  osmacro << "Error: In " __FILE__ ", line " << __LINE__ \
140  << ", function " << GDCM_FUNCTION << '\n' \
141  << msg << "\n\n"; \
142  std::ostream &_os = gdcm::Trace::GetStream(); \
143  _os << osmacro.str() << std::endl; \
144  } \
145 }
146 #endif //NDEBUG
147 
154 #ifdef NDEBUG
155 #define gdcmAssertMacro(arg) {}
156 #else
157 #define gdcmAssertMacro(arg) \
158 { \
159  if( !(arg) ) \
160  { \
161  std::ostringstream osmacro; \
162  osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
163  << ", function " << GDCM_FUNCTION \
164  << "\n\n"; \
165  std::ostream &_os = gdcm::Trace::GetStream(); \
166  _os << osmacro.str() << std::endl; \
167  assert ( arg ); \
168  } \
169 }
170 #endif //NDEBUG
171 
178 #ifdef NDEBUG
179 // User asked for release compilation, but still need to report
180 // if grave issue.
181 #define gdcmAssertAlwaysMacro(arg) \
182 { \
183  if( !(arg) ) \
184  { \
185  std::ostringstream osmacro; \
186  osmacro << "Assert: In " __FILE__ ", line " << __LINE__ \
187  << ", function " << GDCM_FUNCTION \
188  << "\n\n"; \
189  throw osmacro.str(); \
190  } \
191 }
192 #else
193 // Simply reproduce gdcmAssertMacro behavior:
194 #define gdcmAssertAlwaysMacro(arg) gdcmAssertMacro(arg)
195 #endif //NDEBUG
196 
197 } // end namespace gdcm
198 //-----------------------------------------------------------------------------
199 #endif //GDCMTRACE_H

Generated on Wed Jun 13 2012 20:40:37 for GDCM by doxygen 1.8.1
SourceForge.net Logo