00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00030 #ifndef __itkMacro_h
00031 #define __itkMacro_h
00032
00033 #include "itkWin32Header.h"
00034 #include "itkConfigure.h"
00035
00036 #include <string>
00037
00038
00039 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
00040 # include <sstream>
00041 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
00042 # include <strstream>
00043 # define ITK_NO_ANSI_STRING_STREAM
00044 #else
00045 # include <strstream.h>
00046 # define ITK_NO_ANSI_STRING_STREAM
00047 #endif
00048
00053 namespace itk
00054 {
00055 }
00056
00057
00058
00059
00060 #include "itkExceptionObject.h"
00061
00064 #define itkNotUsed(x)
00065
00080 #if defined(_MSC_VER) && (_MSC_VER <= 1300)
00081 # define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00082 #endif
00083 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x540)
00084 # define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00085 #endif
00086 #if defined(__SVR4) && !defined(__SUNPRO_CC)
00087 # define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00088 #endif
00089
00090 #if defined(_MSC_VER) && (_MSC_VER <= 1300)
00091 #define ITK_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
00092 #endif
00093
00094 #ifdef ITK_NO_INCLASS_MEMBER_INITIALIZATION
00095 # define itkStaticConstMacro(name,type,value) enum { name = value }
00096 #else
00097 # define itkStaticConstMacro(name,type,value) static const type name = value
00098 #endif
00099
00100 #ifdef ITK_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
00101 # define itkGetStaticConstMacro(name) name
00102 #else
00103 # define itkGetStaticConstMacro(name) (Self::name)
00104 #endif
00105
00106
00108 #define itkSetMacro(name,type) \
00109 virtual void Set##name (const type _arg) \
00110 { \
00111 itkDebugMacro("setting " #name " to " << _arg); \
00112 if (this->m_##name != _arg) \
00113 { \
00114 this->m_##name = _arg; \
00115 this->Modified(); \
00116 } \
00117 }
00118
00120 #define itkGetMacro(name,type) \
00121 virtual type Get##name () \
00122 { \
00123 itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00124 return this->m_##name; \
00125 }
00126
00130 #define itkGetConstMacro(name,type) \
00131 virtual type Get##name () const \
00132 { \
00133 itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00134 return this->m_##name; \
00135 }
00136
00141 #define itkGetConstReferenceMacro(name,type) \
00142 virtual const type & Get##name () const \
00143 { \
00144 itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00145 return this->m_##name; \
00146 }
00147
00151 #define itkSetStringMacro(name) \
00152 virtual void Set##name (const char* _arg) \
00153 { \
00154 if ( _arg && (_arg == this->m_##name) ) { return;} \
00155 if (_arg) \
00156 { \
00157 this->m_##name = _arg;\
00158 } \
00159 else \
00160 { \
00161 this->m_##name = ""; \
00162 } \
00163 this->Modified(); \
00164 }
00165
00166
00170 #define itkGetStringMacro(name) \
00171 virtual const char* Get##name () const \
00172 { \
00173 return this->m_##name.c_str(); \
00174 }
00175
00179 #define itkSetClampMacro(name,type,min,max) \
00180 virtual void Set##name (type _arg) \
00181 { \
00182 itkDebugMacro("setting " << #name " to " << _arg ); \
00183 if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
00184 { \
00185 this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
00186 this->Modified(); \
00187 } \
00188 }
00189
00194 #define itkSetObjectMacro(name,type) \
00195 virtual void Set##name (type* _arg) \
00196 { \
00197 itkDebugMacro("setting " << #name " to " << _arg ); \
00198 if (this->m_##name != _arg) \
00199 { \
00200 this->m_##name = _arg; \
00201 this->Modified(); \
00202 } \
00203 }
00204
00207 #define itkGetObjectMacro(name,type) \
00208 virtual type * Get##name () \
00209 { \
00210 itkDebugMacro("returning " #name " address " << this->m_##name ); \
00211 return this->m_##name.GetPointer(); \
00212 }
00213
00218 #define itkSetConstObjectMacro(name,type) \
00219 virtual void Set##name (const type* _arg) \
00220 { \
00221 itkDebugMacro("setting " << #name " to " << _arg ); \
00222 if (this->m_##name != _arg) \
00223 { \
00224 this->m_##name = _arg; \
00225 this->Modified(); \
00226 } \
00227 }
00228
00229
00232 #define itkGetConstObjectMacro(name,type) \
00233 virtual const type * Get##name () const \
00234 { \
00235 itkDebugMacro("returning " #name " address " << this->m_##name ); \
00236 return this->m_##name.GetPointer(); \
00237 }
00238
00241 #define itkGetConstReferenceObjectMacro(name,type) \
00242 virtual const typename type::Pointer & Get##name () const \
00243 { \
00244 itkDebugMacro("returning " #name " address " << this->m_##name ); \
00245 return this->m_##name; \
00246 }
00247
00250 #define itkBooleanMacro(name) \
00251 virtual void name##On () { this->Set##name(true);} \
00252 virtual void name##Off () { this->Set##name(false);}
00253
00257 #define itkSetVectorMacro(name,type,count) \
00258 virtual void Set##name(type data[]) \
00259 { \
00260 unsigned int i; \
00261 for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
00262 if ( i < count ) \
00263 { \
00264 this->Modified(); \
00265 for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
00266 } \
00267 }
00268
00271 #define itkGetVectorMacro(name,type,count) \
00272 virtual type *Get##name () const \
00273 { \
00274 return this->m_##name; \
00275 }
00276
00288 #define itkNewMacro(x) \
00289 static Pointer New(void) \
00290 { \
00291 Pointer smartPtr; \
00292 x *rawPtr = ::itk::ObjectFactory<x>::Create(); \
00293 if(rawPtr == NULL) \
00294 { \
00295 rawPtr = new x; \
00296 } \
00297 smartPtr = rawPtr; \
00298 rawPtr->UnRegister(); \
00299 return smartPtr; \
00300 }
00301
00308 #define itkFactorylessNewMacro(x) \
00309 static Pointer New(void) \
00310 { \
00311 Pointer smartPtr; \
00312 x *rawPtr = new x; \
00313 smartPtr = rawPtr; \
00314 rawPtr->UnRegister(); \
00315 return smartPtr; \
00316 }
00317
00320 #define itkTypeMacro(thisClass,superclass) \
00321 virtual const char *GetNameOfClass() const \
00322 {return #thisClass;}
00323
00324
00325 namespace itk
00326 {
00333 extern ITK_EXPORT void OutputWindowDisplayText(const char*);
00334 extern ITK_EXPORT void OutputWindowDisplayErrorText(const char*);
00335 extern ITK_EXPORT void OutputWindowDisplayWarningText(const char*);
00336 extern ITK_EXPORT void OutputWindowDisplayGenericOutputText(const char*);
00337 extern ITK_EXPORT void OutputWindowDisplayDebugText(const char*);
00338 }
00339
00343 #ifdef ITK_LEAN_AND_MEAN
00344 #define itkDebugMacro(x)
00345 #else
00346 #define itkDebugMacro(x) \
00347 { if (this->GetDebug() && itk::Object::GetGlobalWarningDisplay()) \
00348 { ::itk::OStringStream itkmsg; \
00349 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00350 << this->GetNameOfClass() << " (" << this << "): " x \
00351 << "\n\n"; \
00352 ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str());} \
00353 }
00354 #endif
00355
00356
00360 #ifdef ITK_LEAN_AND_MEAN
00361 #define itkWarningMacro(x)
00362 #else
00363 #define itkWarningMacro(x) \
00364 { if (itk::Object::GetGlobalWarningDisplay()) \
00365 { ::itk::OStringStream itkmsg; \
00366 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00367 << this->GetNameOfClass() << " (" << this << "): " x \
00368 << "\n\n"; \
00369 itk::OutputWindowDisplayWarningText(itkmsg.str().c_str());} \
00370 }
00371 #endif
00372
00373 namespace itk
00374 {
00375
00381 #if !defined(ITK_NO_ANSI_STRING_STREAM)
00382 class OStringStream: public std::ostringstream
00383 {
00384 public:
00385 OStringStream() {}
00386 private:
00387 OStringStream(const OStringStream&);
00388 void operator=(const OStringStream&);
00389 };
00390 #else
00391 namespace OStringStreamDetail
00392 {
00393 class Cleanup
00394 {
00395 public:
00396 Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
00397 ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
00398 static void IgnoreUnusedVariable(const Cleanup&) {}
00399 protected:
00400 std::ostrstream& m_OStrStream;
00401 };
00402 }
00403
00404 class OStringStream: public std::ostrstream
00405 {
00406 public:
00407 typedef std::ostrstream Superclass;
00408 OStringStream() {}
00409 std::string str()
00410 {
00411 OStringStreamDetail::Cleanup cleanup(*this);
00412 OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
00413 int pcount = this->pcount();
00414 const char* ptr = this->Superclass::str();
00415 return std::string(ptr?ptr:"", pcount);
00416 }
00417 private:
00418 OStringStream(const OStringStream&);
00419 void operator=(const OStringStream&);
00420 };
00421 #endif
00422
00423 }
00424
00428 #define itkExceptionMacro(x) \
00429 { \
00430 ::itk::OStringStream message; \
00431 message << "itk::ERROR: " << this->GetNameOfClass() \
00432 << "(" << this << "): " x; \
00433 throw ::itk::ExceptionObject(__FILE__, __LINE__, message.str().c_str()); \
00434 }
00435
00436 #define itkGenericExceptionMacro(x) \
00437 { \
00438 ::itk::OStringStream message; \
00439 message << "itk::ERROR: " x; \
00440 throw ::itk::ExceptionObject(__FILE__, __LINE__, message.str().c_str()); \
00441 }
00442
00443 #ifdef ITK_LEAN_AND_MEAN
00444 #define itkGenericOutputMacro(x)
00445 #else
00446 #define itkGenericOutputMacro(x) \
00447 { if (::itk::Object::GetGlobalWarningDisplay()) \
00448 { ::itk::OStringStream itkmsg; \
00449 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00450 x << "\n\n"; \
00451 itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str());} \
00452 }
00453 #endif
00454
00455
00456 #endif //end of itkMacro.h
00457
00458