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

Generated at Fri Sep 8 03:39:43 2006 for ITK by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2000