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/08/27 17:49:34 $
00007   Version:   $Revision: 1.75 $
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 LightObject::Pointer CreateAnother(void) const \
00474 { \
00475   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 // Define itkLegacy macro to mark legacy methods where they are
00668 // declared in their class.  Example usage:
00669 //
00670 //   // @deprecated Replaced by MyOtherMethod() as of ITK 2.0.
00671 //   itkLegacy(void MyMethod());
00672 #if defined(ITK_LEGACY_REMOVE)
00673   // Remove legacy methods completely.
00674 # define itkLegacy(method)
00675 #elif defined(ITK_LEGACY_SILENT) || defined(ITK_WRAPPING_CXX)
00676   // Provide legacy methods with no warnings.
00677 # define itkLegacy(method) method
00678 #else
00679   // Setup compile-time warnings for uses of deprecated methods if
00680   // possible on this compiler.
00681 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00682 #  define itkLegacy(method) method __attribute__((deprecated))
00683 # elif defined(_MSC_VER) && _MSC_VER >= 1300
00684 #  define itkLegacy(method) __declspec(deprecated) method
00685 # else
00686 #  define itkLegacy(method) method
00687 # endif
00688 #endif
00689 
00690 // Macros to create runtime deprecation warning messages in function
00691 // bodies.  Example usage:
00692 //
00693 //   void itkMyClass::MyOldMethod()
00694 //   {
00695 //     itkLegacyBody(itkMyClass::MyOldMethod, 2.0);
00696 //   }
00697 //
00698 //   void itkMyClass::MyMethod()
00699 //   {
00700 //     itkLegacyReplaceBody(itkMyClass::MyMethod, 2.0,
00701 //                          itkMyClass::MyOtherMethod);
00702 //   }
00703 #if defined(ITK_LEGACY_REMOVE) || defined(ITK_LEGACY_SILENT)
00704 # define itkLegacyBody(method, version)
00705 # define itkLegacyReplaceBody(method, version, replace)
00706 #else
00707 # define itkLegacyBody(method, version) \
00708   itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00709 # define itkLegacyReplaceBody(method, version, replace) \
00710   itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.  Use " #replace " instead.")
00711 #endif
00712 
00713 #if defined(__INTEL_COMPILER)
00714 # pragma warning (disable: 193) /* #if testing undefined identifier */
00715 #endif
00716 
00717 //=============================================================================
00718 /* Choose a way to prevent template instantiation on this platform.
00719   - ITK_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
00720                                       prevent instantiation
00721   - ITK_TEMPLATE_EXTERN = use extern template to prevent instantiation
00722 
00723    Note that VS 6 supports extern template instantiation but it is
00724    hard to block the resulting warning because its stream headers
00725    re-enable it.  Therefore we just disable support for now.
00726 */
00727 #if defined(__sgi) && defined(_COMPILER_VERSION)
00728 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 1
00729 #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
00730 # define ITK_TEMPLATE_EXTERN 1
00731 #elif defined(__GNUC__) && __GNUC__ >= 3
00732 # define ITK_TEMPLATE_EXTERN 1
00733 #elif defined(_MSC_VER) && _MSC_VER >= 1300
00734 # define ITK_TEMPLATE_EXTERN 1
00735 #endif
00736 #if !defined(ITK_TEMPLATE_DO_NOT_INSTANTIATE)
00737 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
00738 #endif
00739 #if !defined(ITK_TEMPLATE_EXTERN)
00740 # define ITK_TEMPLATE_EXTERN 0
00741 #endif
00742 
00743 /* Define a macro to explicitly instantiate a template.
00744   - ITK_TEMPLATE_EXPORT(X) =
00745       Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
00746       examples: ITK_TEMPLATE_EXPORT(1(class Foo<int>))
00747                 ITK_TEMPLATE_EXPORT(2(class Bar<int, char>))
00748       Use one level of expansion delay to allow user code to have
00749       a macro determining the number of arguments. */
00750 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
00751 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
00752 
00753 /* Define a macro to prevent template instantiations.
00754   - ITK_TEMPLATE_IMPORT(X) =
00755       Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
00756       examples: ITK_TEMPLATE_IMPORT(1(class Foo<int>))
00757                 ITK_TEMPLATE_IMPORT(2(class Bar<int, char>))
00758       Use one level of expansion delay to allow user code to have
00759       a macro determining the number of arguments.
00760 */
00761 #if ITK_TEMPLATE_EXTERN
00762 # define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
00763 # if defined(_MSC_VER)
00764 #  pragma warning (disable: 4231) /* extern template extension */
00765 # endif
00766 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
00767 # define ITK_TEMPLATE_IMPORT_DELAY(x) \
00768          ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
00769 # define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00770 #endif
00771 #if defined(ITK_TEMPLATE_IMPORT_DELAY)
00772 # define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
00773 # define ITK_TEMPLATE_IMPORT_WORKS 1
00774 #else
00775 # define ITK_TEMPLATE_IMPORT(x)
00776 # define ITK_TEMPLATE_IMPORT_WORKS 0
00777 #endif
00778 
00779 /* Define macros to export and import template instantiations.  These
00780    depend on each class providing a macro defining the instantiations
00781    given template arguments in X.  The argument X is of the form
00782    N(a1[,a2...,aN]).  The argument Y is a valid preprocessing token
00783    unique to the template arguments given in X.  Typical usage is
00784 
00785      ITK_EXPORT_TEMPLATE(itkfoo_EXPORT, Foo, (int), I)
00786      ITK_EXPORT_TEMPLATE(itkfoo_EXPORT, Bar, (int, char), IC)
00787 
00788    The ITK_TEMPLATE_<name> macro should be defined in itk<name>.h and
00789    is of the following form:
00790 
00791      #define ITK_TEMPLATE_<name>(_, EXPORT, x, y) namespace itk { \
00792        _(<n>(class EXPORT <name>< ITK_TEMPLATE_<n> x >)) \
00793        namespace Templates { typedef <name>< ITK_TEMPLATE_<n> x > <name>##y; }\
00794      }
00795 
00796    The argument "_" will be replaced by another macro such as
00797    ITK_TEMPLATE_EXPORT or ITK_TEMPLATE_IMPORT, so it should be used as
00798    if calling one of these macros.  The argument "EXPORT" will be
00799    replaced by a dllexport/dllimport macro such as ITKCommon_EXPORT.
00800    The argument "x" is a paren-enclosed list of template arguments.
00801    The argument "y" is a preprocessing token corresponding to the
00802    given template arguments and should be used to construct typedef
00803    names for the instantiations.
00804 
00805    Note the use of ITK_TEMPLATE_<n>, where <n> is the number of
00806    template arguments for the class template.  Note also that the
00807    number of template arguments is usually the length of the list
00808    nested within the inner parentheses, so the instantiation is listed
00809    with the form <n>(...).  Example definitions:
00810 
00811      #define ITK_TEMPLATE_Foo(_, EXPORT, x, y) namespace itk { \
00812        _(1(class EXPORT Foo< ITK_TEMPLATE_1 x >)) \
00813        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00814                                            const Foo< ITK_TEMPLATE_1 x >&))) \
00815        namespace Templates { typedef Foo< ITK_TEMPLATE_1 x > Foo##y; }\
00816      }
00817 
00818      #define ITK_TEMPLATE_Bar(_, EXPORT, x, y) namespace itk { \
00819        _(2(class EXPORT Bar< ITK_TEMPLATE_2 x >)) \
00820        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00821                                            const Bar< ITK_TEMPLATE_2 x >&))) \
00822        namespace Templates { typedef Bar< ITK_TEMPLATE_2 x > Bar##y; }\
00823      }
00824 
00825    Note that in the stream operator for template Bar there is a "1" at
00826    the beginning even though two arguments are taken.  This is because
00827    the expression "ITK_TEMPLATE_2 x" is contained inside the
00828    parentheses of the function signature which protects the resulting
00829    comma from separating macro arguments.  Therefore the nested
00830    parentheses contain a list of only one macro argument.
00831 
00832    The ITK_EMPTY macro used in these definitions is a hack to work
00833    around a VS 6.0 preprocessor bug when EXPORT is empty.
00834 */
00835 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \
00836         ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y)
00837 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \
00838         ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y)
00839 #define ITK_EMPTY
00840 
00841 /* Define macros to support passing a variable number of arguments
00842    throug other macros.  This is used by ITK_TEMPLATE_EXPORT,
00843    ITK_TEMPLATE_IMPORT, and by each template's instantiation
00844    macro.  */
00845 #define ITK_TEMPLATE_1(x1)                         x1
00846 #define ITK_TEMPLATE_2(x1,x2)                      x1,x2
00847 #define ITK_TEMPLATE_3(x1,x2,x3)                   x1,x2,x3
00848 #define ITK_TEMPLATE_4(x1,x2,x3,x4)                x1,x2,x3,x4
00849 #define ITK_TEMPLATE_5(x1,x2,x3,x4,x5)             x1,x2,x3,x4,x5
00850 #define ITK_TEMPLATE_6(x1,x2,x3,x4,x5,x6)          x1,x2,x3,x4,x5,x6
00851 #define ITK_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7)       x1,x2,x3,x4,x5,x6,x7
00852 #define ITK_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8)    x1,x2,x3,x4,x5,x6,x7,x8
00853 #define ITK_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
00854 
00855 /* In order to support both implicit and explicit instantation a .h
00856    file needs to know whether it should include its .txx file
00857    containing the template definitions.  Define a macro to tell
00858    it.  Typical usage in itkFoo.h:
00859      #if ITK_TEMPLATE_TXX
00860      # include "itkFoo.txx"
00861      #endif
00862 */
00863 #if defined(ITK_MANUAL_INSTANTIATION)
00864 # define ITK_TEMPLATE_TXX 0
00865 #else
00866 # define ITK_TEMPLATE_TXX !(ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE)
00867 #endif
00868 
00869 /* All explicit instantiation source files define ITK_TEMPLATE_CXX.
00870    Define ITK_MANUAL_INSTANTIATION to tell .h files that have not been
00871    converted to this explicit instantiation scheme to not include
00872    their .txx files.  Also disable warnings that commonly occur in
00873    these files but are not useful.  */
00874 #if ITK_TEMPLATE_CXX
00875 # undef ITK_MANUAL_INSTANTIATION
00876 # define ITK_MANUAL_INSTANTIATION
00877 # if defined(_MSC_VER)
00878 #  pragma warning (disable: 4275) /* non dll-interface base */
00879 #  pragma warning (disable: 4661) /* no definition available */
00880 # endif
00881 #endif
00882 //=============================================================================
00883 
00884 /* Define macros to export and import template instantiations for each
00885    library in ITK.  */
00886 #define ITK_EXPORT_ITKCommon(c, x, n) \
00887         ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00888 #define ITK_IMPORT_ITKCommon(c, x, n) \
00889         ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00890 
00891 /* Define a macro to decide whether to block instantiation of ITK
00892    templates.  They should be blocked only if the platform supports
00893    blocking template instantiation and the explicit instantiations are
00894    available.
00895 
00896    - ITK_TEMPLATE_EXPLICIT =
00897       Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
00898       instantiations of templates explicitly instantiated elsewhere.
00899       Typical usage in itkFoo.h:
00900         #if ITK_TEMPLATE_EXPLICIT
00901         # include "itkFoo+-.h"
00902         #endif
00903 */
00904 #if ITK_TEMPLATE_IMPORT_WORKS && defined(ITK_EXPLICIT_INSTANTIATION)
00905 # define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX
00906 #else
00907 # define ITK_TEMPLATE_EXPLICIT 0
00908 #endif
00909 
00910 
00911 //----------------------------------------------------------------------------
00912 // Macro to declare that a function does not return. __attribute__((noreturn))
00913 //    On some compiler, functions that do not return (ex: exit(0)) must
00914 //    have the noreturn attribute. Otherwise, a warning is raised. Use
00915 //    that macro to avoid those warnings. GCC defines the attribute
00916 //    noreturn for versions 2.5 and higher.
00917 #if defined(__GNUC__)
00918 #  if (((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 3))
00919 #    define ITK_NO_RETURN \
00920        __attribute__ ((noreturn))
00921 #  endif
00922 #else
00923 #  define ITK_NO_RETURN
00924 #endif
00925 
00926 
00927 #endif //end of itkMacro.h
00928 

Generated at Sun Sep 23 13:26:24 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000