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: 2008-07-31 12:08:03 $
00007   Version:   $Revision: 1.88 $
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 
00248 #define itkSetEnumMacro(name,type) \
00249   virtual void Set##name (const type _arg) \
00250   { \
00251     itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
00252     if (this->m_##name != _arg) \
00253       { \
00254       this->m_##name = _arg; \
00255       this->Modified(); \
00256       } \
00257   } 
00258 
00259 
00263 #define itkGetEnumMacro(name,type) \
00264   virtual type Get##name () const \
00265   { \
00266     itkDebugMacro("returning " << #name " of " << static_cast<long>(this->m_##name) ); \
00267     return this->m_##name; \
00268   }
00269 
00270 
00274 #define itkSetStringMacro(name) \
00275   virtual void Set##name (const char* _arg) \
00276   { \
00277     if ( _arg && (_arg == this->m_##name) ) { return;} \
00278     if (_arg) \
00279       { \
00280       this->m_##name = _arg;\
00281       } \
00282      else \
00283       { \
00284       this->m_##name = ""; \
00285       } \
00286     this->Modified(); \
00287   } \
00288   virtual void Set##name (const std::string & _arg) \
00289   { \
00290     this->Set##name( _arg.c_str() ); \
00291   } \
00292 
00293 
00294 
00298 #define itkGetStringMacro(name) \
00299   virtual const char* Get##name () const \
00300   { \
00301     return this->m_##name.c_str(); \
00302   }
00303 
00307 #define itkSetClampMacro(name,type,min,max) \
00308   virtual void Set##name (type _arg) \
00309   { \
00310     itkDebugMacro("setting " << #name " to " << _arg ); \
00311     if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
00312       { \
00313       this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
00314       this->Modified(); \
00315       } \
00316   } 
00317 
00318 
00323 #define itkSetObjectMacro(name,type) \
00324   virtual void Set##name (type* _arg) \
00325   { \
00326     itkDebugMacro("setting " << #name " to " << _arg ); \
00327     if (this->m_##name != _arg) \
00328       { \
00329       this->m_##name = _arg; \
00330       this->Modified(); \
00331       } \
00332   } 
00333 
00334 
00337 #define itkGetObjectMacro(name,type) \
00338   virtual type * Get##name () \
00339   { \
00340     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00341     return this->m_##name.GetPointer(); \
00342   } 
00343 
00344 
00349 #define itkSetConstObjectMacro(name,type) \
00350   virtual void Set##name (const type* _arg) \
00351   { \
00352     itkDebugMacro("setting " << #name " to " << _arg ); \
00353     if (this->m_##name != _arg) \
00354       { \
00355       this->m_##name = _arg; \
00356       this->Modified(); \
00357       } \
00358   } 
00359 
00360 
00361 
00364 #define itkGetConstObjectMacro(name,type) \
00365   virtual const type * Get##name () const \
00366   { \
00367     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00368     return this->m_##name.GetPointer(); \
00369   } 
00370 
00371 
00374 #define itkGetConstReferenceObjectMacro(name,type) \
00375   virtual const typename type::Pointer & Get##name () const \
00376   { \
00377     itkDebugMacro("returning " #name " address " << this->m_##name ); \
00378     return this->m_##name; \
00379   } 
00380 
00381 
00384 #define itkBooleanMacro(name) \
00385   virtual void name##On () { this->Set##name(true);} \
00386   virtual void name##Off () { this->Set##name(false);}
00387 
00388 
00392 #define itkSetVectorMacro(name,type,count) \
00393   virtual void Set##name(type data[]) \
00394   { \
00395     unsigned int i; \
00396     for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
00397     if ( i < count ) \
00398       { \
00399       this->Modified(); \
00400       for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
00401       } \
00402   }
00403 
00404 
00407 #define itkGetVectorMacro(name,type,count) \
00408   virtual type *Get##name () const \
00409   { \
00410     return this->m_##name; \
00411   } 
00412 
00429 #define itkNewMacro(x) \
00430 static Pointer New(void) \
00431 { \
00432   Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
00433   if(smartPtr.GetPointer() == NULL) \
00434     { \
00435     smartPtr = new x; \
00436     } \
00437   smartPtr->UnRegister(); \
00438   return smartPtr; \
00439 } \
00440 virtual ::itk::LightObject::Pointer CreateAnother(void) const \
00441 { \
00442   ::itk::LightObject::Pointer smartPtr; \
00443   smartPtr = x::New().GetPointer(); \
00444   return smartPtr; \
00445 }
00446 
00447 
00448 
00465 #define itkFactorylessNewMacro(x) \
00466 static Pointer New(void) \
00467 { \
00468   Pointer smartPtr; \
00469   x *rawPtr = new x; \
00470   smartPtr = rawPtr; \
00471   rawPtr->UnRegister(); \
00472   return smartPtr; \
00473 } \
00474   virtual ::itk::LightObject::Pointer CreateAnother(void) const \
00475 { \
00476   ::itk::LightObject::Pointer smartPtr;         \
00477   smartPtr = x::New().GetPointer(); \
00478   return smartPtr; \
00479 }
00480 
00481 
00484 #define itkTypeMacro(thisClass,superclass) \
00485     virtual const char *GetNameOfClass() const \
00486         {return #thisClass;} 
00487 
00488 
00489 namespace itk
00490 {
00497 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char*);
00498 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char*);
00499 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char*);
00500 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char*);
00501 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char*);
00502 } // end namespace itk
00504 
00508 #if defined(ITK_LEAN_AND_MEAN) || defined(__BORLANDC__) || defined(NDEBUG)
00509 #define itkDebugMacro(x)
00510 #else
00511 #define itkDebugMacro(x) \
00512   { if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay())   \
00513     { ::itk::OStringStream itkmsg; \
00514       itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00515              << this->GetNameOfClass() << " (" << this << "): " x  \
00516              << "\n\n"; \
00517       ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str());} \
00518 }
00519 #endif
00520 
00521 
00522 
00526 #ifdef ITK_LEAN_AND_MEAN
00527 #define itkWarningMacro(x)
00528 #else
00529 #define itkWarningMacro(x) \
00530 { if (::itk::Object::GetGlobalWarningDisplay()) \
00531     { ::itk::OStringStream itkmsg; \
00532       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00533              << this->GetNameOfClass() << " (" << this << "): " x  \
00534              << "\n\n"; \
00535       ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str());} \
00536 }
00537 #endif
00538 
00539 
00540 namespace itk
00541 {
00542 
00548 #if !defined(ITK_NO_ANSI_STRING_STREAM)
00549 class OStringStream: public std::ostringstream
00550 {
00551 public:
00552   OStringStream() {}
00553 private:
00554   OStringStream(const OStringStream&);
00555   void operator=(const OStringStream&);
00556 };
00557 #else
00558 namespace OStringStreamDetail
00559 {
00560   class Cleanup
00561   {
00562   public:
00563     Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
00564     ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
00565     static void IgnoreUnusedVariable(const Cleanup&) {}
00566   protected:
00567     std::ostrstream& m_OStrStream;
00568   };
00569 }//namespace OStringStreamDetail
00571 
00572 class OStringStream: public std::ostrstream
00573 {
00574 public:
00575   typedef std::ostrstream Superclass;
00576   OStringStream() {}
00577   std::string str()
00578     {
00579       OStringStreamDetail::Cleanup cleanup(*this);
00580       OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
00581       int pcount = this->pcount();
00582       const char* ptr = this->Superclass::str();
00583       return std::string(ptr?ptr:"", pcount);
00584     }
00585 private:
00586   OStringStream(const OStringStream&);
00587   void operator=(const OStringStream&);
00588 };
00589 #endif
00590 
00591 }//namespace itk
00592 
00593 #if defined(ITK_CPP_FUNCTION)
00594   #if defined(__BORLANDC__)
00595     #define ITK_LOCATION __FUNC__
00596   #elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(CABLE_CONFIGURATION) && !defined(CSWIG)
00597     #define ITK_LOCATION __FUNCSIG__
00598   #elif defined(__GNUC__)
00599     #define ITK_LOCATION __PRETTY_FUNCTION__
00600   #else
00601     #define ITK_LOCATION __FUNCTION__
00602   #endif
00603 #else
00604   #define ITK_LOCATION "unknown"
00605 #endif
00606 
00607 #include "itkExceptionObject.h"
00608 
00612 #define itkExceptionMacro(x) \
00613   { \
00614   ::itk::OStringStream message; \
00615   message << "itk::ERROR: " << this->GetNameOfClass() \
00616           << "(" << this << "): " x; \
00617   ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00618   throw e_; /* Explicit naming to work around Intel compiler bug.  */ \
00619   }
00620 
00621 
00622 #define itkGenericExceptionMacro(x) \
00623   { \
00624   ::itk::OStringStream message; \
00625   message << "itk::ERROR: " x; \
00626   ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(),ITK_LOCATION); \
00627   throw e_; /* Explicit naming to work around Intel compiler bug.  */ \
00628   }
00629 
00630 #ifdef ITK_LEAN_AND_MEAN
00631 #define itkGenericOutputMacro(x)
00632 #else
00633 #define itkGenericOutputMacro(x) \
00634 { if (::itk::Object::GetGlobalWarningDisplay()) \
00635     { ::itk::OStringStream itkmsg; \
00636       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00637              x << "\n\n"; \
00638       ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str());} \
00639 }
00640 #endif
00641 
00642 
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 Wed Nov 5 22:43:03 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000