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

Generated at Tue Sep 15 03:53:02 2009 for ITK by doxygen 1.5.8 written by Dimitri van Heesch, © 1997-2000