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: 2006/11/29 10:10:51 $
00007   Version:   $Revision: 1.69 $
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 
00135 
00137 #define itkGetInputMacro(name, type, number) \
00138   virtual const type * Get##name##Input() const \
00139   { \
00140     itkDebugMacro("returning input " << #name " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
00141     return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
00142   } \
00143   virtual const type * GetInput##number() const \
00144   { \
00145     itkDebugMacro("returning input " << #number " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
00146     return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
00147   } 
00148 
00149 
00150 
00152 #define itkSetMacro(name,type) \
00153   virtual void Set##name (const type _arg) \
00154   { \
00155     itkDebugMacro("setting " #name " to " << _arg); \
00156     if (this->m_##name != _arg) \
00157       { \
00158       this->m_##name = _arg; \
00159       this->Modified(); \
00160       } \
00161   } 
00162 
00163 
00165 #define itkGetMacro(name,type) \
00166   virtual type Get##name () \
00167   { \
00168     itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00169     return this->m_##name; \
00170   }
00171 
00172 
00176 #define itkGetConstMacro(name,type) \
00177   virtual type Get##name () const \
00178   { \
00179     itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00180     return this->m_##name; \
00181   }
00182 
00183 
00188 #define itkGetConstReferenceMacro(name,type) \
00189   virtual const type & Get##name () const \
00190   { \
00191     itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00192     return this->m_##name; \
00193   }
00194 
00195 
00199 #define itkSetStringMacro(name) \
00200   virtual void Set##name (const char* _arg) \
00201   { \
00202     if ( _arg && (_arg == this->m_##name) ) { return;} \
00203     if (_arg) \
00204       { \
00205       this->m_##name = _arg;\
00206       } \
00207      else \
00208       { \
00209       this->m_##name = ""; \
00210       } \
00211     this->Modified(); \
00212   } \
00213   virtual void Set##name (const std::string & _arg) \
00214   { \
00215     this->Set##name( _arg.c_str() ); \
00216   } \
00217 
00218 
00219 
00223 #define itkGetStringMacro(name) \
00224   virtual const char* Get##name () const \
00225   { \
00226     return this->m_##name.c_str(); \
00227   } 
00228 
00232 #define itkSetClampMacro(name,type,min,max) \
00233   virtual void Set##name (type _arg) \
00234   { \
00235     itkDebugMacro("setting " << #name " to " << _arg ); \
00236     if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
00237       { \
00238       this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
00239       this->Modified(); \
00240       } \
00241   } 
00242 
00243 
00248 #define itkSetObjectMacro(name,type) \
00249   virtual void Set##name (type* _arg) \
00250   { \
00251     itkDebugMacro("setting " << #name " to " << _arg ); \
00252     if (this->m_##name != _arg) \
00253       { \
00254       this->m_##name = _arg; \
00255       this->Modified(); \
00256       } \
00257   } 
00258 
00259 
00262 #define itkGetObjectMacro(name,type) \
00263   virtual type * Get##name () \
00264   { \
00265     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00266     return this->m_##name.GetPointer(); \
00267   } 
00268 
00269 
00274 #define itkSetConstObjectMacro(name,type) \
00275   virtual void Set##name (const type* _arg) \
00276   { \
00277     itkDebugMacro("setting " << #name " to " << _arg ); \
00278     if (this->m_##name != _arg) \
00279       { \
00280       this->m_##name = _arg; \
00281       this->Modified(); \
00282       } \
00283   } 
00284 
00285 
00286 
00289 #define itkGetConstObjectMacro(name,type) \
00290   virtual const type * Get##name () const \
00291   { \
00292     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00293     return this->m_##name.GetPointer(); \
00294   } 
00295 
00296 
00299 #define itkGetConstReferenceObjectMacro(name,type) \
00300   virtual const typename type::Pointer & Get##name () const \
00301   { \
00302     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00303     return this->m_##name; \
00304   } 
00305 
00306 
00309 #define itkBooleanMacro(name) \
00310   virtual void name##On () { this->Set##name(true);} \
00311   virtual void name##Off () { this->Set##name(false);}
00312 
00313 
00317 #define itkSetVectorMacro(name,type,count) \
00318   virtual void Set##name(type data[]) \
00319   { \
00320     unsigned int i; \
00321     for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
00322     if ( i < count ) \
00323       { \
00324       this->Modified(); \
00325       for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
00326       } \
00327   }
00328 
00329 
00332 #define itkGetVectorMacro(name,type,count) \
00333   virtual type *Get##name () const \
00334   { \
00335     return this->m_##name; \
00336   } 
00337 
00354 #define itkNewMacro(x) \
00355 static Pointer New(void) \
00356 { \
00357   Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
00358   if(smartPtr.GetPointer() == NULL) \
00359     { \
00360     smartPtr = new x; \
00361     } \
00362   smartPtr->UnRegister(); \
00363   return smartPtr; \
00364 } \
00365 virtual ::itk::LightObject::Pointer CreateAnother(void) const \
00366 { \
00367   ::itk::LightObject::Pointer smartPtr; \
00368   smartPtr = x::New().GetPointer(); \
00369   return smartPtr; \
00370 }
00371 
00372 
00373 
00390 #define itkFactorylessNewMacro(x) \
00391 static Pointer New(void) \
00392 { \
00393   Pointer smartPtr; \
00394   x *rawPtr = new x; \
00395   smartPtr = rawPtr; \
00396   rawPtr->UnRegister(); \
00397   return smartPtr; \
00398 } \
00399 virtual LightObject::Pointer CreateAnother(void) const \
00400 { \
00401   LightObject::Pointer smartPtr; \
00402   smartPtr = x::New().GetPointer(); \
00403   return smartPtr; \
00404 }
00405 
00406 
00409 #define itkTypeMacro(thisClass,superclass) \
00410     virtual const char *GetNameOfClass() const \
00411         {return #thisClass;} 
00412 
00413 
00414 namespace itk
00415 {
00422 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char*);
00423 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char*);
00424 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char*);
00425 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char*);
00426 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char*);
00427 } // end namespace itk
00429 
00433 #if defined(ITK_LEAN_AND_MEAN) || defined(__BORLANDC__)
00434 #define itkDebugMacro(x)
00435 #else
00436 #define itkDebugMacro(x) \
00437   { if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay())   \
00438     { ::itk::OStringStream itkmsg; \
00439       itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00440              << this->GetNameOfClass() << " (" << this << "): " x  \
00441              << "\n\n"; \
00442       ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str());} \
00443 }
00444 #endif
00445 
00446 
00447 
00451 #ifdef ITK_LEAN_AND_MEAN
00452 #define itkWarningMacro(x)
00453 #else
00454 #define itkWarningMacro(x) \
00455 { if (itk::Object::GetGlobalWarningDisplay()) \
00456     { ::itk::OStringStream itkmsg; \
00457       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00458              << this->GetNameOfClass() << " (" << this << "): " x  \
00459              << "\n\n"; \
00460       itk::OutputWindowDisplayWarningText(itkmsg.str().c_str());} \
00461 }
00462 #endif
00463 
00464 
00465 namespace itk
00466 {
00467 
00473 #if !defined(ITK_NO_ANSI_STRING_STREAM)
00474 class OStringStream: public std::ostringstream
00475 {
00476 public:
00477   OStringStream() {}
00478 private:
00479   OStringStream(const OStringStream&);
00480   void operator=(const OStringStream&);
00481 };
00482 #else
00483 namespace OStringStreamDetail
00484 {
00485   class Cleanup
00486   {
00487   public:
00488     Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
00489     ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
00490     static void IgnoreUnusedVariable(const Cleanup&) {}
00491   protected:
00492     std::ostrstream& m_OStrStream;
00493   };
00494 }//namespace OStringStreamDetail
00496 
00497 class OStringStream: public std::ostrstream
00498 {
00499 public:
00500   typedef std::ostrstream Superclass;
00501   OStringStream() {}
00502   std::string str()
00503     {
00504       OStringStreamDetail::Cleanup cleanup(*this);
00505       OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
00506       int pcount = this->pcount();
00507       const char* ptr = this->Superclass::str();
00508       return std::string(ptr?ptr:"", pcount);
00509     }
00510 private:
00511   OStringStream(const OStringStream&);
00512   void operator=(const OStringStream&);
00513 };
00514 #endif
00515 
00516 }//namespace itk
00517 
00518 #if defined(ITK_CPP_FUNCTION)
00519   #if defined(__BORLANDC__)
00520     #define ITK_LOCATION __FUNC__
00521   #elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(CABLE_CONFIGURATION) && !defined(CSWIG)
00522     #define ITK_LOCATION __FUNCSIG__
00523   #elif defined(__GNUC__)
00524     #define ITK_LOCATION __PRETTY_FUNCTION__
00525   #else
00526     #define ITK_LOCATION __FUNCTION__
00527   #endif
00528 #else
00529   #define ITK_LOCATION "unknown"
00530 #endif
00531 
00532 #include "itkExceptionObject.h"
00533 
00537 #define itkExceptionMacro(x) \
00538   { \
00539   ::itk::OStringStream message; \
00540   message << "itk::ERROR: " << this->GetNameOfClass() \
00541           << "(" << this << "): " x; \
00542   ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00543   throw e_; /* Explicit naming to work around Intel compiler bug.  */ \
00544   }
00545 
00546 
00547 #define itkGenericExceptionMacro(x) \
00548   { \
00549   ::itk::OStringStream message; \
00550   message << "itk::ERROR: " x; \
00551   ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00552   throw e_; /* Explicit naming to work around Intel compiler bug.  */ \
00553   }
00554 
00555 #ifdef ITK_LEAN_AND_MEAN
00556 #define itkGenericOutputMacro(x)
00557 #else
00558 #define itkGenericOutputMacro(x) \
00559 { if (::itk::Object::GetGlobalWarningDisplay()) \
00560     { ::itk::OStringStream itkmsg; \
00561       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00562              x << "\n\n"; \
00563       itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str());} \
00564 }
00565 #endif
00566 
00567 
00568 
00569 //----------------------------------------------------------------------------
00570 // Macros for simplifying the use of logging
00571 //
00572 #define itkLogMacro( x, y)  \
00573 {         \
00574   if (this->GetLogger() ) \
00575     {  \
00576     this->GetLogger()->Write(::itk::LoggerBase::x, y); \
00577     }  \
00578 }
00579 
00580 
00581 #define itkLogMacroStatic( obj, x, y)  \
00582 {         \
00583   if (obj->GetLogger() ) \
00584     {  \
00585     obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
00586     }  \
00587 }
00588 
00589 
00590 //----------------------------------------------------------------------------
00591 // Setup legacy code policy.
00592 
00593 // Define itkLegacy macro to mark legacy methods where they are
00594 // declared in their class.  Example usage:
00595 //
00596 //   // @deprecated Replaced by MyOtherMethod() as of ITK 2.0.
00597 //   itkLegacy(void MyMethod());
00598 #if defined(ITK_LEGACY_REMOVE)
00599   // Remove legacy methods completely.
00600 # define itkLegacy(method)
00601 #elif defined(ITK_LEGACY_SILENT) || defined(ITK_WRAPPING_CXX)
00602   // Provide legacy methods with no warnings.
00603 # define itkLegacy(method) method
00604 #else
00605   // Setup compile-time warnings for uses of deprecated methods if
00606   // possible on this compiler.
00607 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00608 #  define itkLegacy(method) method __attribute__((deprecated))
00609 # elif defined(_MSC_VER) && _MSC_VER >= 1300
00610 #  define itkLegacy(method) __declspec(deprecated) method
00611 # else
00612 #  define itkLegacy(method) method
00613 # endif
00614 #endif
00615 
00616 // Macros to create runtime deprecation warning messages in function
00617 // bodies.  Example usage:
00618 //
00619 //   void itkMyClass::MyOldMethod()
00620 //   {
00621 //     itkLegacyBody(itkMyClass::MyOldMethod, 2.0);
00622 //   }
00623 //
00624 //   void itkMyClass::MyMethod()
00625 //   {
00626 //     itkLegacyReplaceBody(itkMyClass::MyMethod, 2.0,
00627 //                          itkMyClass::MyOtherMethod);
00628 //   }
00629 #if defined(ITK_LEGACY_REMOVE) || defined(ITK_LEGACY_SILENT)
00630 # define itkLegacyBody(method, version)
00631 # define itkLegacyReplaceBody(method, version, replace)
00632 #else
00633 # define itkLegacyBody(method, version) \
00634   itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00635 # define itkLegacyReplaceBody(method, version, replace) \
00636   itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.  Use " #replace " instead.")
00637 #endif
00638 
00639 #if defined(__INTEL_COMPILER)
00640 # pragma warning (disable: 193) /* #if testing undefined identifier */
00641 #endif
00642 
00643 //=============================================================================
00644 /* Choose a way to prevent template instantiation on this platform.
00645   - ITK_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
00646                                       prevent instantiation
00647   - ITK_TEMPLATE_EXTERN = use extern template to prevent instantiation
00648 
00649    Note that VS 6 supports extern template instantiation but it is
00650    hard to block the resulting warning because its stream headers
00651    re-enable it.  Therefore we just disable support for now.
00652 */
00653 #if defined(__sgi) && defined(_COMPILER_VERSION)
00654 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 1
00655 #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
00656 # define ITK_TEMPLATE_EXTERN 1
00657 #elif defined(__GNUC__) && __GNUC__ >= 3
00658 # define ITK_TEMPLATE_EXTERN 1
00659 #elif defined(_MSC_VER) && _MSC_VER >= 1300
00660 # define ITK_TEMPLATE_EXTERN 1
00661 #endif
00662 #if !defined(ITK_TEMPLATE_DO_NOT_INSTANTIATE)
00663 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
00664 #endif
00665 #if !defined(ITK_TEMPLATE_EXTERN)
00666 # define ITK_TEMPLATE_EXTERN 0
00667 #endif
00668 
00669 /* Define a macro to explicitly instantiate a template.
00670   - ITK_TEMPLATE_EXPORT(X) =
00671       Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
00672       examples: ITK_TEMPLATE_EXPORT(1(class Foo<int>))
00673                 ITK_TEMPLATE_EXPORT(2(class Bar<int, char>))
00674       Use one level of expansion delay to allow user code to have
00675       a macro determining the number of arguments. */
00676 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
00677 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
00678 
00679 /* Define a macro to prevent template instantiations.
00680   - ITK_TEMPLATE_IMPORT(X) =
00681       Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
00682       examples: ITK_TEMPLATE_IMPORT(1(class Foo<int>))
00683                 ITK_TEMPLATE_IMPORT(2(class Bar<int, char>))
00684       Use one level of expansion delay to allow user code to have
00685       a macro determining the number of arguments.
00686 */
00687 #if ITK_TEMPLATE_EXTERN
00688 # define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
00689 # if defined(_MSC_VER)
00690 #  pragma warning (disable: 4231) /* extern template extension */
00691 # endif
00692 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
00693 # define ITK_TEMPLATE_IMPORT_DELAY(x) \
00694          ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
00695 # define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00696 #endif
00697 #if defined(ITK_TEMPLATE_IMPORT_DELAY)
00698 # define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
00699 # define ITK_TEMPLATE_IMPORT_WORKS 1
00700 #else
00701 # define ITK_TEMPLATE_IMPORT(x)
00702 # define ITK_TEMPLATE_IMPORT_WORKS 0
00703 #endif
00704 
00705 /* Define macros to export and import template instantiations.  These
00706    depend on each class providing a macro defining the instantiations
00707    given template arguments in X.  The argument X is of the form
00708    N(a1[,a2...,aN]).  The argument Y is a valid preprocessing token
00709    unique to the template arguments given in X.  Typical usage is
00710 
00711      ITK_EXPORT_TEMPLATE(itkfoo_EXPORT, Foo, (int), I)
00712      ITK_EXPORT_TEMPLATE(itkfoo_EXPORT, Bar, (int, char), IC)
00713 
00714    The ITK_TEMPLATE_<name> macro should be defined in itk<name>.h and
00715    is of the following form:
00716 
00717      #define ITK_TEMPLATE_<name>(_, EXPORT, x, y) namespace itk { \
00718        _(<n>(class EXPORT <name>< ITK_TEMPLATE_<n> x >)) \
00719        namespace Templates { typedef <name>< ITK_TEMPLATE_<n> x > <name>##y; }\
00720      }
00721 
00722    The argument "_" will be replaced by another macro such as
00723    ITK_TEMPLATE_EXPORT or ITK_TEMPLATE_IMPORT, so it should be used as
00724    if calling one of these macros.  The argument "EXPORT" will be
00725    replaced by a dllexport/dllimport macro such as ITKCommon_EXPORT.
00726    The argument "x" is a paren-enclosed list of template arguments.
00727    The argument "y" is a preprocessing token corresponding to the
00728    given template arguments and should be used to construct typedef
00729    names for the instantiations.
00730 
00731    Note the use of ITK_TEMPLATE_<n>, where <n> is the number of
00732    template arguments for the class template.  Note also that the
00733    number of template arguments is usually the length of the list
00734    nested within the inner parentheses, so the instantiation is listed
00735    with the form <n>(...).  Example definitions:
00736 
00737      #define ITK_TEMPLATE_Foo(_, EXPORT, x, y) namespace itk { \
00738        _(1(class EXPORT Foo< ITK_TEMPLATE_1 x >)) \
00739        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00740                                            const Foo< ITK_TEMPLATE_1 x >&))) \
00741        namespace Templates { typedef Foo< ITK_TEMPLATE_1 x > Foo##y; }\
00742      }
00743 
00744      #define ITK_TEMPLATE_Bar(_, EXPORT, x, y) namespace itk { \
00745        _(2(class EXPORT Bar< ITK_TEMPLATE_2 x >)) \
00746        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00747                                            const Bar< ITK_TEMPLATE_2 x >&))) \
00748        namespace Templates { typedef Bar< ITK_TEMPLATE_2 x > Bar##y; }\
00749      }
00750 
00751    Note that in the stream operator for template Bar there is a "1" at
00752    the beginning even though two arguments are taken.  This is because
00753    the expression "ITK_TEMPLATE_2 x" is contained inside the
00754    parentheses of the function signature which protects the resulting
00755    comma from separating macro arguments.  Therefore the nested
00756    parentheses contain a list of only one macro argument.
00757 
00758    The ITK_EMPTY macro used in these definitions is a hack to work
00759    around a VS 6.0 preprocessor bug when EXPORT is empty.
00760 */
00761 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \
00762         ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y)
00763 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \
00764         ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y)
00765 #define ITK_EMPTY
00766 
00767 /* Define macros to support passing a variable number of arguments
00768    throug other macros.  This is used by ITK_TEMPLATE_EXPORT,
00769    ITK_TEMPLATE_IMPORT, and by each template's instantiation
00770    macro.  */
00771 #define ITK_TEMPLATE_1(x1)                         x1
00772 #define ITK_TEMPLATE_2(x1,x2)                      x1,x2
00773 #define ITK_TEMPLATE_3(x1,x2,x3)                   x1,x2,x3
00774 #define ITK_TEMPLATE_4(x1,x2,x3,x4)                x1,x2,x3,x4
00775 #define ITK_TEMPLATE_5(x1,x2,x3,x4,x5)             x1,x2,x3,x4,x5
00776 #define ITK_TEMPLATE_6(x1,x2,x3,x4,x5,x6)          x1,x2,x3,x4,x5,x6
00777 #define ITK_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7)       x1,x2,x3,x4,x5,x6,x7
00778 #define ITK_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8)    x1,x2,x3,x4,x5,x6,x7,x8
00779 #define ITK_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
00780 
00781 /* In order to support both implicit and explicit instantation a .h
00782    file needs to know whether it should include its .txx file
00783    containing the template definitions.  Define a macro to tell
00784    it.  Typical usage in itkFoo.h:
00785      #if ITK_TEMPLATE_TXX
00786      # include "itkFoo.txx"
00787      #endif
00788 */
00789 #if defined(ITK_MANUAL_INSTANTIATION)
00790 # define ITK_TEMPLATE_TXX 0
00791 #else
00792 # define ITK_TEMPLATE_TXX !(ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE)
00793 #endif
00794 
00795 /* All explicit instantiation source files define ITK_TEMPLATE_CXX.
00796    Define ITK_MANUAL_INSTANTIATION to tell .h files that have not been
00797    converted to this explicit instantiation scheme to not include
00798    their .txx files.  Also disable warnings that commonly occur in
00799    these files but are not useful.  */
00800 #if ITK_TEMPLATE_CXX
00801 # undef ITK_MANUAL_INSTANTIATION
00802 # define ITK_MANUAL_INSTANTIATION
00803 # if defined(_MSC_VER)
00804 #  pragma warning (disable: 4275) /* non dll-interface base */
00805 #  pragma warning (disable: 4661) /* no definition available */
00806 # endif
00807 #endif
00808 //=============================================================================
00809 
00810 /* Define macros to export and import template instantiations for each
00811    library in ITK.  */
00812 #define ITK_EXPORT_ITKCommon(c, x, n) \
00813         ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00814 #define ITK_IMPORT_ITKCommon(c, x, n) \
00815         ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00816 
00817 /* Define a macro to decide whether to block instantiation of ITK
00818    templates.  They should be blocked only if the platform supports
00819    blocking template instantiation and the explicit instantiations are
00820    available.
00821 
00822    - ITK_TEMPLATE_EXPLICIT =
00823       Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
00824       instantiations of templates explicitly instantiated elsewhere.
00825       Typical usage in itkFoo.h:
00826         #if ITK_TEMPLATE_EXPLICIT
00827         # include "itkFoo+-.h"
00828         #endif
00829 */
00830 #if ITK_TEMPLATE_IMPORT_WORKS && defined(ITK_EXPLICIT_INSTANTIATION)
00831 # define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX
00832 #else
00833 # define ITK_TEMPLATE_EXPLICIT 0
00834 #endif
00835 
00836 #endif //end of itkMacro.h
00837 

Generated at Mon Mar 12 01:33:42 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000