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: 2010-04-26 14:32:50 $
00007   Version:   $Revision: 1.101 $
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 // THIS IS A TEMPORARY PATCH FOR Visual Studio 10. The correct solution must
00787 // be implemented in Insight/CMake/itkTestFriendTemplatedFunction.cxx
00788 #if ( defined (_MSC_VER) && ( _MSC_VER >= 1600 ) )
00789 #ifdef  ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
00790 #undef  ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
00791 #endif
00792 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
00793 #endif
00794 
00795 
00796 //=============================================================================
00797 /* Choose a way to prevent template instantiation on this platform.
00798   - ITK_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
00799                                       prevent instantiation
00800   - ITK_TEMPLATE_EXTERN = use extern template to prevent instantiation
00801 
00802    Note that VS 6 supports extern template instantiation but it is
00803    hard to block the resulting warning because its stream headers
00804    re-enable it.  Therefore we just disable support for now.
00805 */
00806 #if defined(__sgi) && defined(_COMPILER_VERSION)
00807 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 1
00808 #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
00809 # define ITK_TEMPLATE_EXTERN 1
00810 #elif defined(__GNUC__) && __GNUC__ >= 3
00811 # define ITK_TEMPLATE_EXTERN 1
00812 #elif defined(_MSC_VER) && _MSC_VER >= 1300
00813 # define ITK_TEMPLATE_EXTERN 1
00814 #endif
00815 #if !defined(ITK_TEMPLATE_DO_NOT_INSTANTIATE)
00816 # define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
00817 #endif
00818 #if !defined(ITK_TEMPLATE_EXTERN)
00819 # define ITK_TEMPLATE_EXTERN 0
00820 #endif
00821 
00822 /* Define a macro to explicitly instantiate a template.
00823   - ITK_TEMPLATE_EXPORT(X) =
00824       Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
00825       examples: ITK_TEMPLATE_EXPORT(1(class Foo<int>))
00826                 ITK_TEMPLATE_EXPORT(2(class Bar<int, char>))
00827       Use one level of expansion delay to allow user code to have
00828       a macro determining the number of arguments. */
00829 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
00830 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
00831 
00832 /* Define a macro to prevent template instantiations.
00833   - ITK_TEMPLATE_IMPORT(X) =
00834       Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
00835       examples: ITK_TEMPLATE_IMPORT(1(class Foo<int>))
00836                 ITK_TEMPLATE_IMPORT(2(class Bar<int, char>))
00837       Use one level of expansion delay to allow user code to have
00838       a macro determining the number of arguments.
00839 */
00840 #if ITK_TEMPLATE_EXTERN
00841 # define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
00842 # if defined(_MSC_VER)
00843 #  pragma warning (disable: 4231) /* extern template extension */
00844 # endif
00845 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
00846 # define ITK_TEMPLATE_IMPORT_DELAY(x) \
00847          ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
00848 # define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00849 #endif
00850 #if defined(ITK_TEMPLATE_IMPORT_DELAY)
00851 # define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
00852 # define ITK_TEMPLATE_IMPORT_WORKS 1
00853 #else
00854 # define ITK_TEMPLATE_IMPORT(x)
00855 # define ITK_TEMPLATE_IMPORT_WORKS 0
00856 #endif
00857 
00858 /* Define macros to export and import template instantiations.  These
00859    depend on each class providing a macro defining the instantiations
00860    given template arguments in X.  The argument X is of the form
00861    N(a1[,a2...,aN]).  The argument Y is a valid preprocessing token
00862    unique to the template arguments given in X.  Typical usage is
00863 
00864      ITK_EXPORT_TEMPLATE(itkfoo_EXPORT, Foo, (int), I)
00865      ITK_EXPORT_TEMPLATE(itkfoo_EXPORT, Bar, (int, char), IC)
00866 
00867    The ITK_TEMPLATE_<name> macro should be defined in itk<name>.h and
00868    is of the following form:
00869 
00870      #define ITK_TEMPLATE_<name>(_, EXPORT, x, y) namespace itk { \
00871        _(<n>(class EXPORT <name>< ITK_TEMPLATE_<n> x >)) \
00872        namespace Templates { typedef <name>< ITK_TEMPLATE_<n> x > <name>##y; }\
00873      }
00874 
00875    The argument "_" will be replaced by another macro such as
00876    ITK_TEMPLATE_EXPORT or ITK_TEMPLATE_IMPORT, so it should be used as
00877    if calling one of these macros.  The argument "EXPORT" will be
00878    replaced by a dllexport/dllimport macro such as ITKCommon_EXPORT.
00879    The argument "x" is a paren-enclosed list of template arguments.
00880    The argument "y" is a preprocessing token corresponding to the
00881    given template arguments and should be used to construct typedef
00882    names for the instantiations.
00883 
00884    Note the use of ITK_TEMPLATE_<n>, where <n> is the number of
00885    template arguments for the class template.  Note also that the
00886    number of template arguments is usually the length of the list
00887    nested within the inner parentheses, so the instantiation is listed
00888    with the form <n>(...).  Example definitions:
00889 
00890      #define ITK_TEMPLATE_Foo(_, EXPORT, x, y) namespace itk { \
00891        _(1(class EXPORT Foo< ITK_TEMPLATE_1 x >)) \
00892        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00893                                            const Foo< ITK_TEMPLATE_1 x >&))) \
00894        namespace Templates { typedef Foo< ITK_TEMPLATE_1 x > Foo##y; }\
00895      }
00896 
00897      #define ITK_TEMPLATE_Bar(_, EXPORT, x, y) namespace itk { \
00898        _(2(class EXPORT Bar< ITK_TEMPLATE_2 x >)) \
00899        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00900                                            const Bar< ITK_TEMPLATE_2 x >&))) \
00901        namespace Templates { typedef Bar< ITK_TEMPLATE_2 x > Bar##y; }\
00902      }
00903 
00904    Note that in the stream operator for template Bar there is a "1" at
00905    the beginning even though two arguments are taken.  This is because
00906    the expression "ITK_TEMPLATE_2 x" is contained inside the
00907    parentheses of the function signature which protects the resulting
00908    comma from separating macro arguments.  Therefore the nested
00909    parentheses contain a list of only one macro argument.
00910 
00911    The ITK_EMPTY macro used in these definitions is a hack to work
00912    around a VS 6.0 preprocessor bug when EXPORT is empty.
00913 */
00914 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \
00915         ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y)
00916 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \
00917         ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y)
00918 #define ITK_EMPTY
00919 
00920 /* Define macros to support passing a variable number of arguments
00921    throug other macros.  This is used by ITK_TEMPLATE_EXPORT,
00922    ITK_TEMPLATE_IMPORT, and by each template's instantiation
00923    macro.  */
00924 #define ITK_TEMPLATE_1(x1)                         x1
00925 #define ITK_TEMPLATE_2(x1,x2)                      x1,x2
00926 #define ITK_TEMPLATE_3(x1,x2,x3)                   x1,x2,x3
00927 #define ITK_TEMPLATE_4(x1,x2,x3,x4)                x1,x2,x3,x4
00928 #define ITK_TEMPLATE_5(x1,x2,x3,x4,x5)             x1,x2,x3,x4,x5
00929 #define ITK_TEMPLATE_6(x1,x2,x3,x4,x5,x6)          x1,x2,x3,x4,x5,x6
00930 #define ITK_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7)       x1,x2,x3,x4,x5,x6,x7
00931 #define ITK_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8)    x1,x2,x3,x4,x5,x6,x7,x8
00932 #define ITK_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
00933 
00934 /* In order to support both implicit and explicit instantation a .h
00935    file needs to know whether it should include its .txx file
00936    containing the template definitions.  Define a macro to tell
00937    it.  Typical usage in itkFoo.h:
00938      #if ITK_TEMPLATE_TXX
00939      # include "itkFoo.txx"
00940      #endif
00941 */
00942 #if defined(ITK_MANUAL_INSTANTIATION)
00943 # define ITK_TEMPLATE_TXX 0
00944 #else
00945 # define ITK_TEMPLATE_TXX !(ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE)
00946 #endif
00947 
00948 /* All explicit instantiation source files define ITK_TEMPLATE_CXX.
00949    Define ITK_MANUAL_INSTANTIATION to tell .h files that have not been
00950    converted to this explicit instantiation scheme to not include
00951    their .txx files.  Also disable warnings that commonly occur in
00952    these files but are not useful.  */
00953 #if ITK_TEMPLATE_CXX
00954 # undef ITK_MANUAL_INSTANTIATION
00955 # define ITK_MANUAL_INSTANTIATION
00956 # if defined(_MSC_VER)
00957 #  pragma warning (disable: 4275) /* non dll-interface base */
00958 #  pragma warning (disable: 4661) /* no definition available */
00959 # endif
00960 #endif
00961 //=============================================================================
00962 
00963 /* Define macros to export and import template instantiations for each
00964    library in ITK.  */
00965 #define ITK_EXPORT_ITKCommon(c, x, n) \
00966         ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00967 #define ITK_IMPORT_ITKCommon(c, x, n) \
00968         ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
00969 
00970 /* Define a macro to decide whether to block instantiation of ITK
00971    templates.  They should be blocked only if the platform supports
00972    blocking template instantiation and the explicit instantiations are
00973    available.
00974 
00975    - ITK_TEMPLATE_EXPLICIT =
00976       Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
00977       instantiations of templates explicitly instantiated elsewhere.
00978       Typical usage in itkFoo.h:
00979         #if ITK_TEMPLATE_EXPLICIT
00980         # include "itkFoo+-.h"
00981         #endif
00982 */
00983 #if ITK_TEMPLATE_IMPORT_WORKS && defined(ITK_EXPLICIT_INSTANTIATION)
00984 # define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX
00985 #else
00986 # define ITK_TEMPLATE_EXPLICIT 0
00987 #endif
00988 
00989 
00990 //----------------------------------------------------------------------------
00991 // Macro to declare that a function does not return. __attribute__((noreturn))
00992 //    On some compiler, functions that do not return (ex: exit(0)) must
00993 //    have the noreturn attribute. Otherwise, a warning is raised. Use
00994 //    that macro to avoid those warnings. GCC defines the attribute
00995 //    noreturn for versions 2.5 and higher.
00996 #if defined(__GNUC__)
00997 #  if (((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 3))
00998 #    define ITK_NO_RETURN \
00999        __attribute__ ((noreturn))
01000 #  endif
01001 #else
01002 #  define ITK_NO_RETURN
01003 #endif
01004 
01005 
01006 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
01007 //--------------------------------------------------------------------------------
01008 //  Helper macros for Template Meta-Programming techniques of for-loops unrolling
01009 //--------------------------------------------------------------------------------
01010 
01011 //--------------------------------------------------------------------------------
01012 // Macro that generates an unrolled for loop for assigning elements of one array
01013 // to elements of another array The array are assumed to be of same length
01014 // (dimension), and this is also assumed to be the value of NumberOfIterations.
01015 // No verification of size is performed. Casting is perfomed as part of the
01016 // assignment, by using the DestinationElementType as the casting type. 
01017 // Source and destination array types must have defined opearator[] in their API.
01018 #define itkForLoopAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
01019     for(unsigned int i=0;i < NumberOfIterations; ++i) \
01020       { \
01021       DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
01022       }
01023 
01024 //--------------------------------------------------------------------------------
01025 // Macro that generates an unrolled for loop for rounding and assigning
01026 // elements of one array to elements of another array The array are assumed to
01027 // be of same length (dimension), and this is also assumed to be the value of
01028 // NumberOfIterations.  No verification of size is performed. Casting is
01029 // perfomed as part of the assignment, by using the DestinationElementType as
01030 // the casting type. 
01031 // Source and destination array types must have defined opearator[] in their API.
01032 #define itkForLoopRoundingAndAssignmentMacro(DestinationType,Sourcrnd_halfintup,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
01033     for(unsigned int i=0;i < NumberOfIterations; ++i) \
01034       { \
01035       DestinationArray[i] = itk::Math::Round< DestinationElementType >( SourceArray[i] ); \
01036       }
01037 
01038 #endif
01039 // end of Template Meta Programming helper macros
01040 
01041 
01042 #ifndef NDEBUG 
01043 
01044 #ifdef _POSIX_SOURCE
01045 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
01046 #else
01047 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro( << msg );
01048 #endif
01049 
01050 #else 
01051 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro( << msg);
01052 #endif
01053 
01054 #define itkAssertOrThrowMacro(test, message) \
01055    if( !(test) ) \
01056      { \
01057      ::itk::OStringStream msgstr; \
01058      msgstr << message;      \
01059      itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
01060      }
01061 
01062 #endif //end of itkMacro.h
01063 

Generated at Mon Jul 12 2010 19:04:56 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000