ITK
4.0.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 /*========================================================================= 00019 * 00020 * Portions of this file are subject to the VTK Toolkit Version 3 copyright. 00021 * 00022 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00023 * 00024 * For complete copyright, license and disclaimer of warranty information 00025 * please refer to the NOTICE file at the top of the ITK source tree. 00026 * 00027 *=========================================================================*/ 00038 #ifndef __itkMacro_h 00039 #define __itkMacro_h 00040 00041 #include "itkWin32Header.h" 00042 #include "itkConfigure.h" 00043 00044 #include <string> 00045 #include <cstdlib> 00046 #ifndef NDEBUG 00047 #include <cassert> 00048 #endif 00049 00050 #include <sstream> 00051 00056 namespace itk 00057 { 00058 // end namespace itk - this is here for documentation purposes 00059 } 00060 00063 #define itkNotUsed(x) 00064 00065 /* 00066 * ITK only supports MSVC++ 7.1 and greater 00067 * MSVC++ 11.0 _MSC_VER = 1700 00068 * MSVC++ 10.0 _MSC_VER = 1600 00069 * MSVC++ 9.0 _MSC_VER = 1500 00070 * MSVC++ 8.0 _MSC_VER = 1400 00071 * MSVC++ 7.1 _MSC_VER = 1310 00072 * MSVC++ 7.0 _MSC_VER = 1300 00073 * MSVC++ 6.0 _MSC_VER = 1200 00074 * MSVC++ 5.0 _MSC_VER = 1100 00075 */ 00076 #if defined( _MSC_VER ) && ( _MSC_VER < 1310 ) 00077 //#error "_MSC_VER < 1310 (MSVC++ 7.1) not supported under ITKv4" 00078 #endif 00079 #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC < 0x590 ) 00080 #error "__SUNPRO_CC < 0x590 not supported under ITKv4" 00081 #endif 00082 #if defined( __CYGWIN__ ) 00083 #error "The Cygwin compiler is not supported in ITKv4 and above" 00084 #endif 00085 #if defined( __BORLANDC__ ) 00086 #error "The Borland C compiler is not supported in ITKv4 and above" 00087 #endif 00088 #if defined( __MWERKS__ ) 00089 #error "The MetroWerks compiler is not supported in ITKv4 and above" 00090 #endif 00091 #if defined( __GNUC__ ) && ( __GNUC__ < 3 ) 00092 #error "The __GNUC__ version 2.95 compiler is not supprted under ITKv4 and above" 00093 #if defined( __sgi ) 00094 //This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m. 00095 //TODO: At some future point, it may be necessary to 00096 //define a minimum __sgi version that will work. 00097 #error "The __sgi compiler is not supprted under ITKv4 and above" 00098 #endif 00099 #endif 00100 00101 // Setup symbol exports 00102 // 00103 // When a class definition has ITK_EXPORT, the class will be 00104 // checked automatically, by Utilities/Dart/PrintSelfCheck.tcl 00105 #define ITK_EXPORT 00106 00107 #if defined( _WIN32 ) || defined ( WIN32 ) 00108 #define ITK_ABI_IMPORT __declspec(dllimport) 00109 #define ITK_ABI_EXPORT __declspec(dllexport) 00110 #define ITK_ABI_HIDDEN 00111 #else 00112 #if __GNUC__ >= 4 00113 #define ITK_ABI_IMPORT __attribute__ ((visibility ("default"))) 00114 #define ITK_ABI_EXPORT __attribute__ ((visibility ("default"))) 00115 #define ITK_ABI_HIDDEN __attribute__ ((visibility ("hidden"))) 00116 #else 00117 #define ITK_ABI_IMPORT 00118 #define ITK_ABI_EXPORT 00119 #define ITK_ABI_HIDDEN 00120 #endif 00121 #endif 00122 00123 #define ITKCommon_HIDDEN ITK_ABI_HIDDEN 00124 00125 #if !defined( ITKSTATIC ) 00126 #ifdef ITKCommon_EXPORTS 00127 #define ITKCommon_EXPORT ITK_ABI_EXPORT 00128 #else 00129 #define ITKCommon_EXPORT ITK_ABI_IMPORT 00130 #endif /* ITKCommon_EXPORTS */ 00131 #else 00132 /* ITKCommon is build as a static lib */ 00133 #if __GNUC__ >= 4 00134 // Don't hide symbols in the static ITKCommon library in case 00135 // -fvisibility=hidden is used 00136 #define ITKCommon_EXPORT ITK_ABI_EXPORT 00137 #else 00138 #define ITKCommon_EXPORT 00139 #endif 00140 #endif 00141 00142 //This is probably better, but requires a lot of extra work 00143 //for gettting ExplicitInstantiation to work properly. \#define 00144 // itkStaticConstMacro(name, type, value) static const type name = value 00145 #define itkStaticConstMacro(name, type, value) enum { name = value } 00146 00147 #define itkGetStaticConstMacro(name) (Self::name) 00148 00150 #define itkSetInputMacro(name, type) \ 00151 virtual void Set##name(const type *_arg) \ 00152 { \ 00153 itkDebugMacro("setting input " #name " to " << _arg); \ 00154 if ( _arg != static_cast< type * >( this->ProcessObject::GetInput(#name) ) ) \ 00155 { \ 00156 this->ProcessObject::SetInput( #name, const_cast< type * >( _arg ) ); \ 00157 this->Modified(); \ 00158 } \ 00159 } 00160 00161 00163 #define itkGetInputMacro(name, type) \ 00164 virtual const type * Get##name() const \ 00165 { \ 00166 itkDebugMacro( "returning input " << #name " of " \ 00167 << static_cast< const type * >( this->ProcessObject::GetInput(#name) ) ); \ 00168 return static_cast< const type * >( this->ProcessObject::GetInput(#name) ); \ 00169 } 00170 00171 00173 #define itkSetDecoratedInputMacro(name, type) \ 00174 virtual void Set##name##Input(const SimpleDataObjectDecorator< type > *_arg) \ 00175 { \ 00176 itkDebugMacro("setting input " #name " to " << _arg); \ 00177 if ( _arg != static_cast< SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \ 00178 { \ 00179 this->ProcessObject::SetInput( #name, const_cast< SimpleDataObjectDecorator< type > * >( _arg ) ); \ 00180 this->Modified(); \ 00181 } \ 00182 } \ 00183 virtual void Set##name(const type &_arg) \ 00184 { \ 00185 typedef SimpleDataObjectDecorator< type > DecoratorType; \ 00186 itkDebugMacro("setting input " #name " to " << _arg); \ 00187 const DecoratorType *oldInput = \ 00188 static_cast< const DecoratorType * >( \ 00189 this->ProcessObject::GetInput(#name) ); \ 00190 if ( oldInput && oldInput->Get() == _arg ) \ 00191 { \ 00192 return; \ 00193 } \ 00194 typename DecoratorType::Pointer newInput = DecoratorType::New(); \ 00195 newInput->Set(_arg); \ 00196 this->Set##name##Input(newInput); \ 00197 } 00198 00199 00201 #define itkGetDecoratedInputMacro(name, type) \ 00202 virtual const SimpleDataObjectDecorator< type > * Get##name##Input() const \ 00203 { \ 00204 itkDebugMacro( "returning input " << #name " of " \ 00205 << static_cast< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ); \ 00206 return static_cast< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \ 00207 } \ 00208 virtual const type & Get##name() const \ 00209 { \ 00210 itkDebugMacro("Getting input " #name); \ 00211 typedef SimpleDataObjectDecorator< type > DecoratorType; \ 00212 const DecoratorType *input = \ 00213 static_cast< const DecoratorType * >( \ 00214 this->ProcessObject::GetInput(#name) ); \ 00215 if( input == NULL ) \ 00216 { \ 00217 itkExceptionMacro(<<"input" #name " is not set"); \ 00218 } \ 00219 return input->Get(); \ 00220 } 00221 00222 00225 #define itkSetGetDecoratedInputMacro(name, type) \ 00226 itkSetDecoratedInputMacro(name, type) \ 00227 itkGetDecoratedInputMacro(name, type) 00228 00233 #define itkSetDecoratedObjectInputMacro(name, type) \ 00234 virtual void Set##name##Input(const DataObjectDecorator< type > *_arg) \ 00235 { \ 00236 itkDebugMacro("setting input " #name " to " << _arg); \ 00237 if ( _arg != static_cast< DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \ 00238 { \ 00239 this->ProcessObject::SetInput( #name, const_cast< DataObjectDecorator< type > * >( _arg ) ); \ 00240 this->Modified(); \ 00241 } \ 00242 } \ 00243 virtual void Set##name(const type * _arg) \ 00244 { \ 00245 typedef DataObjectDecorator< type > DecoratorType; \ 00246 itkDebugMacro("setting input " #name " to " << _arg); \ 00247 const DecoratorType *oldInput = \ 00248 static_cast< const DecoratorType * >( \ 00249 this->ProcessObject::GetInput(#name) ); \ 00250 if ( oldInput && oldInput->Get() == _arg ) \ 00251 { \ 00252 return; \ 00253 } \ 00254 typename DecoratorType::Pointer newInput = DecoratorType::New(); \ 00255 newInput->Set(_arg); \ 00256 this->Set##name##Input(newInput); \ 00257 } 00258 00259 00264 #define itkGetDecoratedObjectInputMacro(name, type) \ 00265 virtual const DataObjectDecorator< type > * Get##name##Input() const \ 00266 { \ 00267 itkDebugMacro( "returning input " << #name " of " \ 00268 << static_cast< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ); \ 00269 return static_cast< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \ 00270 } \ 00271 virtual const type * Get##name() const \ 00272 { \ 00273 itkDebugMacro("Getting input " #name); \ 00274 typedef DataObjectDecorator< type > DecoratorType; \ 00275 const DecoratorType *input = \ 00276 static_cast< const DecoratorType * >( \ 00277 this->ProcessObject::GetInput(#name) ); \ 00278 if( input == NULL ) \ 00279 { \ 00280 itkExceptionMacro(<<"input" #name " is not set"); \ 00281 } \ 00282 return input->Get(); \ 00283 } 00284 00285 00288 #define itkSetGetDecoratedObjectInputMacro(name, type) \ 00289 itkSetDecoratedObjectInputMacro(name, type) \ 00290 itkGetDecoratedObjectInputMacro(name, type) 00291 00293 #define itkSetMacro(name, type) \ 00294 virtual void Set##name (const type _arg) \ 00295 { \ 00296 itkDebugMacro("setting " #name " to " << _arg); \ 00297 if ( this->m_##name != _arg ) \ 00298 { \ 00299 this->m_##name = _arg; \ 00300 this->Modified(); \ 00301 } \ 00302 } 00303 00304 00306 #define itkGetMacro(name, type) \ 00307 virtual type Get##name () \ 00308 { \ 00309 return this->m_##name; \ 00310 } 00311 00312 00316 #define itkGetConstMacro(name, type) \ 00317 virtual type Get##name () const \ 00318 { \ 00319 return this->m_##name; \ 00320 } 00321 00322 00327 #define itkGetConstReferenceMacro(name, type) \ 00328 virtual const type &Get##name () const \ 00329 { \ 00330 return this->m_##name; \ 00331 } 00332 00333 00338 #define itkSetEnumMacro(name, type) \ 00339 virtual void Set##name (const type _arg) \ 00340 { \ 00341 itkDebugMacro( "setting " #name " to " << static_cast< long >( _arg ) ); \ 00342 if ( this->m_##name != _arg ) \ 00343 { \ 00344 this->m_##name = _arg; \ 00345 this->Modified(); \ 00346 } \ 00347 } 00348 00349 00354 #define itkGetEnumMacro(name, type) \ 00355 virtual type Get##name () const \ 00356 { \ 00357 return this->m_##name; \ 00358 } 00359 00360 00364 #define itkSetStringMacro(name) \ 00365 virtual void Set##name (const char *_arg) \ 00366 { \ 00367 if ( _arg && ( _arg == this->m_##name ) ) { return; } \ 00368 if ( _arg ) \ 00369 { \ 00370 this->m_##name = _arg; \ 00371 } \ 00372 else \ 00373 { \ 00374 this->m_##name = ""; \ 00375 } \ 00376 this->Modified(); \ 00377 } \ 00378 virtual void Set##name (const std::string & _arg) \ 00379 { \ 00380 this->Set##name( _arg.c_str() ); \ 00381 } \ 00382 00383 00384 00388 #define itkGetStringMacro(name) \ 00389 virtual const char *Get##name () const \ 00390 { \ 00391 return this->m_##name.c_str(); \ 00392 } 00393 00397 #define itkSetClampMacro(name, type, min, max) \ 00398 virtual void Set##name (type _arg) \ 00399 { \ 00400 itkDebugMacro("setting " << #name " to " << _arg); \ 00401 if ( this->m_##name != ( _arg < min ? min : ( _arg > max ? max : _arg ) ) ) \ 00402 { \ 00403 this->m_##name = ( _arg < min ? min : ( _arg > max ? max : _arg ) ); \ 00404 this->Modified(); \ 00405 } \ 00406 } 00407 00408 00413 #define itkSetObjectMacro(name, type) \ 00414 virtual void Set##name (type * _arg) \ 00415 { \ 00416 itkDebugMacro("setting " << #name " to " << _arg); \ 00417 if ( this->m_##name != _arg ) \ 00418 { \ 00419 this->m_##name = _arg; \ 00420 this->Modified(); \ 00421 } \ 00422 } 00423 00424 00427 #define itkGetObjectMacro(name, type) \ 00428 virtual type * Get##name () \ 00429 { \ 00430 return this->m_##name.GetPointer(); \ 00431 } 00432 00437 #define itkSetConstObjectMacro(name, type) \ 00438 virtual void Set##name (const type * _arg) \ 00439 { \ 00440 itkDebugMacro("setting " << #name " to " << _arg); \ 00441 if ( this->m_##name != _arg ) \ 00442 { \ 00443 this->m_##name = _arg; \ 00444 this->Modified(); \ 00445 } \ 00446 } 00447 00448 00451 #define itkGetConstObjectMacro(name, type) \ 00452 virtual const type * Get##name () const \ 00453 { \ 00454 return this->m_##name.GetPointer(); \ 00455 } 00456 00459 #define itkGetConstReferenceObjectMacro(name, type) \ 00460 virtual const typename type::Pointer & Get##name () const \ 00461 { \ 00462 return this->m_##name; \ 00463 } 00464 00467 #define itkBooleanMacro(name) \ 00468 virtual void name##On () \ 00469 { \ 00470 this->Set##name(true); \ 00471 } \ 00472 virtual void name##Off () \ 00473 { \ 00474 this->Set##name(false); \ 00475 } 00476 00477 00481 #define itkSetVectorMacro(name, type, count) \ 00482 virtual void Set##name(type data[]) \ 00483 { \ 00484 unsigned int i; \ 00485 for ( i = 0; i < count; i++ ) \ 00486 { \ 00487 if ( data[i] != this->m_##name[i] ) \ 00488 { \ 00489 break; \ 00490 } \ 00491 } \ 00492 if ( i < count ) \ 00493 { \ 00494 this->Modified(); \ 00495 for ( i = 0; i < count; i++ ) \ 00496 { \ 00497 this->m_##name[i] = data[i]; \ 00498 } \ 00499 } \ 00500 } 00501 00502 00505 #define itkGetVectorMacro(name, type, count) \ 00506 virtual type * Get##name () const \ 00507 { \ 00508 return this->m_##name; \ 00509 } 00510 00531 #define itkNewMacro(x) \ 00532 itkSimpleNewMacro(x) \ 00533 itkCreateAnotherMacro(x) 00534 00535 #define itkSimpleNewMacro(x) \ 00536 static Pointer New(void) \ 00537 { \ 00538 Pointer smartPtr = ::itk::ObjectFactory< x >::Create(); \ 00539 if ( smartPtr.GetPointer() == NULL ) \ 00540 { \ 00541 smartPtr = new x; \ 00542 } \ 00543 smartPtr->UnRegister(); \ 00544 return smartPtr; \ 00545 } 00546 00547 #define itkCreateAnotherMacro(x) \ 00548 virtual::itk::LightObject::Pointer CreateAnother(void) const \ 00549 { \ 00550 ::itk::LightObject::Pointer smartPtr; \ 00551 smartPtr = x::New().GetPointer(); \ 00552 return smartPtr; \ 00553 } 00554 00571 #define itkFactorylessNewMacro(x) \ 00572 static Pointer New(void) \ 00573 { \ 00574 Pointer smartPtr; \ 00575 x * rawPtr = new x; \ 00576 smartPtr = rawPtr; \ 00577 rawPtr->UnRegister(); \ 00578 return smartPtr; \ 00579 } \ 00580 virtual::itk::LightObject::Pointer CreateAnother(void) const \ 00581 { \ 00582 ::itk::LightObject::Pointer smartPtr; \ 00583 smartPtr = x::New().GetPointer(); \ 00584 return smartPtr; \ 00585 } 00586 00587 00590 #define itkTypeMacro(thisClass, superclass) \ 00591 virtual const char *GetNameOfClass() const \ 00592 { \ 00593 return #thisClass; \ 00594 } 00595 00596 namespace itk 00597 { 00604 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char *); 00606 00607 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char *); 00608 00609 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char *); 00610 00611 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char *); 00612 00613 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char *); 00614 } // end namespace itk 00615 00619 #if defined( NDEBUG ) 00620 #define itkDebugMacro(x) 00621 #define itkDebugStatement(x) 00622 #else 00623 #define itkDebugMacro(x) \ 00624 { \ 00625 if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \ 00626 { \ 00627 std::ostringstream itkmsg; \ 00628 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \ 00629 << this->GetNameOfClass() << " (" << this << "): " x \ 00630 << "\n\n"; \ 00631 ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() ); \ 00632 } \ 00633 } 00634 00635 00636 //The itkDebugStatement is to be used ot protect code that is only 00637 //used in the itkDebugMacro 00638 #define itkDebugStatement(x) x 00639 #endif 00640 00644 #define itkWarningMacro(x) \ 00645 { \ 00646 if ( ::itk::Object::GetGlobalWarningDisplay() ) \ 00647 { \ 00648 std::ostringstream itkmsg; \ 00649 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \ 00650 << this->GetNameOfClass() << " (" << this << "): " x \ 00651 << "\n\n"; \ 00652 ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() ); \ 00653 } \ 00654 } 00655 00656 00657 //The itkDebugStatement is to be used ot protect code that is only 00658 //used in the itkDebugMacro 00659 #define itkWarningStatement(x) x 00660 00661 #if defined( ITK_CPP_FUNCTION ) 00662 #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( CABLE_CONFIGURATION ) \ 00663 && !defined( CSWIG ) 00664 #define ITK_LOCATION __FUNCSIG__ 00665 #elif defined( __GNUC__ ) 00666 #define ITK_LOCATION __PRETTY_FUNCTION__ 00667 #else 00668 #define ITK_LOCATION __FUNCTION__ 00669 #endif 00670 #else 00671 #define ITK_LOCATION "unknown" 00672 #endif 00673 00674 #include "itkExceptionObject.h" 00675 00679 #define itkExceptionMacro(x) \ 00680 { \ 00681 std::ostringstream message; \ 00682 message << "itk::ERROR: " << this->GetNameOfClass() \ 00683 << "(" << this << "): " x; \ 00684 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \ 00685 throw e_; /* Explicit naming to work around Intel compiler bug. */ \ 00686 } 00687 00688 00689 #define itkGenericExceptionMacro(x) \ 00690 { \ 00691 std::ostringstream message; \ 00692 message << "itk::ERROR: " x; \ 00693 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \ 00694 throw e_; /* Explicit naming to work around Intel compiler bug. */ \ 00695 } 00696 00697 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage) \ 00698 namespace itk { \ 00699 class ITK_EXPORT newexcp : public parentexcp \ 00700 { \ 00701 public: \ 00702 newexcp( const char *file, unsigned int lineNumber ) : \ 00703 parentexcp( file, lineNumber ) \ 00704 { \ 00705 this->SetDescription( whatmessage ); \ 00706 } \ 00707 newexcp( const std::string & file, unsigned int lineNumber ) : \ 00708 parentexcp( file, lineNumber ) \ 00709 { \ 00710 this->SetDescription( whatmessage ); \ 00711 } \ 00712 itkTypeMacro(newexcp, parentexcp); \ 00713 }; \ 00714 } 00715 00716 #define itkSpecializedExceptionMacro(exceptiontype) \ 00717 { \ 00718 ::itk::exceptiontype e_(__FILE__, __LINE__); \ 00719 e_.SetLocation(ITK_LOCATION); \ 00720 throw e_; /* Explicit naming to work around Intel compiler bug. */ \ 00721 } 00722 00723 #define itkSpecializedMessageExceptionMacro(exceptiontype,x) \ 00724 { \ 00725 ::itk::exceptiontype e_(__FILE__, __LINE__); \ 00726 std::ostringstream message; \ 00727 message << "itk::ERROR: " x; \ 00728 e_.SetDescription(message.str().c_str()); \ 00729 e_.SetLocation(ITK_LOCATION); \ 00730 throw e_; /* Explicit naming to work around Intel compiler bug. */ \ 00731 } 00732 00733 00734 #define itkGenericOutputMacro(x) \ 00735 { \ 00736 if ( ::itk::Object::GetGlobalWarningDisplay() ) \ 00737 { \ 00738 std::ostringstream itkmsg; \ 00739 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \ 00740 x << "\n\n"; \ 00741 ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \ 00742 } \ 00743 } 00744 00745 //---------------------------------------------------------------------------- 00746 // Macros for simplifying the use of logging 00747 // 00748 #define itkLogMacro(x, y) \ 00749 { \ 00750 if ( this->GetLogger() ) \ 00751 { \ 00752 this->GetLogger()->Write(::itk::LoggerBase::x, y); \ 00753 } \ 00754 } 00755 00756 #define itkLogMacroStatic(obj, x, y) \ 00757 { \ 00758 if ( obj->GetLogger() ) \ 00759 { \ 00760 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \ 00761 } \ 00762 } 00763 00764 //---------------------------------------------------------------------------- 00765 // Setup legacy code policy. 00766 // 00767 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted 00768 // They may be used to completely remove legacy code or silence the 00769 // warnings. The default is to warn about their use. 00770 // 00771 // Source files that test the legacy code may define ITK_LEGACY_TEST 00772 // like this: 00773 // 00774 // #define ITK_LEGACY_TEST 00775 // #include "itkClassWithDeprecatedMethod.h" 00776 // 00777 // in order to silence the warnings for calling deprecated methods. 00778 // No other source files in ITK should call the methods since they are 00779 // provided only for compatibility with older user code. 00780 00781 // Define itkLegacyMacro to mark legacy methods where they are 00782 // declared in their class. Example usage: 00783 // 00784 // // @deprecated Replaced by MyOtherMethod() as of ITK 2.0. 00785 // itkLegacyMacro(void MyMethod()); 00786 #if defined( ITK_LEGACY_REMOVE ) 00787 // Remove legacy methods completely. Put a bogus declaration in 00788 // place to avoid stray semicolons because this is an error for some 00789 // compilers. Using a class forward declaration allows any number 00790 // of repeats in any context without generating unique names. 00791 #define itkLegacyMacro(method) class itkLegacyMethodRemoved /* no ';' */ 00792 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( CSWIG ) 00793 // Provide legacy methods with no warnings. 00794 #define itkLegacyMacro(method) method 00795 #else 00796 // Setup compile-time warnings for uses of deprecated methods if 00797 // possible on this compiler. 00798 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) ) 00799 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) ) 00800 #elif defined( _MSC_VER ) 00801 #define itkLegacyMacro(method) __declspec(deprecated) method 00802 #else 00803 #define itkLegacyMacro(method) method 00804 #endif 00805 #endif 00806 00807 // Macros to create runtime deprecation warning messages in function 00808 // bodies. Example usage: 00809 // 00810 // void itkMyClass::MyOldMethod() 00811 // { 00812 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0); 00813 // } 00814 // 00815 // void itkMyClass::MyMethod() 00816 // { 00817 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0, 00818 // itkMyClass::MyOtherMethod); 00819 // } 00820 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT ) 00821 #define itkLegacyBodyMacro(method, version) 00822 #define itkLegacyReplaceBodyMacro(method, version, replace) 00823 #define itkGenericLegacyBodyMacro(method, version) 00824 #define itkGenericLegacyReplaceBodyMacro(method, version, replace) 00825 #else 00826 #define itkLegacyBodyMacro(method, version) \ 00827 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.") 00828 #define itkLegacyReplaceBodyMacro(method, version, replace) \ 00829 itkWarningMacro( \ 00830 #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \ 00831 " instead.") 00832 #define itkGenericLegacyBodyMacro(method, version) \ 00833 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.") 00834 #define itkGenericLegacyReplaceBodyMacro(method, version, replace) \ 00835 itkGenericOutputMacro( \ 00836 #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \ 00837 " instead.") 00838 #endif 00839 00840 //============================================================================= 00841 /* Define a common way of declaring a templated function as a friend inside a class. 00842 - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T) 00843 00844 The following templated function 00845 00846 template <T> 00847 T add(const T & a, const T & b); 00848 00849 is declared as friend in some compilers as: 00850 00851 class A 00852 { 00853 public: 00854 friend Self add<Self>( const Self & a, const Self & b ); 00855 } 00856 00857 while other compilers will do 00858 00859 class A 00860 { 00861 public: 00862 friend Self add<>( const Self & a, const Self & b ); 00863 } 00864 00865 This characteristic of the compiler is checked by a TRY_COMPILE 00866 command defined in Insight/CMake/itkTestFriendTemplatedFunction.cxx 00867 00868 */ 00869 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_NULL_STRING ) 00870 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) 00871 #else 00872 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_EMPTY_BRACKETS ) 00873 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < > 00874 #else 00875 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_TEMPLATE_ARGUMENTS ) 00876 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < T > 00877 #endif 00878 #endif 00879 #endif 00880 // THIS IS A TEMPORARY PATCH FOR Visual Studio 10. The correct solution must 00881 // be implemented in Insight/CMake/itkTestFriendTemplatedFunction.cxx 00882 #if ( defined ( _MSC_VER ) && ( _MSC_VER >= 1600 ) ) 00883 #ifdef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT 00884 #undef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT 00885 #endif 00886 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) 00887 #endif 00888 00889 //============================================================================= 00890 /* Choose a way to prevent template instantiation on this platform. 00891 - ITK_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to 00892 prevent instantiation 00893 - ITK_TEMPLATE_EXTERN = use extern template to prevent instantiation 00894 00895 Note that VS 6 supports extern template instantiation but it is 00896 hard to block the resulting warning because its stream headers 00897 re-enable it. Therefore we just disable support for now. 00898 */ 00899 #if defined( __INTEL_COMPILER ) && __INTEL_COMPILER >= 700 00900 #define ITK_TEMPLATE_EXTERN 1 00901 #elif defined( __GNUC__ ) && __GNUC__ >= 3 00902 #define ITK_TEMPLATE_EXTERN 1 00903 #elif defined( _MSC_VER ) 00904 #define ITK_TEMPLATE_EXTERN 1 00905 #endif 00906 #if !defined( ITK_TEMPLATE_DO_NOT_INSTANTIATE ) 00907 #define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0 00908 #endif 00909 #if !defined( ITK_TEMPLATE_EXTERN ) 00910 #define ITK_TEMPLATE_EXTERN 0 00911 #endif 00912 00913 /* Define a macro to explicitly instantiate a template. 00914 - ITK_TEMPLATE_EXPORT(X) = 00915 Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]). 00916 examples: ITK_TEMPLATE_EXPORT(1(class Foo<int>)) 00917 ITK_TEMPLATE_EXPORT(2(class Bar<int, char>)) 00918 Use one level of expansion delay to allow user code to have 00919 a macro determining the number of arguments. */ 00920 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x) 00921 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x; 00922 00923 /* Define a macro to prevent template instantiations. 00924 - ITK_TEMPLATE_IMPORT(X) = 00925 Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]). 00926 examples: ITK_TEMPLATE_IMPORT(1(class Foo<int>)) 00927 ITK_TEMPLATE_IMPORT(2(class Bar<int, char>)) 00928 Use one level of expansion delay to allow user code to have 00929 a macro determining the number of arguments. 00930 */ 00931 #if ITK_TEMPLATE_EXTERN 00932 #define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x; 00933 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE 00934 #define ITK_TEMPLATE_IMPORT_DELAY(x) \ 00935 ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x) 00936 #define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x) 00937 #endif 00938 #if defined( ITK_TEMPLATE_IMPORT_DELAY ) 00939 #define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x) 00940 #define ITK_TEMPLATE_IMPORT_WORKS 1 00941 #else 00942 #define ITK_TEMPLATE_IMPORT(x) 00943 #define ITK_TEMPLATE_IMPORT_WORKS 0 00944 #endif 00945 01011 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \ 01012 ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y) 01013 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \ 01014 ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y) 01015 #define ITK_EMPTY 01016 01017 /* Define macros to support passing a variable number of arguments 01018 throug other macros. This is used by ITK_TEMPLATE_EXPORT, 01019 ITK_TEMPLATE_IMPORT, and by each template's instantiation 01020 macro. */ 01021 #define ITK_TEMPLATE_1(x1) x1 01022 #define ITK_TEMPLATE_2(x1, x2) x1, x2 01023 #define ITK_TEMPLATE_3(x1, x2, x3) x1, x2, x3 01024 #define ITK_TEMPLATE_4(x1, x2, x3, x4) x1, x2, x3, x4 01025 #define ITK_TEMPLATE_5(x1, x2, x3, x4, x5) x1, x2, x3, x4, x5 01026 #define ITK_TEMPLATE_6(x1, x2, x3, x4, x5, x6) x1, x2, x3, x4, x5, x6 01027 #define ITK_TEMPLATE_7(x1, x2, x3, x4, x5, x6, x7) x1, x2, x3, x4, x5, x6, x7 01028 #define ITK_TEMPLATE_8(x1, x2, x3, x4, x5, x6, x7, x8) x1, x2, x3, x4, x5, x6, x7, x8 01029 #define ITK_TEMPLATE_9(x1, x2, x3, x4, x5, x6, x7, x8, x9) x1, x2, x3, x4, x5, x6, x7, x8, x9 01030 01031 /* In order to support both implicit and explicit instantation a .h 01032 file needs to know whether it should include its .hxx file 01033 containing the template definitions. Define a macro to tell 01034 it. Typical usage in itkFoo.h: 01035 #if ITK_TEMPLATE_TXX 01036 #include "itkFoo.hxx" 01037 #endif 01038 */ 01039 #ifndef ITK_TEMPLATE_CXX //At this point this variable MUST be defined 01040 #define ITK_TEMPLATE_CXX 0 01041 #endif 01042 #ifndef ITK_TEMPLATE_TYPE 01043 #define ITK_TEMPLATE_TYPE 0 01044 #endif 01045 #if defined( ITK_MANUAL_INSTANTIATION ) 01046 #define ITK_TEMPLATE_TXX 0 01047 #else 01048 #define ITK_TEMPLATE_TXX !( ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE ) 01049 #endif 01050 01051 /* All explicit instantiation source files define ITK_TEMPLATE_CXX. 01052 Define ITK_MANUAL_INSTANTIATION to tell .h files that have not been 01053 converted to this explicit instantiation scheme to not include 01054 their .hxx files. Also disable warnings that commonly occur in 01055 these files but are not useful. */ 01056 #if ITK_TEMPLATE_CXX 01057 #undef ITK_MANUAL_INSTANTIATION 01058 #define ITK_MANUAL_INSTANTIATION 01059 #endif 01060 //============================================================================= 01061 01062 /* Define macros to export and import template instantiations for each 01063 library in ITK. */ 01064 #define ITK_EXPORT_ITKCommon(c, x, n) \ 01065 ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n) 01066 #define ITK_IMPORT_ITKCommon(c, x, n) \ 01067 ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n) 01068 01069 /* Define a macro to decide whether to block instantiation of ITK 01070 templates. They should be blocked only if the platform supports 01071 blocking template instantiation and the explicit instantiations are 01072 available. 01073 01074 - ITK_TEMPLATE_EXPLICIT = 01075 Whether to include "XXX+-.h" from "XXX.h" to prevent implicit 01076 instantiations of templates explicitly instantiated elsewhere. 01077 Typical usage in itkFoo.h: 01078 #if ITK_TEMPLATE_EXPLICIT 01079 #include "itkFoo+-.h" 01080 #endif 01081 */ 01082 #if ITK_TEMPLATE_IMPORT_WORKS && defined( ITK_EXPLICIT_INSTANTIATION ) 01083 #define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX 01084 #else 01085 #define ITK_TEMPLATE_EXPLICIT 0 01086 #endif 01087 01088 //-------------------------------------------------------------------------------- 01089 // Helper macros for Template Meta-Programming techniques of for-loops 01090 // unrolling 01091 //-------------------------------------------------------------------------------- 01092 01093 //-------------------------------------------------------------------------------- 01094 // Macro that generates an unrolled for loop for assigning elements of one array 01095 // to elements of another array The array are assumed to be of same length 01096 // (dimension), and this is also assumed to be the value of NumberOfIterations. 01097 // No verification of size is performed. Casting is perfomed as part of the 01098 // assignment, by using the DestinationElementType as the casting type. 01099 // Source and destination array types must have defined opearator[] in their 01100 // API. 01101 #define itkForLoopAssignmentMacro(DestinationType, \ 01102 SourceType, \ 01103 DestinationElementType, \ 01104 DestinationArray, \ 01105 SourceArray, \ 01106 NumberOfIterations) \ 01107 for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \ 01108 { \ 01109 DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \ 01110 } 01111 01112 //-------------------------------------------------------------------------------- 01113 // Macro that generates an unrolled for loop for rounding and assigning 01114 // elements of one array to elements of another array The array are assumed to 01115 // be of same length (dimension), and this is also assumed to be the value of 01116 // NumberOfIterations. No verification of size is performed. Casting is 01117 // perfomed as part of the assignment, by using the DestinationElementType as 01118 // the casting type. 01119 // Source and destination array types must have defined opearator[] in their 01120 // API. 01121 #define itkForLoopRoundingAndAssignmentMacro(DestinationType, \ 01122 Sourcrnd_halfintup, \ 01123 DestinationElementType, \ 01124 DestinationArray, \ 01125 SourceArray, \ 01126 NumberOfIterations) \ 01127 for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \ 01128 { \ 01129 DestinationArray[i] = itk::Math::Round< DestinationElementType >(SourceArray[i]); \ 01130 } 01131 01132 // end of Template Meta Programming helper macros 01133 01134 #ifndef NDEBUG 01135 01136 #ifdef _POSIX_SOURCE 01137 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION); 01138 #else 01139 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg); 01140 #endif 01141 01142 #else 01143 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg); 01144 #endif 01145 01146 #define itkAssertOrThrowMacro(test, message) \ 01147 if ( !( test ) ) \ 01148 { \ 01149 std::ostringstream msgstr; \ 01150 msgstr << message; \ 01151 itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \ 01152 } 01153 01154 #ifndef NDEBUG 01155 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X) 01156 #else 01157 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) 01158 #endif 01159 01160 #ifdef ITKV3_COMPATIBILITY 01161 // As of MSVS++ 7.1 and greater, typename is supported in templates 01162 // All ITKv4 compilers support the typename keyword, but this is 01163 // needed to ease transition from ITKv3. 01164 #define ITK_TYPENAME typename 01165 #endif 01166 01167 01168 #endif //end of itkMacro.h 01169