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
00059 #define itkNotUsed(x)
00060
00075 #if defined(_MSC_VER) && (_MSC_VER <= 1300)
00076 # define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00077 #endif
00078 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x540)
00079 # define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00080 #endif
00081 #if defined(__SVR4) && !defined(__SUNPRO_CC)
00082 # define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00083 #endif
00084
00085
00086
00087
00088
00089
00090
00091
00092 #if defined(__GNUC__)
00093 # define ITK_NO_SIZEOF_CONSTANT_LOOKUP
00094 #endif
00095
00096 #if defined(_MSC_VER) && (_MSC_VER <= 1300)
00097 #define ITK_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
00098 #endif
00099
00100 #if defined(ITK_NO_INCLASS_MEMBER_INITIALIZATION) || \
00101 defined(ITK_NO_SIZEOF_CONSTANT_LOOKUP)
00102 # define itkStaticConstMacro(name,type,value) enum { name = value }
00103 #else
00104 # define itkStaticConstMacro(name,type,value) static const type name = value
00105 #endif
00106
00107 #ifdef ITK_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
00108 # define itkGetStaticConstMacro(name) name
00109 #else
00110 # define itkGetStaticConstMacro(name) (Self::name)
00111 #endif
00112
00114 #define itkSetInputMacro(name, type, number) \
00115 virtual void Set##name##Input(const type *_arg) \
00116 { \
00117 itkDebugMacro("setting input " #name " to " << _arg); \
00118 if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \
00119 { \
00120 this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \
00121 this->Modified(); \
00122 } \
00123 } \
00124 virtual void SetInput##number(const type *_arg) \
00125 { \
00126 itkDebugMacro("setting input " #number " to " << _arg); \
00127 if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \
00128 { \
00129 this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \
00130 this->Modified(); \
00131 } \
00132 }
00133
00134
00135
00137 #define itkGetInputMacro(name, type, number) \
00138 virtual const type * Get##name##Input() const \
00139 { \
00140 itkDebugMacro("returning input " << #name " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
00141 return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
00142 } \
00143 virtual const type * GetInput##number() const \
00144 { \
00145 itkDebugMacro("returning input " << #number " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
00146 return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
00147 }
00148
00149
00150
00152 #define itkSetMacro(name,type) \
00153 virtual void Set##name (const type _arg) \
00154 { \
00155 itkDebugMacro("setting " #name " to " << _arg); \
00156 if (this->m_##name != _arg) \
00157 { \
00158 this->m_##name = _arg; \
00159 this->Modified(); \
00160 } \
00161 }
00162
00163
00165 #define itkGetMacro(name,type) \
00166 virtual type Get##name () \
00167 { \
00168 itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00169 return this->m_##name; \
00170 }
00171
00172
00176 #define itkGetConstMacro(name,type) \
00177 virtual type Get##name () const \
00178 { \
00179 itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00180 return this->m_##name; \
00181 }
00182
00183
00188 #define itkGetConstReferenceMacro(name,type) \
00189 virtual const type & Get##name () const \
00190 { \
00191 itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00192 return this->m_##name; \
00193 }
00194
00195
00199 #define itkSetStringMacro(name) \
00200 virtual void Set##name (const char* _arg) \
00201 { \
00202 if ( _arg && (_arg == this->m_##name) ) { return;} \
00203 if (_arg) \
00204 { \
00205 this->m_##name = _arg;\
00206 } \
00207 else \
00208 { \
00209 this->m_##name = ""; \
00210 } \
00211 this->Modified(); \
00212 } \
00213 virtual void Set##name (const std::string & _arg) \
00214 { \
00215 this->Set##name( _arg.c_str() ); \
00216 } \
00217
00218
00219
00223 #define itkGetStringMacro(name) \
00224 virtual const char* Get##name () const \
00225 { \
00226 return this->m_##name.c_str(); \
00227 }
00228
00232 #define itkSetClampMacro(name,type,min,max) \
00233 virtual void Set##name (type _arg) \
00234 { \
00235 itkDebugMacro("setting " << #name " to " << _arg ); \
00236 if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
00237 { \
00238 this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
00239 this->Modified(); \
00240 } \
00241 }
00242
00243
00248 #define itkSetObjectMacro(name,type) \
00249 virtual void Set##name (type* _arg) \
00250 { \
00251 itkDebugMacro("setting " << #name " to " << _arg ); \
00252 if (this->m_##name != _arg) \
00253 { \
00254 this->m_##name = _arg; \
00255 this->Modified(); \
00256 } \
00257 }
00258
00259
00262 #define itkGetObjectMacro(name,type) \
00263 virtual type * Get##name () \
00264 { \
00265 itkDebugMacro("returning " #name " address " << this->m_##name ); \
00266 return this->m_##name.GetPointer(); \
00267 }
00268
00269
00274 #define itkSetConstObjectMacro(name,type) \
00275 virtual void Set##name (const type* _arg) \
00276 { \
00277 itkDebugMacro("setting " << #name " to " << _arg ); \
00278 if (this->m_##name != _arg) \
00279 { \
00280 this->m_##name = _arg; \
00281 this->Modified(); \
00282 } \
00283 }
00284
00285
00286
00289 #define itkGetConstObjectMacro(name,type) \
00290 virtual const type * Get##name () const \
00291 { \
00292 itkDebugMacro("returning " #name " address " << this->m_##name ); \
00293 return this->m_##name.GetPointer(); \
00294 }
00295
00296
00299 #define itkGetConstReferenceObjectMacro(name,type) \
00300 virtual const typename type::Pointer & Get##name () const \
00301 { \
00302 itkDebugMacro("returning " #name " address " << this->m_##name ); \
00303 return this->m_##name; \
00304 }
00305
00306
00309 #define itkBooleanMacro(name) \
00310 virtual void name##On () { this->Set##name(true);} \
00311 virtual void name##Off () { this->Set##name(false);}
00312
00313
00317 #define itkSetVectorMacro(name,type,count) \
00318 virtual void Set##name(type data[]) \
00319 { \
00320 unsigned int i; \
00321 for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
00322 if ( i < count ) \
00323 { \
00324 this->Modified(); \
00325 for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
00326 } \
00327 }
00328
00329
00332 #define itkGetVectorMacro(name,type,count) \
00333 virtual type *Get##name () const \
00334 { \
00335 return this->m_##name; \
00336 }
00337
00354 #define itkNewMacro(x) \
00355 static Pointer New(void) \
00356 { \
00357 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
00358 if(smartPtr.GetPointer() == NULL) \
00359 { \
00360 smartPtr = new x; \
00361 } \
00362 smartPtr->UnRegister(); \
00363 return smartPtr; \
00364 } \
00365 virtual ::itk::LightObject::Pointer CreateAnother(void) const \
00366 { \
00367 ::itk::LightObject::Pointer smartPtr; \
00368 smartPtr = x::New().GetPointer(); \
00369 return smartPtr; \
00370 }
00371
00372
00373
00390 #define itkFactorylessNewMacro(x) \
00391 static Pointer New(void) \
00392 { \
00393 Pointer smartPtr; \
00394 x *rawPtr = new x; \
00395 smartPtr = rawPtr; \
00396 rawPtr->UnRegister(); \
00397 return smartPtr; \
00398 } \
00399 virtual LightObject::Pointer CreateAnother(void) const \
00400 { \
00401 LightObject::Pointer smartPtr; \
00402 smartPtr = x::New().GetPointer(); \
00403 return smartPtr; \
00404 }
00405
00406
00409 #define itkTypeMacro(thisClass,superclass) \
00410 virtual const char *GetNameOfClass() const \
00411 {return #thisClass;}
00412
00413
00414 namespace itk
00415 {
00422 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char*);
00423 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char*);
00424 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char*);
00425 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char*);
00426 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char*);
00427 }
00429
00433 #if defined(ITK_LEAN_AND_MEAN) || defined(__BORLANDC__)
00434 #define itkDebugMacro(x)
00435 #else
00436 #define itkDebugMacro(x) \
00437 { if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
00438 { ::itk::OStringStream itkmsg; \
00439 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00440 << this->GetNameOfClass() << " (" << this << "): " x \
00441 << "\n\n"; \
00442 ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str());} \
00443 }
00444 #endif
00445
00446
00447
00451 #ifdef ITK_LEAN_AND_MEAN
00452 #define itkWarningMacro(x)
00453 #else
00454 #define itkWarningMacro(x) \
00455 { if (itk::Object::GetGlobalWarningDisplay()) \
00456 { ::itk::OStringStream itkmsg; \
00457 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00458 << this->GetNameOfClass() << " (" << this << "): " x \
00459 << "\n\n"; \
00460 itk::OutputWindowDisplayWarningText(itkmsg.str().c_str());} \
00461 }
00462 #endif
00463
00464
00465 namespace itk
00466 {
00467
00473 #if !defined(ITK_NO_ANSI_STRING_STREAM)
00474 class OStringStream: public std::ostringstream
00475 {
00476 public:
00477 OStringStream() {}
00478 private:
00479 OStringStream(const OStringStream&);
00480 void operator=(const OStringStream&);
00481 };
00482 #else
00483 namespace OStringStreamDetail
00484 {
00485 class Cleanup
00486 {
00487 public:
00488 Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
00489 ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
00490 static void IgnoreUnusedVariable(const Cleanup&) {}
00491 protected:
00492 std::ostrstream& m_OStrStream;
00493 };
00494 }
00496
00497 class OStringStream: public std::ostrstream
00498 {
00499 public:
00500 typedef std::ostrstream Superclass;
00501 OStringStream() {}
00502 std::string str()
00503 {
00504 OStringStreamDetail::Cleanup cleanup(*this);
00505 OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
00506 int pcount = this->pcount();
00507 const char* ptr = this->Superclass::str();
00508 return std::string(ptr?ptr:"", pcount);
00509 }
00510 private:
00511 OStringStream(const OStringStream&);
00512 void operator=(const OStringStream&);
00513 };
00514 #endif
00515
00516 }
00517
00518 #if defined(ITK_CPP_FUNCTION)
00519 #if defined(__BORLANDC__)
00520 #define ITK_LOCATION __FUNC__
00521 #elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(CABLE_CONFIGURATION) && !defined(CSWIG)
00522 #define ITK_LOCATION __FUNCSIG__
00523 #elif defined(__GNUC__)
00524 #define ITK_LOCATION __PRETTY_FUNCTION__
00525 #else
00526 #define ITK_LOCATION __FUNCTION__
00527 #endif
00528 #else
00529 #define ITK_LOCATION "unknown"
00530 #endif
00531
00532 #include "itkExceptionObject.h"
00533
00537 #define itkExceptionMacro(x) \
00538 { \
00539 ::itk::OStringStream message; \
00540 message << "itk::ERROR: " << this->GetNameOfClass() \
00541 << "(" << this << "): " x; \
00542 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00543 throw e_; \
00544 }
00545
00546
00547 #define itkGenericExceptionMacro(x) \
00548 { \
00549 ::itk::OStringStream message; \
00550 message << "itk::ERROR: " x; \
00551 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00552 throw e_; \
00553 }
00554
00555 #ifdef ITK_LEAN_AND_MEAN
00556 #define itkGenericOutputMacro(x)
00557 #else
00558 #define itkGenericOutputMacro(x) \
00559 { if (::itk::Object::GetGlobalWarningDisplay()) \
00560 { ::itk::OStringStream itkmsg; \
00561 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00562 x << "\n\n"; \
00563 itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str());} \
00564 }
00565 #endif
00566
00567
00568
00569
00570
00571
00572 #define itkLogMacro( x, y) \
00573 { \
00574 if (this->GetLogger() ) \
00575 { \
00576 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
00577 } \
00578 }
00579
00580
00581 #define itkLogMacroStatic( obj, x, y) \
00582 { \
00583 if (obj->GetLogger() ) \
00584 { \
00585 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
00586 } \
00587 }
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598 #if defined(ITK_LEGACY_REMOVE)
00599
00600 # define itkLegacy(method)
00601 #elif defined(ITK_LEGACY_SILENT) || defined(ITK_WRAPPING_CXX)
00602
00603 # define itkLegacy(method) method
00604 #else
00605
00606
00607 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00608 # define itkLegacy(method) method __attribute__((deprecated))
00609 # elif defined(_MSC_VER) && _MSC_VER >= 1300
00610 # define itkLegacy(method) __declspec(deprecated) method
00611 # else
00612 # define itkLegacy(method) method
00613 # endif
00614 #endif
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629 #if defined(ITK_LEGACY_REMOVE) || defined(ITK_LEGACY_SILENT)
00630 # define itkLegacyBody(method, version)
00631 # define itkLegacyReplaceBody(method, version, replace)
00632 #else
00633 # define itkLegacyBody(method, version) \
00634 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00635 # define itkLegacyReplaceBody(method, version, replace) \
00636 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace " instead.")
00637 #endif
00638
00639 #if defined(__INTEL_COMPILER)
00640 # pragma warning (disable: 193)
00641 #endif
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653 #if defined(__sgi) && defined(_COMPILER_VERSION)
00654 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 1
00655 #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
00656 # define ITK_TEMPLATE_EXTERN 1
00657 #elif defined(__GNUC__) && __GNUC__ >= 3
00658 # define ITK_TEMPLATE_EXTERN 1
00659 #elif defined(_MSC_VER) && _MSC_VER >= 1300
00660 # define ITK_TEMPLATE_EXTERN 1
00661 #endif
00662 #if !defined(ITK_TEMPLATE_DO_NOT_INSTANTIATE)
00663 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
00664 #endif
00665 #if !defined(ITK_TEMPLATE_EXTERN)
00666 # define ITK_TEMPLATE_EXTERN 0
00667 #endif
00668
00669
00670
00671
00672
00673
00674
00675
00676 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
00677 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687 #if ITK_TEMPLATE_EXTERN
00688 # define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
00689 # if defined(_MSC_VER)
00690 # pragma warning (disable: 4231)
00691 # endif
00692 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
00693 # define ITK_TEMPLATE_IMPORT_DELAY(x) \
00694 ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
00695 # define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00696 #endif
00697 #if defined(ITK_TEMPLATE_IMPORT_DELAY)
00698 # define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
00699 # define ITK_TEMPLATE_IMPORT_WORKS 1
00700 #else
00701 # define ITK_TEMPLATE_IMPORT(x)
00702 # define ITK_TEMPLATE_IMPORT_WORKS 0
00703 #endif
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \
00762 ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y)
00763 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \
00764 ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y)
00765 #define ITK_EMPTY
00766
00767
00768
00769
00770
00771 #define ITK_TEMPLATE_1(x1) x1
00772 #define ITK_TEMPLATE_2(x1,x2) x1,x2
00773 #define ITK_TEMPLATE_3(x1,x2,x3) x1,x2,x3
00774 #define ITK_TEMPLATE_4(x1,x2,x3,x4) x1,x2,x3,x4
00775 #define ITK_TEMPLATE_5(x1,x2,x3,x4,x5) x1,x2,x3,x4,x5
00776 #define ITK_TEMPLATE_6(x1,x2,x3,x4,x5,x6) x1,x2,x3,x4,x5,x6
00777 #define ITK_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7) x1,x2,x3,x4,x5,x6,x7
00778 #define ITK_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8) x1,x2,x3,x4,x5,x6,x7,x8
00779 #define ITK_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789 #if defined(ITK_MANUAL_INSTANTIATION)
00790 # define ITK_TEMPLATE_TXX 0
00791 #else
00792 # define ITK_TEMPLATE_TXX !(ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE)
00793 #endif
00794
00795
00796
00797
00798
00799
00800 #if ITK_TEMPLATE_CXX
00801 # undef ITK_MANUAL_INSTANTIATION
00802 # define ITK_MANUAL_INSTANTIATION
00803 # if defined(_MSC_VER)
00804 # pragma warning (disable: 4275)
00805 # pragma warning (disable: 4661)
00806 # endif
00807 #endif
00808
00809
00810
00811
00812 #define ITK_EXPORT_ITKCommon(c, x, n) \
00813 ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00814 #define ITK_IMPORT_ITKCommon(c, x, n) \
00815 ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830 #if ITK_TEMPLATE_IMPORT_WORKS && defined(ITK_EXPLICIT_INSTANTIATION)
00831 # define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX
00832 #else
00833 # define ITK_TEMPLATE_EXPLICIT 0
00834 #endif
00835
00836 #endif //end of itkMacro.h
00837