Orfeo Toolbox  4.0
otbMacro.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
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.
16 
17 =========================================================================*/
18 
25 #ifndef __otbMacro_h
26 #define __otbMacro_h
27 
28 #include "itkMacro.h"
29 #include "itkObject.h"
30 #include "otbConfigure.h"
31 
37 namespace otb
38 {
39 } // end namespace otb - this is here for documentation purposes
40 
44 #define otbDebugMacro(x) itkDebugMacro(x)
45 /* { if ( this->GetDebug() && *::itk::Object::GetGlobalWarningDisplay()) \
46  { std::ostringstream itkmsg; \
47  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
48  << this->GetNameOfClass() << " (" << this << "): " x \
49  << "\n\n"; \
50  ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); } \
51 }*/
52 
53 #define otbMsgDebugMacro(x) \
54  { \
55  if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
56  { \
57  std::ostringstream itkmsg; \
58  itkmsg << " Msg Debug: " x << "\n"; \
59  ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
60  } \
61  }
62 
63 
64 #ifndef NDEBUG
65 #define otbGenericMsgDebugMacro(x) \
66  { \
67  if (::itk::Object::GetGlobalWarningDisplay()) \
68  { \
69  std::ostringstream itkmsg; \
70  itkmsg << " Generic Msg Debug: " x << "\n"; \
71  ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
72  } \
73  }
74 #else
75 #define otbGenericMsgDebugMacro(x)
76 #endif
77 
78 #define otbGenericMsgTestingMacro(x) \
79  { \
80  std::cout x << std::endl; \
81  }
82 
83 #ifdef OTB_SHOW_ALL_MSG_DEBUG
84 #define otbMsgDevMacro(x) \
85  { \
86  { \
87  std::ostringstream itkmsg; \
88  itkmsg << " Msg Dev: (" << __FILE__ << ":" << __LINE__ << ") " x << "\n"; \
89  ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
90  } \
91  }
92 #else
93 #define otbMsgDevMacro(x)
94 #endif
95 
99 #define otbWarningMacro(x) \
100  { \
101  if (itk::Object::GetGlobalWarningDisplay()) \
102  { \
103  std::ostringstream itkmsg; \
104  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
105  << this->GetNameOfClass() << " (" << this << "): " x \
106  << "\n\n"; \
107  itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
108  } \
109  }
110 
111 #define otbGenericWarningMacro(x) \
112  { \
113  if (itk::Object::GetGlobalWarningDisplay()) \
114  { \
115  std::ostringstream itkmsg; \
116  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << ": " x <<"\n";\
117  itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
118  } \
119  }
120 
124 #define otbControlConditionTestMacro(condition, message) \
125  { \
126  if ((condition)) itkGenericExceptionMacro(<< message); \
127  }
128 
130 #define otbSetObjectMemberMacro(object, name, type) \
131  virtual void Set ## name (const type _arg) \
132  { \
133  itkDebugMacro("setting member " # name " to " << _arg); \
134  this->m_ ## object->Set ## name(_arg); \
135  this->Modified(); \
136  }
137 
139 #define otbGetObjectMemberMacro(object, name, type) \
140  virtual type Get ## name () \
141  { \
142  itkDebugMacro("returning " << # name " of " << this->m_ ## object->Get ## name()); \
143  return this->m_ ## object->Get ## name(); \
144  }
145 
149 #define otbGetObjectMemberConstMacro(object, name, type) \
150  virtual type Get ## name () const \
151  { \
152  itkDebugMacro("returning " << # name " of " << this->m_ ## object->Get ## name()); \
153  return this->m_ ## object->Get ## name(); \
154  }
155 
160 #define otbGetObjectMemberConstReferenceMacro(object, name, type) \
161  virtual const type &Get ## name () const \
162  { \
163  itkDebugMacro("returning " << # name " of " << this->m_ ## object->Get ## name()); \
164  return this->m_ ## object->Get ## name(); \
165  }
166 
170 #define otbTestingCheckValidCommand(command) \
171  { \
172  try \
173  { \
174  command; \
175  } \
176  catch (const std::exception&) { \
177  throw; } \
178  catch (...) \
179  { \
180  std::ostringstream message; \
181  message << "otb::ERROR Unknow error while running " << # command << " (catch(...) )"; \
182  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
183  throw e_; \
184  } \
185  std::cout << " Checking valid command " << # command " ok." << std::endl; \
186  }
187 
188 #define otbGenericExceptionMacro(T, x) \
189 { \
190  std::ostringstream message; \
191  message << "otb::ERROR: " x; \
192  T e_(__FILE__, __LINE__, message.str(),ITK_LOCATION); \
193  throw e_;\
194 }
195 
196 #define otbTestingCheckNotValidCommand(command) \
197  { \
198  int result(1); \
199  try \
200  { \
201  command; \
202  } \
203  catch (std::bad_alloc& err) { \
204  throw err; } \
205  catch (itk::ExceptionObject&) { std::cout << "Checking not valid Command " << # command " ok." << std::endl; \
206  result = 0; } \
207  catch (const std::exception& stde) { \
208  throw stde; } \
209  catch (...) \
210  { \
211  std::ostringstream message; \
212  message << "otb::ERROR Unknow error while running " << # command << " (catch(...) )"; \
213  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
214  throw e_; \
215  } \
216  if (result == 1) \
217  { \
218  std::ostringstream message; \
219  message << "otb::ERROR: " << # command << " should be throwing an exception."; \
220  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
221  throw e_; \
222  } \
223  }
224 
225 #endif //end of otbMacro.h

Generated at Sat Mar 8 2014 16:06:36 for Orfeo Toolbox with doxygen 1.8.3.1