Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkMacro.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMacro.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007-12-28 18:28:29 $
00007   Version:   $Revision: 1.83 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012   Portions of this code are covered under the VTK copyright.
00013   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
00014 
00015      This software is distributed WITHOUT ANY WARRANTY; without even 
00016      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00017      PURPOSE.  See the above copyright notices for more information.
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 // Determine type of string stream to use.
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 } // end namespace itk - this is here for documentation purposes
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 // A class template like this will not instantiate on GCC 2.95:
00086 //   template<class T> struct A
00087 //   {
00088 //     static const int N = 1;
00089 //     enum { S = sizeof(A::N) };
00090 //   };
00091 // We need to use enum for static constants instead.
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 
00136 #define itkSuperclassTraitMacro(traitnameType) \
00137   typedef typename Superclass::traitnameType traitnameType;
00138 
00140 #define itkGetInputMacro(name, type, number) \
00141   virtual const type * Get##name##Input() const \
00142   { \
00143     itkDebugMacro("returning input " << #name " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
00144     return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
00145   } \
00146   virtual const type * GetInput##number() const \
00147   { \
00148     itkDebugMacro("returning input " << #number " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
00149     return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
00150   } 
00151 
00152 
00155 #define itkSetDecoratedInputMacro(name, type, number) \
00156   itkSetInputMacro(name, SimpleDataObjectDecorator<type>, number); \
00157   itkGetInputMacro(name, SimpleDataObjectDecorator<type>, number); \
00158   virtual void Set##name(const type &_arg) \
00159   { \
00160     typedef SimpleDataObjectDecorator< type > DecoratorType; \
00161     itkDebugMacro("setting input " #name " to " << _arg); \
00162     const DecoratorType * oldInput = \
00163       static_cast< const DecoratorType * >( \
00164         this->ProcessObject::GetInput(number) ); \
00165     if( oldInput && oldInput->Get() == _arg ) \
00166       { \
00167       return; \
00168       } \
00169     typename DecoratorType::Pointer newInput = DecoratorType::New(); \
00170     newInput->Set( _arg ); \
00171     this->Set##name##Input( newInput ); \
00172   }
00173 
00174 
00178 #define itkSetDecoratedObjectInputMacro(name, type, number) \
00179   itkSetInputMacro(name, DataObjectDecorator<type>, number); \
00180   itkGetInputMacro(name, DataObjectDecorator<type>, number); \
00181   virtual void Set##name(const type *_arg) \
00182   { \
00183     typedef DataObjectDecorator< type > DecoratorType; \
00184     itkDebugMacro("setting input " #name " to " << _arg); \
00185     const DecoratorType * oldInput = \
00186       static_cast< const DecoratorType * >( \
00187         this->ProcessObject::GetInput(number) ); \
00188     if( oldInput && oldInput->Get() == _arg ) \
00189       { \
00190       return; \
00191       } \
00192     typename DecoratorType::Pointer newInput = DecoratorType::New(); \
00193     newInput->Set( _arg ); \
00194     this->Set##name##Input( newInput ); \
00195   }
00196 
00197 
00198 
00200 #define itkSetMacro(name,type) \
00201   virtual void Set##name (const type _arg) \
00202   { \
00203     itkDebugMacro("setting " #name " to " << _arg); \
00204     if (this->m_##name != _arg) \
00205       { \
00206       this->m_##name = _arg; \
00207       this->Modified(); \
00208       } \
00209   } 
00210 
00211 
00213 #define itkGetMacro(name,type) \
00214   virtual type Get##name () \
00215   { \
00216     itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00217     return this->m_##name; \
00218   }
00219 
00220 
00224 #define itkGetConstMacro(name,type) \
00225   virtual type Get##name () const \
00226   { \
00227     itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00228     return this->m_##name; \
00229   }
00230 
00231 
00236 #define itkGetConstReferenceMacro(name,type) \
00237   virtual const type & Get##name () const \
00238   { \
00239     itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00240     return this->m_##name; \
00241   }
00242 
00243 
00247 #define itkSetEnumMacro(name,type) \
00248   virtual void Set##name (const type _arg) \
00249   { \
00250     itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
00251     if (this->m_##name != _arg) \
00252       { \
00253       this->m_##name = _arg; \
00254       this->Modified(); \
00255       } \
00256   } 
00257 
00258 
00262 #define itkGetEnumMacro(name,type) \
00263   virtual type Get##name () const \
00264   { \
00265     itkDebugMacro("returning " << #name " of " << static_cast<long>(this->m_##name) ); \
00266     return this->m_##name; \
00267   }
00268 
00269 
00273 #define itkSetStringMacro(name) \
00274   virtual void Set##name (const char* _arg) \
00275   { \
00276     if ( _arg && (_arg == this->m_##name) ) { return;} \
00277     if (_arg) \
00278       { \
00279       this->m_##name = _arg;\
00280       } \
00281      else \
00282       { \
00283       this->m_##name = ""; \
00284       } \
00285     this->Modified(); \
00286   } \
00287   virtual void Set##name (const std::string & _arg) \
00288   { \
00289     this->Set##name( _arg.c_str() ); \
00290   } \
00291 
00292 
00293 
00297 #define itkGetStringMacro(name) \
00298   virtual const char* Get##name () const \
00299   { \
00300     return this->m_##name.c_str(); \
00301   }
00302 
00306 #define itkSetClampMacro(name,type,min,max) \
00307   virtual void Set##name (type _arg) \
00308   { \
00309     itkDebugMacro("setting " << #name " to " << _arg ); \
00310     if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
00311       { \
00312       this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
00313       this->Modified(); \
00314       } \
00315   } 
00316 
00317 
00322 #define itkSetObjectMacro(name,type) \
00323   virtual void Set##name (type* _arg) \
00324   { \
00325     itkDebugMacro("setting " << #name " to " << _arg ); \
00326     if (this->m_##name != _arg) \
00327       { \
00328       this->m_##name = _arg; \
00329       this->Modified(); \
00330       } \
00331   } 
00332 
00333 
00336 #define itkGetObjectMacro(name,type) \
00337   virtual type * Get##name () \
00338   { \
00339     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00340     return this->m_##name.GetPointer(); \
00341   } 
00342 
00343 
00348 #define itkSetConstObjectMacro(name,type) \
00349   virtual void Set##name (const type* _arg) \
00350   { \
00351     itkDebugMacro("setting " << #name " to " << _arg ); \
00352     if (this->m_##name != _arg) \
00353       { \
00354       this->m_##name = _arg; \
00355       this->Modified(); \
00356       } \
00357   } 
00358 
00359 
00360 
00363 #define itkGetConstObjectMacro(name,type) \
00364   virtual const type * Get##name () const \
00365   { \
00366     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00367     return this->m_##name.GetPointer(); \
00368   } 
00369 
00370 
00373 #define itkGetConstReferenceObjectMacro(name,type) \
00374   virtual const typename type::Pointer & Get##name () const \
00375   { \
00376     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00377     return this->m_##name; \
00378   } 
00379 
00380 
00383 #define itkBooleanMacro(name) \
00384   virtual void name##On () { this->Set##name(true);} \
00385   virtual void name##Off () { this->Set##name(false);}
00386 
00387 
00391 #define itkSetVectorMacro(name,type,count) \
00392   virtual void Set##name(type data[]) \
00393   { \
00394     unsigned int i; \
00395     for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
00396     if ( i < count ) \
00397       { \
00398       this->Modified(); \
00399       for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
00400       } \
00401   }
00402 
00403 
00406 #define itkGetVectorMacro(name,type,count) \
00407   virtual type *Get##name () const \
00408   { \
00409     return this->m_##name; \
00410   } 
00411 
00428 #define itkNewMacro(x) \
00429 static Pointer New(void) \
00430 { \
00431   Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
00432   if(smartPtr.GetPointer() == NULL) \
00433     { \
00434     smartPtr = new x; \
00435     } \
00436   smartPtr->UnRegister(); \
00437   return smartPtr; \
00438 } \
00439 virtual ::itk::LightObject::Pointer CreateAnother(void) const \
00440 { \
00441   ::itk::LightObject::Pointer smartPtr; \
00442   smartPtr = x::New().GetPointer(); \
00443   return smartPtr; \
00444 }
00445 
00446 
00447 
00464 #define itkFactorylessNewMacro(x) \
00465 static Pointer New(void) \
00466 { \
00467   Pointer smartPtr; \
00468   x *rawPtr = new x; \
00469   smartPtr = rawPtr; \
00470   rawPtr->UnRegister(); \
00471   return smartPtr; \
00472 } \
00473   virtual ::itk::LightObject::Pointer CreateAnother(void) const \
00474 { \
00475   ::itk::LightObject::Pointer smartPtr;         \
00476   smartPtr = x::New().GetPointer(); \
00477   return smartPtr; \
00478 }
00479 
00480 
00483 #define itkTypeMacro(thisClass,superclass) \
00484     virtual const char *GetNameOfClass() const \
00485         {return #thisClass;} 
00486 
00487 
00488 namespace itk
00489 {
00496 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char*);
00497 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char*);
00498 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char*);
00499 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char*);
00500 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char*);
00501 } // end namespace itk
00503 
00507 #if defined(ITK_LEAN_AND_MEAN) || defined(__BORLANDC__)
00508 #define itkDebugMacro(x)
00509 #else
00510 #define itkDebugMacro(x) \
00511   { if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay())   \
00512     { ::itk::OStringStream itkmsg; \
00513       itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00514              << this->GetNameOfClass() << " (" << this << "): " x  \
00515              << "\n\n"; \
00516       ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str());} \
00517 }
00518 #endif
00519 
00520 
00521 
00525 #ifdef ITK_LEAN_AND_MEAN
00526 #define itkWarningMacro(x)
00527 #else
00528 #define itkWarningMacro(x) \
00529 { if (::itk::Object::GetGlobalWarningDisplay()) \
00530     { ::itk::OStringStream itkmsg; \
00531       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00532              << this->GetNameOfClass() << " (" << this << "): " x  \
00533              << "\n\n"; \
00534       ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str());} \
00535 }
00536 #endif
00537 
00538 
00539 namespace itk
00540 {
00541 
00547 #if !defined(ITK_NO_ANSI_STRING_STREAM)
00548 class OStringStream: public std::ostringstream
00549 {
00550 public:
00551   OStringStream() {}
00552 private:
00553   OStringStream(const OStringStream&);
00554   void operator=(const OStringStream&);
00555 };
00556 #else
00557 namespace OStringStreamDetail
00558 {
00559   class Cleanup
00560   {
00561   public:
00562     Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
00563     ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
00564     static void IgnoreUnusedVariable(const Cleanup&) {}
00565   protected:
00566     std::ostrstream& m_OStrStream;
00567   };
00568 }//namespace OStringStreamDetail
00570 
00571 class OStringStream: public std::ostrstream
00572 {
00573 public:
00574   typedef std::ostrstream Superclass;
00575   OStringStream() {}
00576   std::string str()
00577     {
00578       OStringStreamDetail::Cleanup cleanup(*this);
00579       OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
00580       int pcount = this->pcount();
00581       const char* ptr = this->Superclass::str();
00582       return std::string(ptr?ptr:"", pcount);
00583     }
00584 private:
00585   OStringStream(const OStringStream&);
00586   void operator=(const OStringStream&);
00587 };
00588 #endif
00589 
00590 }//namespace itk
00591 
00592 #if defined(ITK_CPP_FUNCTION)
00593   #if defined(__BORLANDC__)
00594     #define ITK_LOCATION __FUNC__
00595   #elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(CABLE_CONFIGURATION) && !defined(CSWIG)
00596     #define ITK_LOCATION __FUNCSIG__
00597   #elif defined(__GNUC__)
00598     #define ITK_LOCATION __PRETTY_FUNCTION__
00599   #else
00600     #define ITK_LOCATION __FUNCTION__
00601   #endif
00602 #else
00603   #define ITK_LOCATION "unknown"
00604 #endif
00605 
00606 #include "itkExceptionObject.h"
00607 
00611 #define itkExceptionMacro(x) \
00612   { \
00613   ::itk::OStringStream message; \
00614   message << "itk::ERROR: " << this->GetNameOfClass() \
00615           << "(" << this << "): " x; \
00616   ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00617   throw e_; /* Explicit naming to work around Intel compiler bug.  */ \
00618   }
00619 
00620 
00621 #define itkGenericExceptionMacro(x) \
00622   { \
00623   ::itk::OStringStream message; \
00624   message << "itk::ERROR: " x; \
00625   ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00626   throw e_; /* Explicit naming to work around Intel compiler bug.  */ \
00627   }
00628 
00629 #ifdef ITK_LEAN_AND_MEAN
00630 #define itkGenericOutputMacro(x)
00631 #else
00632 #define itkGenericOutputMacro(x) \
00633 { if (::itk::Object::GetGlobalWarningDisplay()) \
00634     { ::itk::OStringStream itkmsg; \
00635       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00636              x << "\n\n"; \
00637       ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str());} \
00638 }
00639 #endif
00640 
00641 
00642 
00643 //----------------------------------------------------------------------------
00644 // Macros for simplifying the use of logging
00645 //
00646 #define itkLogMacro( x, y)  \
00647 {         \
00648   if (this->GetLogger() ) \
00649     {  \
00650     this->GetLogger()->Write(::itk::LoggerBase::x, y); \
00651     }  \
00652 }
00653 
00654 
00655 #define itkLogMacroStatic( obj, x, y)  \
00656 {         \
00657   if (obj->GetLogger() ) \
00658     {  \
00659     obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
00660     }  \
00661 }
00662 
00663 
00664 //----------------------------------------------------------------------------
00665 // Setup legacy code policy.
00666 //
00667 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted
00668 // to definitions (or non-defs) in itkConfigure.h and tested below.
00669 // They may be used to completely remove legacy code or silence the
00670 // warnings.  The default is to warn about their use.
00671 //
00672 // Source files that test the legacy code may define ITK_LEGACY_TEST
00673 // like this:
00674 //
00675 //  #define ITK_LEGACY_TEST
00676 //  #include "itkClassWithDeprecatedMethod.h"
00677 //
00678 // in order to silence the warnings for calling deprecated methods.
00679 // No other source files in ITK should call the methods since they are
00680 // provided only for compatibility with older user code.
00681 
00682 // Define itkLegacyMacro to mark legacy methods where they are
00683 // declared in their class.  Example usage:
00684 //
00685 //   // @deprecated Replaced by MyOtherMethod() as of ITK 2.0.
00686 //   itkLegacyMacro(void MyMethod());
00687 #if defined(ITK_LEGACY_REMOVE)
00688 // Remove legacy methods completely.  Put a bogus declaration in
00689 // place to avoid stray semicolons because this is an error for some
00690 // compilers.  Using a class forward declaration allows any number
00691 // of repeats in any context without generating unique names.
00692 # define itkLegacyMacro(method) class itkLegacyMethodRemoved /* no ';' */
00693 #elif defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST) || defined(CSWIG)
00694   // Provide legacy methods with no warnings.
00695 # define itkLegacyMacro(method) method
00696 #else
00697   // Setup compile-time warnings for uses of deprecated methods if
00698   // possible on this compiler.
00699 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00700 #  define itkLegacyMacro(method) method __attribute__((deprecated))
00701 # elif defined(_MSC_VER) && _MSC_VER >= 1300
00702 #  define itkLegacyMacro(method) __declspec(deprecated) method
00703 # else
00704 #  define itkLegacyMacro(method) method
00705 # endif
00706 #endif
00707 
00708 // Macros to create runtime deprecation warning messages in function
00709 // bodies.  Example usage:
00710 //
00711 //   void itkMyClass::MyOldMethod()
00712 //     {
00713 //     itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
00714 //     }
00715 //
00716 //   void itkMyClass::MyMethod()
00717 //     {
00718 //     itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
00719 //                               itkMyClass::MyOtherMethod);
00720 //     }
00721 #if defined(ITK_LEGACY_REMOVE) || defined(ITK_LEGACY_SILENT)
00722 # define itkLegacyBodyMacro(method, version)
00723 # define itkLegacyReplaceBodyMacro(method, version, replace)
00724 #else
00725 # define itkLegacyBodyMacro(method, version) \
00726   itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00727 # define itkLegacyReplaceBodyMacro(method, version, replace) \
00728   itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.  Use " #replace " instead.")
00729 #endif
00730 
00731 #if defined(__INTEL_COMPILER)
00732 # pragma warning (disable: 193) /* #if testing undefined identifier */
00733 #endif
00734 
00735 //=============================================================================
00736 /* Choose a way to prevent template instantiation on this platform.
00737   - ITK_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
00738                                       prevent instantiation
00739   - ITK_TEMPLATE_EXTERN = use extern template to prevent instantiation
00740 
00741    Note that VS 6 supports extern template instantiation but it is
00742    hard to block the resulting warning because its stream headers
00743    re-enable it.  Therefore we just disable support for now.
00744 */
00745 #if defined(__sgi) && defined(_COMPILER_VERSION)
00746 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 1
00747 #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
00748 # define ITK_TEMPLATE_EXTERN 1
00749 #elif defined(__GNUC__) && __GNUC__ >= 3
00750 # define ITK_TEMPLATE_EXTERN 1
00751 #elif defined(_MSC_VER) && _MSC_VER >= 1300
00752 # define ITK_TEMPLATE_EXTERN 1
00753 #endif
00754 #if !defined(ITK_TEMPLATE_DO_NOT_INSTANTIATE)
00755 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
00756 #endif
00757 #if !defined(ITK_TEMPLATE_EXTERN)
00758 # define ITK_TEMPLATE_EXTERN 0
00759 #endif
00760 
00761 /* Define a macro to explicitly instantiate a template.
00762   - ITK_TEMPLATE_EXPORT(X) =
00763       Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
00764       examples: ITK_TEMPLATE_EXPORT(1(class Foo<int>))
00765                 ITK_TEMPLATE_EXPORT(2(class Bar<int, char>))
00766       Use one level of expansion delay to allow user code to have
00767       a macro determining the number of arguments. */
00768 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
00769 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
00770 
00771 /* Define a macro to prevent template instantiations.
00772   - ITK_TEMPLATE_IMPORT(X) =
00773       Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
00774       examples: ITK_TEMPLATE_IMPORT(1(class Foo<int>))
00775                 ITK_TEMPLATE_IMPORT(2(class Bar<int, char>))
00776       Use one level of expansion delay to allow user code to have
00777       a macro determining the number of arguments.
00778 */
00779 #if ITK_TEMPLATE_EXTERN
00780 # define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
00781 # if defined(_MSC_VER)
00782 #  pragma warning (disable: 4231) /* extern template extension */
00783 # endif
00784 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
00785 # define ITK_TEMPLATE_IMPORT_DELAY(x) \
00786          ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
00787 # define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00788 #endif
00789 #if defined(ITK_TEMPLATE_IMPORT_DELAY)
00790 # define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
00791 # define ITK_TEMPLATE_IMPORT_WORKS 1
00792 #else
00793 # define ITK_TEMPLATE_IMPORT(x)
00794 # define ITK_TEMPLATE_IMPORT_WORKS 0
00795 #endif
00796 
00797 /* Define macros to export and import template instantiations.  These
00798    depend on each class providing a macro defining the instantiations
00799    given template arguments in X.  The argument X is of the form
00800    N(a1[,a2...,aN]).  The argument Y is a valid preprocessing token
00801    unique to the template arguments given in X.  Typical usage is
00802 
00803      ITK_EXPORT_TEMPLATE(itkfoo_EXPORT, Foo, (int), I)
00804      ITK_EXPORT_TEMPLATE(itkfoo_EXPORT, Bar, (int, char), IC)
00805 
00806    The ITK_TEMPLATE_<name> macro should be defined in itk<name>.h and
00807    is of the following form:
00808 
00809      #define ITK_TEMPLATE_<name>(_, EXPORT, x, y) namespace itk { \
00810        _(<n>(class EXPORT <name>< ITK_TEMPLATE_<n> x >)) \
00811        namespace Templates { typedef <name>< ITK_TEMPLATE_<n> x > <name>##y; }\
00812      }
00813 
00814    The argument "_" will be replaced by another macro such as
00815    ITK_TEMPLATE_EXPORT or ITK_TEMPLATE_IMPORT, so it should be used as
00816    if calling one of these macros.  The argument "EXPORT" will be
00817    replaced by a dllexport/dllimport macro such as ITKCommon_EXPORT.
00818    The argument "x" is a paren-enclosed list of template arguments.
00819    The argument "y" is a preprocessing token corresponding to the
00820    given template arguments and should be used to construct typedef
00821    names for the instantiations.
00822 
00823    Note the use of ITK_TEMPLATE_<n>, where <n> is the number of
00824    template arguments for the class template.  Note also that the
00825    number of template arguments is usually the length of the list
00826    nested within the inner parentheses, so the instantiation is listed
00827    with the form <n>(...).  Example definitions:
00828 
00829      #define ITK_TEMPLATE_Foo(_, EXPORT, x, y) namespace itk { \
00830        _(1(class EXPORT Foo< ITK_TEMPLATE_1 x >)) \
00831        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00832                                            const Foo< ITK_TEMPLATE_1 x >&))) \
00833        namespace Templates { typedef Foo< ITK_TEMPLATE_1 x > Foo##y; }\
00834      }
00835 
00836      #define ITK_TEMPLATE_Bar(_, EXPORT, x, y) namespace itk { \
00837        _(2(class EXPORT Bar< ITK_TEMPLATE_2 x >)) \
00838        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00839                                            const Bar< ITK_TEMPLATE_2 x >&))) \
00840        namespace Templates { typedef Bar< ITK_TEMPLATE_2 x > Bar##y; }\
00841      }
00842 
00843    Note that in the stream operator for template Bar there is a "1" at
00844    the beginning even though two arguments are taken.  This is because
00845    the expression "ITK_TEMPLATE_2 x" is contained inside the
00846    parentheses of the function signature which protects the resulting
00847    comma from separating macro arguments.  Therefore the nested
00848    parentheses contain a list of only one macro argument.
00849 
00850    The ITK_EMPTY macro used in these definitions is a hack to work
00851    around a VS 6.0 preprocessor bug when EXPORT is empty.
00852 */
00853 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \
00854         ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y)
00855 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \
00856         ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y)
00857 #define ITK_EMPTY
00858 
00859 /* Define macros to support passing a variable number of arguments
00860    throug other macros.  This is used by ITK_TEMPLATE_EXPORT,
00861    ITK_TEMPLATE_IMPORT, and by each template's instantiation
00862    macro.  */
00863 #define ITK_TEMPLATE_1(x1)                         x1
00864 #define ITK_TEMPLATE_2(x1,x2)                      x1,x2
00865 #define ITK_TEMPLATE_3(x1,x2,x3)                   x1,x2,x3
00866 #define ITK_TEMPLATE_4(x1,x2,x3,x4)                x1,x2,x3,x4
00867 #define ITK_TEMPLATE_5(x1,x2,x3,x4,x5)             x1,x2,x3,x4,x5
00868 #define ITK_TEMPLATE_6(x1,x2,x3,x4,x5,x6)          x1,x2,x3,x4,x5,x6
00869 #define ITK_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7)       x1,x2,x3,x4,x5,x6,x7
00870 #define ITK_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8)    x1,x2,x3,x4,x5,x6,x7,x8
00871 #define ITK_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
00872 
00873 /* In order to support both implicit and explicit instantation a .h
00874    file needs to know whether it should include its .txx file
00875    containing the template definitions.  Define a macro to tell
00876    it.  Typical usage in itkFoo.h:
00877      #if ITK_TEMPLATE_TXX
00878      # include "itkFoo.txx"
00879      #endif
00880 */
00881 #if defined(ITK_MANUAL_INSTANTIATION)
00882 # define ITK_TEMPLATE_TXX 0
00883 #else
00884 # define ITK_TEMPLATE_TXX !(ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE)
00885 #endif
00886 
00887 /* All explicit instantiation source files define ITK_TEMPLATE_CXX.
00888    Define ITK_MANUAL_INSTANTIATION to tell .h files that have not been
00889    converted to this explicit instantiation scheme to not include
00890    their .txx files.  Also disable warnings that commonly occur in
00891    these files but are not useful.  */
00892 #if ITK_TEMPLATE_CXX
00893 # undef ITK_MANUAL_INSTANTIATION
00894 # define ITK_MANUAL_INSTANTIATION
00895 # if defined(_MSC_VER)
00896 #  pragma warning (disable: 4275) /* non dll-interface base */
00897 #  pragma warning (disable: 4661) /* no definition available */
00898 # endif
00899 #endif
00900 //=============================================================================
00901 
00902 /* Define macros to export and import template instantiations for each
00903    library in ITK.  */
00904 #define ITK_EXPORT_ITKCommon(c, x, n) \
00905         ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00906 #define ITK_IMPORT_ITKCommon(c, x, n) \
00907         ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00908 
00909 /* Define a macro to decide whether to block instantiation of ITK
00910    templates.  They should be blocked only if the platform supports
00911    blocking template instantiation and the explicit instantiations are
00912    available.
00913 
00914    - ITK_TEMPLATE_EXPLICIT =
00915       Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
00916       instantiations of templates explicitly instantiated elsewhere.
00917       Typical usage in itkFoo.h:
00918         #if ITK_TEMPLATE_EXPLICIT
00919         # include "itkFoo+-.h"
00920         #endif
00921 */
00922 #if ITK_TEMPLATE_IMPORT_WORKS && defined(ITK_EXPLICIT_INSTANTIATION)
00923 # define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX
00924 #else
00925 # define ITK_TEMPLATE_EXPLICIT 0
00926 #endif
00927 
00928 
00929 //----------------------------------------------------------------------------
00930 // Macro to declare that a function does not return. __attribute__((noreturn))
00931 //    On some compiler, functions that do not return (ex: exit(0)) must
00932 //    have the noreturn attribute. Otherwise, a warning is raised. Use
00933 //    that macro to avoid those warnings. GCC defines the attribute
00934 //    noreturn for versions 2.5 and higher.
00935 #if defined(__GNUC__)
00936 #  if (((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 3))
00937 #    define ITK_NO_RETURN \
00938        __attribute__ ((noreturn))
00939 #  endif
00940 #else
00941 #  define ITK_NO_RETURN
00942 #endif
00943 
00944 
00945 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
00946 //--------------------------------------------------------------------------------
00947 //  Helper macros for Template Meta-Programming techniques of for-loops unrolling
00948 //--------------------------------------------------------------------------------
00949 
00950 //--------------------------------------------------------------------------------
00951 // Macro that generates an unrolled for loop for assigning elements of one array
00952 // to elements of another array The array are assumed to be of same length
00953 // (dimension), and this is also assumed to be the value of NumberOfIterations.
00954 // No verification of size is performed. Casting is perfomed as part of the
00955 // assignment, by using the DestinationElementType as the casting type. 
00956 // Source and destination array types must have defined opearator[] in their API.
00957 #define itkFoorLoopAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
00958     for(unsigned int i=0;i < NumberOfIterations; ++i) \
00959       { \
00960       DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
00961       }
00962 
00963 //--------------------------------------------------------------------------------
00964 // Macro that generates an unrolled for loop for rounding and assigning
00965 // elements of one array to elements of another array The array are assumed to
00966 // be of same length (dimension), and this is also assumed to be the value of
00967 // NumberOfIterations.  No verification of size is performed. Casting is
00968 // perfomed as part of the assignment, by using the DestinationElementType as
00969 // the casting type. 
00970 // Source and destination array types must have defined opearator[] in their API.
00971 #define itkFoorLoopRoundingAndAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
00972     for(unsigned int i=0;i < NumberOfIterations; ++i) \
00973       { \
00974       DestinationArray[i] = static_cast< DestinationElementType >( vnl_math_rnd( SourceArray[i] ) ); \
00975       }
00976 
00977 #endif
00978 // end of Template Meta Programming helper macros
00979 
00980 
00981 #endif //end of itkMacro.h
00982 

Generated at Mon Apr 14 13:26:02 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000