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

Generated at Fri Apr 16 18:58:38 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000