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: 2009-02-05 19:05:01 $
00007   Version:   $Revision: 1.89 $
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 #include <cstdlib>
00038 
00039 // Determine type of string stream to use.
00040 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
00041 #  include <sstream>
00042 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
00043 #  include <strstream>
00044 #  define ITK_NO_ANSI_STRING_STREAM
00045 #else
00046 #  include <strstream.h>
00047 #  define ITK_NO_ANSI_STRING_STREAM
00048 #endif
00049 
00054 namespace itk
00055 {
00056 } // end namespace itk - this is here for documentation purposes
00057 
00060 #define itkNotUsed(x)
00061 
00076 #if defined(_MSC_VER) && (_MSC_VER <= 1300) 
00077 #   define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00078 #endif
00079 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x540)
00080 #   define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00081 #endif
00082 #if defined(__SVR4) && !defined(__SUNPRO_CC)
00083 #   define ITK_NO_INCLASS_MEMBER_INITIALIZATION
00084 #endif
00085 
00086 // A class template like this will not instantiate on GCC 2.95:
00087 //   template<class T> struct A
00088 //   {
00089 //     static const int N = 1;
00090 //     enum { S = sizeof(A::N) };
00091 //   };
00092 // We need to use enum for static constants instead.
00093 #if defined(__GNUC__)
00094 # define ITK_NO_SIZEOF_CONSTANT_LOOKUP
00095 #endif
00096 
00097 #if defined(_MSC_VER) && (_MSC_VER <= 1300) 
00098 #define ITK_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
00099 #endif
00100 
00101 #if defined(ITK_NO_INCLASS_MEMBER_INITIALIZATION) || \
00102     defined(ITK_NO_SIZEOF_CONSTANT_LOOKUP)
00103 #   define itkStaticConstMacro(name,type,value) enum { name = value }
00104 #else
00105 #   define itkStaticConstMacro(name,type,value) static const type name = value
00106 #endif
00107 
00108 #ifdef ITK_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
00109 #   define itkGetStaticConstMacro(name) name
00110 #else
00111 #   define itkGetStaticConstMacro(name) (Self::name)
00112 #endif
00113 
00115 #define itkSetInputMacro(name, type, number) \
00116   virtual void Set##name##Input(const type *_arg) \
00117   { \
00118     itkDebugMacro("setting input " #name " to " << _arg); \
00119     if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \
00120       { \
00121       this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \
00122       this->Modified(); \
00123       } \
00124   } \
00125   virtual void SetInput##number(const type *_arg) \
00126   { \
00127     itkDebugMacro("setting input " #number " to " << _arg); \
00128     if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \
00129       { \
00130       this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \
00131       this->Modified(); \
00132       } \
00133   } 
00134 
00135 
00137 #define itkSuperclassTraitMacro(traitnameType) \
00138   typedef typename Superclass::traitnameType traitnameType;
00139 
00141 #define itkGetInputMacro(name, type, number) \
00142   virtual const type * Get##name##Input() const \
00143   { \
00144     itkDebugMacro("returning input " << #name " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
00145     return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
00146   } \
00147   virtual const type * GetInput##number() const \
00148   { \
00149     itkDebugMacro("returning input " << #number " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
00150     return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
00151   } 
00152 
00153 
00156 #define itkSetDecoratedInputMacro(name, type, number) \
00157   itkSetInputMacro(name, SimpleDataObjectDecorator<type>, number); \
00158   itkGetInputMacro(name, SimpleDataObjectDecorator<type>, number); \
00159   virtual void Set##name(const type &_arg) \
00160   { \
00161     typedef SimpleDataObjectDecorator< type > DecoratorType; \
00162     itkDebugMacro("setting input " #name " to " << _arg); \
00163     const DecoratorType * oldInput = \
00164       static_cast< const DecoratorType * >( \
00165         this->ProcessObject::GetInput(number) ); \
00166     if( oldInput && oldInput->Get() == _arg ) \
00167       { \
00168       return; \
00169       } \
00170     typename DecoratorType::Pointer newInput = DecoratorType::New(); \
00171     newInput->Set( _arg ); \
00172     this->Set##name##Input( newInput ); \
00173   }
00174 
00175 
00179 #define itkSetDecoratedObjectInputMacro(name, type, number) \
00180   itkSetInputMacro(name, DataObjectDecorator<type>, number); \
00181   itkGetInputMacro(name, DataObjectDecorator<type>, number); \
00182   virtual void Set##name(const type *_arg) \
00183   { \
00184     typedef DataObjectDecorator< type > DecoratorType; \
00185     itkDebugMacro("setting input " #name " to " << _arg); \
00186     const DecoratorType * oldInput = \
00187       static_cast< const DecoratorType * >( \
00188         this->ProcessObject::GetInput(number) ); \
00189     if( oldInput && oldInput->Get() == _arg ) \
00190       { \
00191       return; \
00192       } \
00193     typename DecoratorType::Pointer newInput = DecoratorType::New(); \
00194     newInput->Set( _arg ); \
00195     this->Set##name##Input( newInput ); \
00196   }
00197 
00198 
00199 
00201 #define itkSetMacro(name,type) \
00202   virtual void Set##name (const type _arg) \
00203   { \
00204     itkDebugMacro("setting " #name " to " << _arg); \
00205     if (this->m_##name != _arg) \
00206       { \
00207       this->m_##name = _arg; \
00208       this->Modified(); \
00209       } \
00210   } 
00211 
00212 
00214 #define itkGetMacro(name,type) \
00215   virtual type Get##name () \
00216   { \
00217     itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00218     return this->m_##name; \
00219   }
00220 
00221 
00225 #define itkGetConstMacro(name,type) \
00226   virtual type Get##name () const \
00227   { \
00228     itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00229     return this->m_##name; \
00230   }
00231 
00232 
00237 #define itkGetConstReferenceMacro(name,type) \
00238   virtual const type & Get##name () const \
00239   { \
00240     itkDebugMacro("returning " << #name " of " << this->m_##name ); \
00241     return this->m_##name; \
00242   }
00243 
00244 
00249 #define itkSetEnumMacro(name,type) \
00250   virtual void Set##name (const type _arg) \
00251   { \
00252     itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
00253     if (this->m_##name != _arg) \
00254       { \
00255       this->m_##name = _arg; \
00256       this->Modified(); \
00257       } \
00258   } 
00259 
00260 
00265 #define itkGetEnumMacro(name,type) \
00266   virtual type Get##name () const \
00267   { \
00268     itkDebugMacro("returning " << #name " of " << static_cast<long>(this->m_##name) ); \
00269     return this->m_##name; \
00270   }
00271 
00272 
00276 #define itkSetStringMacro(name) \
00277   virtual void Set##name (const char* _arg) \
00278   { \
00279     if ( _arg && (_arg == this->m_##name) ) { return;} \
00280     if (_arg) \
00281       { \
00282       this->m_##name = _arg;\
00283       } \
00284      else \
00285       { \
00286       this->m_##name = ""; \
00287       } \
00288     this->Modified(); \
00289   } \
00290   virtual void Set##name (const std::string & _arg) \
00291   { \
00292     this->Set##name( _arg.c_str() ); \
00293   } \
00294 
00295 
00296 
00300 #define itkGetStringMacro(name) \
00301   virtual const char* Get##name () const \
00302   { \
00303     return this->m_##name.c_str(); \
00304   }
00305 
00309 #define itkSetClampMacro(name,type,min,max) \
00310   virtual void Set##name (type _arg) \
00311   { \
00312     itkDebugMacro("setting " << #name " to " << _arg ); \
00313     if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
00314       { \
00315       this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
00316       this->Modified(); \
00317       } \
00318   } 
00319 
00320 
00325 #define itkSetObjectMacro(name,type) \
00326   virtual void Set##name (type* _arg) \
00327   { \
00328     itkDebugMacro("setting " << #name " to " << _arg ); \
00329     if (this->m_##name != _arg) \
00330       { \
00331       this->m_##name = _arg; \
00332       this->Modified(); \
00333       } \
00334   } 
00335 
00336 
00339 #define itkGetObjectMacro(name,type) \
00340   virtual type * Get##name () \
00341   { \
00342     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00343     return this->m_##name.GetPointer(); \
00344   } 
00345 
00346 
00351 #define itkSetConstObjectMacro(name,type) \
00352   virtual void Set##name (const type* _arg) \
00353   { \
00354     itkDebugMacro("setting " << #name " to " << _arg ); \
00355     if (this->m_##name != _arg) \
00356       { \
00357       this->m_##name = _arg; \
00358       this->Modified(); \
00359       } \
00360   } 
00361 
00362 
00363 
00366 #define itkGetConstObjectMacro(name,type) \
00367   virtual const type * Get##name () const \
00368   { \
00369     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00370     return this->m_##name.GetPointer(); \
00371   } 
00372 
00373 
00376 #define itkGetConstReferenceObjectMacro(name,type) \
00377   virtual const typename type::Pointer & Get##name () const \
00378   { \
00379     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00380     return this->m_##name; \
00381   } 
00382 
00383 
00386 #define itkBooleanMacro(name) \
00387   virtual void name##On () { this->Set##name(true);} \
00388   virtual void name##Off () { this->Set##name(false);}
00389 
00390 
00394 #define itkSetVectorMacro(name,type,count) \
00395   virtual void Set##name(type data[]) \
00396   { \
00397     unsigned int i; \
00398     for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
00399     if ( i < count ) \
00400       { \
00401       this->Modified(); \
00402       for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
00403       } \
00404   }
00405 
00406 
00409 #define itkGetVectorMacro(name,type,count) \
00410   virtual type *Get##name () const \
00411   { \
00412     return this->m_##name; \
00413   } 
00414 
00431 #define itkNewMacro(x) \
00432 static Pointer New(void) \
00433 { \
00434   Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
00435   if(smartPtr.GetPointer() == NULL) \
00436     { \
00437     smartPtr = new x; \
00438     } \
00439   smartPtr->UnRegister(); \
00440   return smartPtr; \
00441 } \
00442 virtual ::itk::LightObject::Pointer CreateAnother(void) const \
00443 { \
00444   ::itk::LightObject::Pointer smartPtr; \
00445   smartPtr = x::New().GetPointer(); \
00446   return smartPtr; \
00447 }
00448 
00449 
00450 
00467 #define itkFactorylessNewMacro(x) \
00468 static Pointer New(void) \
00469 { \
00470   Pointer smartPtr; \
00471   x *rawPtr = new x; \
00472   smartPtr = rawPtr; \
00473   rawPtr->UnRegister(); \
00474   return smartPtr; \
00475 } \
00476   virtual ::itk::LightObject::Pointer CreateAnother(void) const \
00477 { \
00478   ::itk::LightObject::Pointer smartPtr;         \
00479   smartPtr = x::New().GetPointer(); \
00480   return smartPtr; \
00481 }
00482 
00483 
00486 #define itkTypeMacro(thisClass,superclass) \
00487     virtual const char *GetNameOfClass() const \
00488         {return #thisClass;} 
00489 
00490 
00491 namespace itk
00492 {
00499 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char*);
00500 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char*);
00501 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char*);
00502 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char*);
00503 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char*);
00504 } // end namespace itk
00506 
00510 #if defined(ITK_LEAN_AND_MEAN) || defined(__BORLANDC__) || defined(NDEBUG)
00511 #define itkDebugMacro(x)
00512 #else
00513 #define itkDebugMacro(x) \
00514   { if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay())   \
00515     { ::itk::OStringStream itkmsg; \
00516       itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00517              << this->GetNameOfClass() << " (" << this << "): " x  \
00518              << "\n\n"; \
00519       ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str());} \
00520 }
00521 #endif
00522 
00523 
00524 
00528 #ifdef ITK_LEAN_AND_MEAN
00529 #define itkWarningMacro(x)
00530 #else
00531 #define itkWarningMacro(x) \
00532 { if (::itk::Object::GetGlobalWarningDisplay()) \
00533     { ::itk::OStringStream itkmsg; \
00534       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00535              << this->GetNameOfClass() << " (" << this << "): " x  \
00536              << "\n\n"; \
00537       ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str());} \
00538 }
00539 #endif
00540 
00541 
00542 namespace itk
00543 {
00544 
00550 #if !defined(ITK_NO_ANSI_STRING_STREAM)
00551 class OStringStream: public std::ostringstream
00552 {
00553 public:
00554   OStringStream() {}
00555 private:
00556   OStringStream(const OStringStream&);
00557   void operator=(const OStringStream&);
00558 };
00559 #else
00560 namespace OStringStreamDetail
00561 {
00562   class Cleanup
00563   {
00564   public:
00565     Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
00566     ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
00567     static void IgnoreUnusedVariable(const Cleanup&) {}
00568   protected:
00569     std::ostrstream& m_OStrStream;
00570   };
00571 }//namespace OStringStreamDetail
00573 
00574 class OStringStream: public std::ostrstream
00575 {
00576 public:
00577   typedef std::ostrstream Superclass;
00578   OStringStream() {}
00579   std::string str()
00580     {
00581       OStringStreamDetail::Cleanup cleanup(*this);
00582       OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
00583       int pcount = this->pcount();
00584       const char* ptr = this->Superclass::str();
00585       return std::string(ptr?ptr:"", pcount);
00586     }
00587 private:
00588   OStringStream(const OStringStream&);
00589   void operator=(const OStringStream&);
00590 };
00591 #endif
00592 
00593 }//namespace itk
00594 
00595 #if defined(ITK_CPP_FUNCTION)
00596   #if defined(__BORLANDC__)
00597     #define ITK_LOCATION __FUNC__
00598   #elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(CABLE_CONFIGURATION) && !defined(CSWIG)
00599     #define ITK_LOCATION __FUNCSIG__
00600   #elif defined(__GNUC__)
00601     #define ITK_LOCATION __PRETTY_FUNCTION__
00602   #else
00603     #define ITK_LOCATION __FUNCTION__
00604   #endif
00605 #else
00606   #define ITK_LOCATION "unknown"
00607 #endif
00608 
00609 #include "itkExceptionObject.h"
00610 
00614 #define itkExceptionMacro(x) \
00615   { \
00616   ::itk::OStringStream message; \
00617   message << "itk::ERROR: " << this->GetNameOfClass() \
00618           << "(" << this << "): " x; \
00619   ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00620   throw e_; /* Explicit naming to work around Intel compiler bug.  */ \
00621   }
00622 
00623 
00624 #define itkGenericExceptionMacro(x) \
00625   { \
00626   ::itk::OStringStream message; \
00627   message << "itk::ERROR: " x; \
00628   ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00629   throw e_; /* Explicit naming to work around Intel compiler bug.  */ \
00630   }
00631 
00632 #ifdef ITK_LEAN_AND_MEAN
00633 #define itkGenericOutputMacro(x)
00634 #else
00635 #define itkGenericOutputMacro(x) \
00636 { if (::itk::Object::GetGlobalWarningDisplay()) \
00637     { ::itk::OStringStream itkmsg; \
00638       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00639              x << "\n\n"; \
00640       ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str());} \
00641 }
00642 #endif
00643 
00644 //----------------------------------------------------------------------------
00645 // Macros for simplifying the use of logging
00646 //
00647 #define itkLogMacro( x, y)  \
00648 {         \
00649   if (this->GetLogger() ) \
00650     {  \
00651     this->GetLogger()->Write(::itk::LoggerBase::x, y); \
00652     }  \
00653 }
00654 
00655 
00656 #define itkLogMacroStatic( obj, x, y)  \
00657 {         \
00658   if (obj->GetLogger() ) \
00659     {  \
00660     obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
00661     }  \
00662 }
00663 
00664 
00665 //----------------------------------------------------------------------------
00666 // Setup legacy code policy.
00667 //
00668 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted
00669 // to definitions (or non-defs) in itkConfigure.h and tested below.
00670 // They may be used to completely remove legacy code or silence the
00671 // warnings.  The default is to warn about their use.
00672 //
00673 // Source files that test the legacy code may define ITK_LEGACY_TEST
00674 // like this:
00675 //
00676 //  #define ITK_LEGACY_TEST
00677 //  #include "itkClassWithDeprecatedMethod.h"
00678 //
00679 // in order to silence the warnings for calling deprecated methods.
00680 // No other source files in ITK should call the methods since they are
00681 // provided only for compatibility with older user code.
00682 
00683 // Define itkLegacyMacro to mark legacy methods where they are
00684 // declared in their class.  Example usage:
00685 //
00686 //   // @deprecated Replaced by MyOtherMethod() as of ITK 2.0.
00687 //   itkLegacyMacro(void MyMethod());
00688 #if defined(ITK_LEGACY_REMOVE)
00689 // Remove legacy methods completely.  Put a bogus declaration in
00690 // place to avoid stray semicolons because this is an error for some
00691 // compilers.  Using a class forward declaration allows any number
00692 // of repeats in any context without generating unique names.
00693 # define itkLegacyMacro(method) class itkLegacyMethodRemoved /* no ';' */
00694 #elif defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST) || defined(CSWIG)
00695   // Provide legacy methods with no warnings.
00696 # define itkLegacyMacro(method) method
00697 #else
00698   // Setup compile-time warnings for uses of deprecated methods if
00699   // possible on this compiler.
00700 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00701 #  define itkLegacyMacro(method) method __attribute__((deprecated))
00702 # elif defined(_MSC_VER) && _MSC_VER >= 1300
00703 #  define itkLegacyMacro(method) __declspec(deprecated) method
00704 # else
00705 #  define itkLegacyMacro(method) method
00706 # endif
00707 #endif
00708 
00709 // Macros to create runtime deprecation warning messages in function
00710 // bodies.  Example usage:
00711 //
00712 //   void itkMyClass::MyOldMethod()
00713 //     {
00714 //     itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
00715 //     }
00716 //
00717 //   void itkMyClass::MyMethod()
00718 //     {
00719 //     itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
00720 //                               itkMyClass::MyOtherMethod);
00721 //     }
00722 #if defined(ITK_LEGACY_REMOVE) || defined(ITK_LEGACY_SILENT)
00723 # define itkLegacyBodyMacro(method, version)
00724 # define itkLegacyReplaceBodyMacro(method, version, replace)
00725 # define itkGenericLegacyBodyMacro(method, version)
00726 # define itkGenericLegacyReplaceBodyMacro(method, version, replace)
00727 #else
00728 # define itkLegacyBodyMacro(method, version) \
00729   itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00730 # define itkLegacyReplaceBodyMacro(method, version, replace) \
00731   itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.  Use " #replace " instead.")
00732 # define itkGenericLegacyBodyMacro(method, version) \
00733   itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00734 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
00735   itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.  Use " #replace " instead.")
00736 #endif
00737 
00738 #if defined(__INTEL_COMPILER)
00739 # pragma warning (disable: 193) /* #if testing undefined identifier */
00740 #endif
00741 
00742 //=============================================================================
00743 /* Define a common way of declaring a templated function as a friend inside a class.
00744   - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T) 
00745 
00746   The following templated function 
00747 
00748             template <T>
00749             T add(const T & a, const T & b);
00750 
00751   is declared as friend in some compilers as:
00752 
00753             class A
00754               {
00755               public:
00756                 friend Self add<Self>( const Self & a, const Self & b );
00757               }
00758 
00759    while other compilers will do
00760 
00761             class A
00762               {
00763               public:
00764                 friend Self add<>( const Self & a, const Self & b );
00765               }
00766 
00767    This characteristic of the compiler is checked by a TRY_COMPILE
00768    command defined in Insight/CMake/itkTestFriendTemplatedFunction.cxx
00769 
00770 */
00771 #if defined(ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_NULL_STRING)
00772 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
00773 #else
00774 #if defined(ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_EMPTY_BRACKETS)
00775 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)  <>
00776 #else
00777 #if defined(ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_TEMPLATE_ARGUMENTS)
00778 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)  <T>
00779 #endif
00780 #endif
00781 #endif
00782 
00783 
00784 //=============================================================================
00785 /* Choose a way to prevent template instantiation on this platform.
00786   - ITK_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
00787                                       prevent instantiation
00788   - ITK_TEMPLATE_EXTERN = use extern template to prevent instantiation
00789 
00790    Note that VS 6 supports extern template instantiation but it is
00791    hard to block the resulting warning because its stream headers
00792    re-enable it.  Therefore we just disable support for now.
00793 */
00794 #if defined(__sgi) && defined(_COMPILER_VERSION)
00795 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 1
00796 #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
00797 # define ITK_TEMPLATE_EXTERN 1
00798 #elif defined(__GNUC__) && __GNUC__ >= 3
00799 # define ITK_TEMPLATE_EXTERN 1
00800 #elif defined(_MSC_VER) && _MSC_VER >= 1300
00801 # define ITK_TEMPLATE_EXTERN 1
00802 #endif
00803 #if !defined(ITK_TEMPLATE_DO_NOT_INSTANTIATE)
00804 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
00805 #endif
00806 #if !defined(ITK_TEMPLATE_EXTERN)
00807 # define ITK_TEMPLATE_EXTERN 0
00808 #endif
00809 
00810 /* Define a macro to explicitly instantiate a template.
00811   - ITK_TEMPLATE_EXPORT(X) =
00812       Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
00813       examples: ITK_TEMPLATE_EXPORT(1(class Foo<int>))
00814                 ITK_TEMPLATE_EXPORT(2(class Bar<int, char>))
00815       Use one level of expansion delay to allow user code to have
00816       a macro determining the number of arguments. */
00817 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
00818 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
00819 
00820 /* Define a macro to prevent template instantiations.
00821   - ITK_TEMPLATE_IMPORT(X) =
00822       Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
00823       examples: ITK_TEMPLATE_IMPORT(1(class Foo<int>))
00824                 ITK_TEMPLATE_IMPORT(2(class Bar<int, char>))
00825       Use one level of expansion delay to allow user code to have
00826       a macro determining the number of arguments.
00827 */
00828 #if ITK_TEMPLATE_EXTERN
00829 # define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
00830 # if defined(_MSC_VER)
00831 #  pragma warning (disable: 4231) /* extern template extension */
00832 # endif
00833 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
00834 # define ITK_TEMPLATE_IMPORT_DELAY(x) \
00835          ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
00836 # define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00837 #endif
00838 #if defined(ITK_TEMPLATE_IMPORT_DELAY)
00839 # define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
00840 # define ITK_TEMPLATE_IMPORT_WORKS 1
00841 #else
00842 # define ITK_TEMPLATE_IMPORT(x)
00843 # define ITK_TEMPLATE_IMPORT_WORKS 0
00844 #endif
00845 
00846 /* Define macros to export and import template instantiations.  These
00847    depend on each class providing a macro defining the instantiations
00848    given template arguments in X.  The argument X is of the form
00849    N(a1[,a2...,aN]).  The argument Y is a valid preprocessing token
00850    unique to the template arguments given in X.  Typical usage is
00851 
00852      ITK_EXPORT_TEMPLATE(itkfoo_EXPORT, Foo, (int), I)
00853      ITK_EXPORT_TEMPLATE(itkfoo_EXPORT, Bar, (int, char), IC)
00854 
00855    The ITK_TEMPLATE_<name> macro should be defined in itk<name>.h and
00856    is of the following form:
00857 
00858      #define ITK_TEMPLATE_<name>(_, EXPORT, x, y) namespace itk { \
00859        _(<n>(class EXPORT <name>< ITK_TEMPLATE_<n> x >)) \
00860        namespace Templates { typedef <name>< ITK_TEMPLATE_<n> x > <name>##y; }\
00861      }
00862 
00863    The argument "_" will be replaced by another macro such as
00864    ITK_TEMPLATE_EXPORT or ITK_TEMPLATE_IMPORT, so it should be used as
00865    if calling one of these macros.  The argument "EXPORT" will be
00866    replaced by a dllexport/dllimport macro such as ITKCommon_EXPORT.
00867    The argument "x" is a paren-enclosed list of template arguments.
00868    The argument "y" is a preprocessing token corresponding to the
00869    given template arguments and should be used to construct typedef
00870    names for the instantiations.
00871 
00872    Note the use of ITK_TEMPLATE_<n>, where <n> is the number of
00873    template arguments for the class template.  Note also that the
00874    number of template arguments is usually the length of the list
00875    nested within the inner parentheses, so the instantiation is listed
00876    with the form <n>(...).  Example definitions:
00877 
00878      #define ITK_TEMPLATE_Foo(_, EXPORT, x, y) namespace itk { \
00879        _(1(class EXPORT Foo< ITK_TEMPLATE_1 x >)) \
00880        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00881                                            const Foo< ITK_TEMPLATE_1 x >&))) \
00882        namespace Templates { typedef Foo< ITK_TEMPLATE_1 x > Foo##y; }\
00883      }
00884 
00885      #define ITK_TEMPLATE_Bar(_, EXPORT, x, y) namespace itk { \
00886        _(2(class EXPORT Bar< ITK_TEMPLATE_2 x >)) \
00887        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00888                                            const Bar< ITK_TEMPLATE_2 x >&))) \
00889        namespace Templates { typedef Bar< ITK_TEMPLATE_2 x > Bar##y; }\
00890      }
00891 
00892    Note that in the stream operator for template Bar there is a "1" at
00893    the beginning even though two arguments are taken.  This is because
00894    the expression "ITK_TEMPLATE_2 x" is contained inside the
00895    parentheses of the function signature which protects the resulting
00896    comma from separating macro arguments.  Therefore the nested
00897    parentheses contain a list of only one macro argument.
00898 
00899    The ITK_EMPTY macro used in these definitions is a hack to work
00900    around a VS 6.0 preprocessor bug when EXPORT is empty.
00901 */
00902 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \
00903         ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y)
00904 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \
00905         ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y)
00906 #define ITK_EMPTY
00907 
00908 /* Define macros to support passing a variable number of arguments
00909    throug other macros.  This is used by ITK_TEMPLATE_EXPORT,
00910    ITK_TEMPLATE_IMPORT, and by each template's instantiation
00911    macro.  */
00912 #define ITK_TEMPLATE_1(x1)                         x1
00913 #define ITK_TEMPLATE_2(x1,x2)                      x1,x2
00914 #define ITK_TEMPLATE_3(x1,x2,x3)                   x1,x2,x3
00915 #define ITK_TEMPLATE_4(x1,x2,x3,x4)                x1,x2,x3,x4
00916 #define ITK_TEMPLATE_5(x1,x2,x3,x4,x5)             x1,x2,x3,x4,x5
00917 #define ITK_TEMPLATE_6(x1,x2,x3,x4,x5,x6)          x1,x2,x3,x4,x5,x6
00918 #define ITK_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7)       x1,x2,x3,x4,x5,x6,x7
00919 #define ITK_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8)    x1,x2,x3,x4,x5,x6,x7,x8
00920 #define ITK_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
00921 
00922 /* In order to support both implicit and explicit instantation a .h
00923    file needs to know whether it should include its .txx file
00924    containing the template definitions.  Define a macro to tell
00925    it.  Typical usage in itkFoo.h:
00926      #if ITK_TEMPLATE_TXX
00927      # include "itkFoo.txx"
00928      #endif
00929 */
00930 #if defined(ITK_MANUAL_INSTANTIATION)
00931 # define ITK_TEMPLATE_TXX 0
00932 #else
00933 # define ITK_TEMPLATE_TXX !(ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE)
00934 #endif
00935 
00936 /* All explicit instantiation source files define ITK_TEMPLATE_CXX.
00937    Define ITK_MANUAL_INSTANTIATION to tell .h files that have not been
00938    converted to this explicit instantiation scheme to not include
00939    their .txx files.  Also disable warnings that commonly occur in
00940    these files but are not useful.  */
00941 #if ITK_TEMPLATE_CXX
00942 # undef ITK_MANUAL_INSTANTIATION
00943 # define ITK_MANUAL_INSTANTIATION
00944 # if defined(_MSC_VER)
00945 #  pragma warning (disable: 4275) /* non dll-interface base */
00946 #  pragma warning (disable: 4661) /* no definition available */
00947 # endif
00948 #endif
00949 //=============================================================================
00950 
00951 /* Define macros to export and import template instantiations for each
00952    library in ITK.  */
00953 #define ITK_EXPORT_ITKCommon(c, x, n) \
00954         ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00955 #define ITK_IMPORT_ITKCommon(c, x, n) \
00956         ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00957 
00958 /* Define a macro to decide whether to block instantiation of ITK
00959    templates.  They should be blocked only if the platform supports
00960    blocking template instantiation and the explicit instantiations are
00961    available.
00962 
00963    - ITK_TEMPLATE_EXPLICIT =
00964       Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
00965       instantiations of templates explicitly instantiated elsewhere.
00966       Typical usage in itkFoo.h:
00967         #if ITK_TEMPLATE_EXPLICIT
00968         # include "itkFoo+-.h"
00969         #endif
00970 */
00971 #if ITK_TEMPLATE_IMPORT_WORKS && defined(ITK_EXPLICIT_INSTANTIATION)
00972 # define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX
00973 #else
00974 # define ITK_TEMPLATE_EXPLICIT 0
00975 #endif
00976 
00977 
00978 //----------------------------------------------------------------------------
00979 // Macro to declare that a function does not return. __attribute__((noreturn))
00980 //    On some compiler, functions that do not return (ex: exit(0)) must
00981 //    have the noreturn attribute. Otherwise, a warning is raised. Use
00982 //    that macro to avoid those warnings. GCC defines the attribute
00983 //    noreturn for versions 2.5 and higher.
00984 #if defined(__GNUC__)
00985 #  if (((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 3))
00986 #    define ITK_NO_RETURN \
00987        __attribute__ ((noreturn))
00988 #  endif
00989 #else
00990 #  define ITK_NO_RETURN
00991 #endif
00992 
00993 
00994 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
00995 //--------------------------------------------------------------------------------
00996 //  Helper macros for Template Meta-Programming techniques of for-loops unrolling
00997 //--------------------------------------------------------------------------------
00998 
00999 //--------------------------------------------------------------------------------
01000 // Macro that generates an unrolled for loop for assigning elements of one array
01001 // to elements of another array The array are assumed to be of same length
01002 // (dimension), and this is also assumed to be the value of NumberOfIterations.
01003 // No verification of size is performed. Casting is perfomed as part of the
01004 // assignment, by using the DestinationElementType as the casting type. 
01005 // Source and destination array types must have defined opearator[] in their API.
01006 #define itkFoorLoopAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
01007     for(unsigned int i=0;i < NumberOfIterations; ++i) \
01008       { \
01009       DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
01010       }
01011 
01012 //--------------------------------------------------------------------------------
01013 // Macro that generates an unrolled for loop for rounding and assigning
01014 // elements of one array to elements of another array The array are assumed to
01015 // be of same length (dimension), and this is also assumed to be the value of
01016 // NumberOfIterations.  No verification of size is performed. Casting is
01017 // perfomed as part of the assignment, by using the DestinationElementType as
01018 // the casting type. 
01019 // Source and destination array types must have defined opearator[] in their API.
01020 #define itkFoorLoopRoundingAndAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
01021     for(unsigned int i=0;i < NumberOfIterations; ++i) \
01022       { \
01023       DestinationArray[i] = static_cast< DestinationElementType >( vnl_math_rnd( SourceArray[i] ) ); \
01024       }
01025 
01026 #endif
01027 // end of Template Meta Programming helper macros
01028 
01029 
01030 #endif //end of itkMacro.h
01031 

Generated at Sat Feb 28 12:57:04 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000