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__) && __GNUC__ < 3
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
00214
00215
00219 #define itkGetStringMacro(name) \
00220 virtual const char* Get##name () const \
00221 { \
00222 return this->m_##name.c_str(); \
00223 }
00224
00228 #define itkSetClampMacro(name,type,min,max) \
00229 virtual void Set##name (type _arg) \
00230 { \
00231 itkDebugMacro("setting " << #name " to " << _arg ); \
00232 if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
00233 { \
00234 this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
00235 this->Modified(); \
00236 } \
00237 }
00238
00239
00244 #define itkSetObjectMacro(name,type) \
00245 virtual void Set##name (type* _arg) \
00246 { \
00247 itkDebugMacro("setting " << #name " to " << _arg ); \
00248 if (this->m_##name != _arg) \
00249 { \
00250 this->m_##name = _arg; \
00251 this->Modified(); \
00252 } \
00253 }
00254
00255
00258 #define itkGetObjectMacro(name,type) \
00259 virtual type * Get##name () \
00260 { \
00261 itkDebugMacro("returning " #name " address " << this->m_##name ); \
00262 return this->m_##name.GetPointer(); \
00263 }
00264
00265
00270 #define itkSetConstObjectMacro(name,type) \
00271 virtual void Set##name (const type* _arg) \
00272 { \
00273 itkDebugMacro("setting " << #name " to " << _arg ); \
00274 if (this->m_##name != _arg) \
00275 { \
00276 this->m_##name = _arg; \
00277 this->Modified(); \
00278 } \
00279 }
00280
00281
00282
00285 #define itkGetConstObjectMacro(name,type) \
00286 virtual const type * Get##name () const \
00287 { \
00288 itkDebugMacro("returning " #name " address " << this->m_##name ); \
00289 return this->m_##name.GetPointer(); \
00290 }
00291
00292
00295 #define itkGetConstReferenceObjectMacro(name,type) \
00296 virtual const typename type::Pointer & Get##name () const \
00297 { \
00298 itkDebugMacro("returning " #name " address " << this->m_##name ); \
00299 return this->m_##name; \
00300 }
00301
00302
00305 #define itkBooleanMacro(name) \
00306 virtual void name##On () { this->Set##name(true);} \
00307 virtual void name##Off () { this->Set##name(false);}
00308
00309
00313 #define itkSetVectorMacro(name,type,count) \
00314 virtual void Set##name(type data[]) \
00315 { \
00316 unsigned int i; \
00317 for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
00318 if ( i < count ) \
00319 { \
00320 this->Modified(); \
00321 for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
00322 } \
00323 }
00324
00325
00328 #define itkGetVectorMacro(name,type,count) \
00329 virtual type *Get##name () const \
00330 { \
00331 return this->m_##name; \
00332 }
00333
00350 #define itkNewMacro(x) \
00351 static Pointer New(void) \
00352 { \
00353 Pointer smartPtr; \
00354 x *rawPtr = ::itk::ObjectFactory<x>::Create(); \
00355 if(rawPtr == NULL) \
00356 { \
00357 rawPtr = new x; \
00358 } \
00359 smartPtr = rawPtr; \
00360 rawPtr->UnRegister(); \
00361 return smartPtr; \
00362 } \
00363 virtual ::itk::LightObject::Pointer CreateAnother(void) const \
00364 { \
00365 ::itk::LightObject::Pointer smartPtr; \
00366 smartPtr = x::New().GetPointer(); \
00367 return smartPtr; \
00368 }
00369
00370
00371
00388 #define itkFactorylessNewMacro(x) \
00389 static Pointer New(void) \
00390 { \
00391 Pointer smartPtr; \
00392 x *rawPtr = new x; \
00393 smartPtr = rawPtr; \
00394 rawPtr->UnRegister(); \
00395 return smartPtr; \
00396 } \
00397 virtual LightObject::Pointer CreateAnother(void) const \
00398 { \
00399 LightObject::Pointer smartPtr; \
00400 smartPtr = x::New().GetPointer(); \
00401 return smartPtr; \
00402 }
00403
00404
00407 #define itkTypeMacro(thisClass,superclass) \
00408 virtual const char *GetNameOfClass() const \
00409 {return #thisClass;}
00410
00411
00412 namespace itk
00413 {
00420 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char*);
00421 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char*);
00422 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char*);
00423 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char*);
00424 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char*);
00425 }
00427
00431 #if defined(ITK_LEAN_AND_MEAN) || defined(__BORLANDC__)
00432 #define itkDebugMacro(x)
00433 #else
00434 #define itkDebugMacro(x) \
00435 { if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
00436 { ::itk::OStringStream itkmsg; \
00437 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00438 << this->GetNameOfClass() << " (" << this << "): " x \
00439 << "\n\n"; \
00440 ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str());} \
00441 }
00442 #endif
00443
00444
00445
00449 #ifdef ITK_LEAN_AND_MEAN
00450 #define itkWarningMacro(x)
00451 #else
00452 #define itkWarningMacro(x) \
00453 { if (itk::Object::GetGlobalWarningDisplay()) \
00454 { ::itk::OStringStream itkmsg; \
00455 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00456 << this->GetNameOfClass() << " (" << this << "): " x \
00457 << "\n\n"; \
00458 itk::OutputWindowDisplayWarningText(itkmsg.str().c_str());} \
00459 }
00460 #endif
00461
00462
00463 namespace itk
00464 {
00465
00471 #if !defined(ITK_NO_ANSI_STRING_STREAM)
00472 class OStringStream: public std::ostringstream
00473 {
00474 public:
00475 OStringStream() {}
00476 private:
00477 OStringStream(const OStringStream&);
00478 void operator=(const OStringStream&);
00479 };
00480 #else
00481 namespace OStringStreamDetail
00482 {
00483 class Cleanup
00484 {
00485 public:
00486 Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
00487 ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
00488 static void IgnoreUnusedVariable(const Cleanup&) {}
00489 protected:
00490 std::ostrstream& m_OStrStream;
00491 };
00492 }
00494
00495 class OStringStream: public std::ostrstream
00496 {
00497 public:
00498 typedef std::ostrstream Superclass;
00499 OStringStream() {}
00500 std::string str()
00501 {
00502 OStringStreamDetail::Cleanup cleanup(*this);
00503 OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
00504 int pcount = this->pcount();
00505 const char* ptr = this->Superclass::str();
00506 return std::string(ptr?ptr:"", pcount);
00507 }
00508 private:
00509 OStringStream(const OStringStream&);
00510 void operator=(const OStringStream&);
00511 };
00512 #endif
00513
00514 }
00515
00516 #if defined(ITK_CPP_FUNCTION)
00517 #if defined(__BORLANDC__)
00518 #define ITK_LOCATION __FUNC__
00519 #elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__)
00520 #define ITK_LOCATION __FUNCSIG__
00521 #elif defined(__GNUC__)
00522 #define ITK_LOCATION __PRETTY_FUNCTION__
00523 #else
00524 #define ITK_LOCATION __FUNCTION__
00525 #endif
00526 #else
00527 #define ITK_LOCATION "unknown"
00528 #endif
00529
00530 #include "itkExceptionObject.h"
00531
00535 #define itkExceptionMacro(x) \
00536 { \
00537 ::itk::OStringStream message; \
00538 message << "itk::ERROR: " << this->GetNameOfClass() \
00539 << "(" << this << "): " x; \
00540 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00541 throw e_; \
00542 }
00543
00544
00545 #define itkGenericExceptionMacro(x) \
00546 { \
00547 ::itk::OStringStream message; \
00548 message << "itk::ERROR: " x; \
00549 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00550 throw e_; \
00551 }
00552
00553 #ifdef ITK_LEAN_AND_MEAN
00554 #define itkGenericOutputMacro(x)
00555 #else
00556 #define itkGenericOutputMacro(x) \
00557 { if (::itk::Object::GetGlobalWarningDisplay()) \
00558 { ::itk::OStringStream itkmsg; \
00559 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00560 x << "\n\n"; \
00561 itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str());} \
00562 }
00563 #endif
00564
00565
00566
00567
00568
00569
00570 #define itkLogMacro( x, y) \
00571 { \
00572 if (this->GetLogger() ) \
00573 { \
00574 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
00575 } \
00576 }
00577
00578
00579 #define itkLogMacroStatic( obj, x, y) \
00580 { \
00581 if (obj->GetLogger() ) \
00582 { \
00583 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
00584 } \
00585 }
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596 #if defined(ITK_LEGACY_REMOVE)
00597
00598 # define itkLegacy(method)
00599 #elif defined(ITK_LEGACY_SILENT) || defined(ITK_WRAPPING_CXX)
00600
00601 # define itkLegacy(method) method
00602 #else
00603
00604
00605 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00606 # define itkLegacy(method) method __attribute__((deprecated))
00607 # elif defined(_MSC_VER) && _MSC_VER >= 1300
00608 # define itkLegacy(method) __declspec(deprecated) method
00609 # else
00610 # define itkLegacy(method) method
00611 # endif
00612 #endif
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627 #if defined(ITK_LEGACY_REMOVE) || defined(ITK_LEGACY_SILENT)
00628 # define itkLegacyBody(method, version)
00629 # define itkLegacyReplaceBody(method, version, replace)
00630 #else
00631 # define itkLegacyBody(method, version) \
00632 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00633 # define itkLegacyReplaceBody(method, version, replace) \
00634 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace " instead.")
00635 #endif
00636
00637 #if defined(__INTEL_COMPILER)
00638 # pragma warning (disable: 193)
00639 #endif
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651 #if defined(__sgi) && defined(_COMPILER_VERSION)
00652 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 1
00653 #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
00654 # define ITK_TEMPLATE_EXTERN 1
00655 #elif defined(__GNUC__) && __GNUC__ >= 3
00656 # define ITK_TEMPLATE_EXTERN 1
00657 #elif defined(_MSC_VER) && _MSC_VER >= 1300
00658 # define ITK_TEMPLATE_EXTERN 1
00659 #endif
00660 #if !defined(ITK_TEMPLATE_DO_NOT_INSTANTIATE)
00661 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
00662 #endif
00663 #if !defined(ITK_TEMPLATE_EXTERN)
00664 # define ITK_TEMPLATE_EXTERN 0
00665 #endif
00666
00667
00668
00669
00670
00671
00672
00673
00674 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
00675 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685 #if ITK_TEMPLATE_EXTERN
00686 # define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
00687 # if defined(_MSC_VER)
00688 # pragma warning (disable: 4231)
00689 # endif
00690 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
00691 # define ITK_TEMPLATE_IMPORT_DELAY(x) \
00692 ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
00693 # define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00694 #endif
00695 #if defined(ITK_TEMPLATE_IMPORT_DELAY)
00696 # define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
00697 # define ITK_TEMPLATE_IMPORT_WORKS 1
00698 #else
00699 # define ITK_TEMPLATE_IMPORT(x)
00700 # define ITK_TEMPLATE_IMPORT_WORKS 0
00701 #endif
00702
00703
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 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \
00760 ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y)
00761 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \
00762 ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y)
00763 #define ITK_EMPTY
00764
00765
00766
00767
00768
00769 #define ITK_TEMPLATE_1(x1) x1
00770 #define ITK_TEMPLATE_2(x1,x2) x1,x2
00771 #define ITK_TEMPLATE_3(x1,x2,x3) x1,x2,x3
00772 #define ITK_TEMPLATE_4(x1,x2,x3,x4) x1,x2,x3,x4
00773 #define ITK_TEMPLATE_5(x1,x2,x3,x4,x5) x1,x2,x3,x4,x5
00774 #define ITK_TEMPLATE_6(x1,x2,x3,x4,x5,x6) x1,x2,x3,x4,x5,x6
00775 #define ITK_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7) x1,x2,x3,x4,x5,x6,x7
00776 #define ITK_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8) x1,x2,x3,x4,x5,x6,x7,x8
00777 #define ITK_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787 #if defined(ITK_MANUAL_INSTANTIATION)
00788 # define ITK_TEMPLATE_TXX 0
00789 #else
00790 # define ITK_TEMPLATE_TXX !(ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE)
00791 #endif
00792
00793
00794
00795
00796
00797
00798 #if ITK_TEMPLATE_CXX
00799 # undef ITK_MANUAL_INSTANTIATION
00800 # define ITK_MANUAL_INSTANTIATION
00801 # if defined(_MSC_VER)
00802 # pragma warning (disable: 4275)
00803 # pragma warning (disable: 4661)
00804 # endif
00805 #endif
00806
00807
00808
00809
00810 #define ITK_EXPORT_ITKCommon(c, x, n) \
00811 ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00812 #define ITK_IMPORT_ITKCommon(c, x, n) \
00813 ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828 #if ITK_TEMPLATE_IMPORT_WORKS && defined(ITK_EXPLICIT_INSTANTIATION)
00829 # define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX
00830 #else
00831 # define ITK_TEMPLATE_EXPLICIT 0
00832 #endif
00833
00834 #endif //end of itkMacro.h
00835