ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMacro.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 /*=========================================================================
00019  *
00020  *  Portions of this file are subject to the VTK Toolkit Version 3 copyright.
00021  *
00022  *  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00023  *
00024  *  For complete copyright, license and disclaimer of warranty information
00025  *  please refer to the NOTICE file at the top of the ITK source tree.
00026  *
00027  *=========================================================================*/
00038 #ifndef __itkMacro_h
00039 #define __itkMacro_h
00040 
00041 #include "itkWin32Header.h"
00042 #include "itkConfigure.h"
00043 
00044 #include <string>
00045 #include <cstdlib>
00046 #ifndef NDEBUG
00047 #include <cassert>
00048 #endif
00049 
00050 #include <sstream>
00051 
00056 namespace itk
00057 {
00058 // end namespace itk - this is here for documentation purposes
00059 }
00060 
00063 #define itkNotUsed(x)
00064 
00065 /*
00066  * ITK only supports MSVC++ 7.1 and greater
00067  * MSVC++ 11.0 _MSC_VER = 1700
00068  * MSVC++ 10.0 _MSC_VER = 1600
00069  * MSVC++ 9.0 _MSC_VER = 1500
00070  * MSVC++ 8.0 _MSC_VER = 1400
00071  * MSVC++ 7.1 _MSC_VER = 1310
00072  * MSVC++ 7.0 _MSC_VER = 1300
00073  * MSVC++ 6.0 _MSC_VER = 1200
00074  * MSVC++ 5.0 _MSC_VER = 1100
00075 */
00076 #if defined( _MSC_VER ) && ( _MSC_VER < 1310 )
00077 //#error "_MSC_VER < 1310 (MSVC++ 7.1) not supported under ITKv4"
00078 #endif
00079 #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC < 0x590 )
00080 #error "__SUNPRO_CC < 0x590 not supported under ITKv4"
00081 #endif
00082 #if defined( __CYGWIN__ )
00083 #error "The Cygwin compiler is not supported in ITKv4 and above"
00084 #endif
00085 #if defined( __BORLANDC__ )
00086 #error "The Borland C compiler is not supported in ITKv4 and above"
00087 #endif
00088 #if defined( __MWERKS__ )
00089 #error "The MetroWerks compiler is not supported in ITKv4 and above"
00090 #endif
00091 #if defined( __GNUC__ ) && ( __GNUC__ < 3 )
00092 #error "The __GNUC__ version 2.95 compiler is not supprted under ITKv4 and above"
00093 #if defined( __sgi )
00094 //This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
00095 //TODO: At some future point, it may be necessary to
00096 //define a minimum __sgi version that will work.
00097 #error "The __sgi compiler is not supprted under ITKv4 and above"
00098 #endif
00099 #endif
00100 
00101 // Setup symbol exports
00102 //
00103 // When a class definition has ITK_EXPORT, the class will be
00104 // checked automatically, by Utilities/Dart/PrintSelfCheck.tcl
00105 #define ITK_EXPORT
00106 
00107 #if defined( _WIN32 ) || defined ( WIN32 )
00108   #define ITK_ABI_IMPORT __declspec(dllimport)
00109   #define ITK_ABI_EXPORT __declspec(dllexport)
00110   #define ITK_ABI_HIDDEN
00111 #else
00112   #if __GNUC__ >= 4
00113     #define ITK_ABI_IMPORT __attribute__ ((visibility ("default")))
00114     #define ITK_ABI_EXPORT __attribute__ ((visibility ("default")))
00115     #define ITK_ABI_HIDDEN __attribute__ ((visibility ("hidden")))
00116   #else
00117     #define ITK_ABI_IMPORT
00118     #define ITK_ABI_EXPORT
00119     #define ITK_ABI_HIDDEN
00120   #endif
00121 #endif
00122 
00123 #define ITKCommon_HIDDEN ITK_ABI_HIDDEN
00124 
00125 #if !defined( ITKSTATIC )
00126   #ifdef ITKCommon_EXPORTS
00127     #define ITKCommon_EXPORT ITK_ABI_EXPORT
00128   #else
00129     #define ITKCommon_EXPORT ITK_ABI_IMPORT
00130   #endif  /* ITKCommon_EXPORTS */
00131 #else
00132   /* ITKCommon is build as a static lib */
00133   #if __GNUC__ >= 4
00134     // Don't hide symbols in the static ITKCommon library in case
00135     // -fvisibility=hidden is used
00136     #define ITKCommon_EXPORT ITK_ABI_EXPORT
00137   #else
00138     #define ITKCommon_EXPORT
00139   #endif
00140 #endif
00141 
00142 //This is probably better, but requires a lot of extra work
00143 //for gettting ExplicitInstantiation to work properly. \#define
00144 // itkStaticConstMacro(name, type, value) static const type name = value
00145 #define itkStaticConstMacro(name, type, value) enum { name = value }
00146 
00147 #define itkGetStaticConstMacro(name) (Self::name)
00148 
00150 #define itkSetInputMacro(name, type)                                              \
00151   virtual void Set##name(const type *_arg)                                        \
00152     {                                                                             \
00153     itkDebugMacro("setting input " #name " to " << _arg);                         \
00154     if ( _arg != static_cast< type * >( this->ProcessObject::GetInput(#name) ) )  \
00155       {                                                                           \
00156       this->ProcessObject::SetInput( #name, const_cast< type * >( _arg ) );       \
00157       this->Modified();                                                           \
00158       }                                                                           \
00159     }
00160 
00161 
00163 #define itkGetInputMacro(name, type)                                                                            \
00164   virtual const type * Get##name() const                                                                        \
00165     {                                                                                                           \
00166     itkDebugMacro( "returning input " << #name " of "                                                           \
00167                                       << static_cast< const type * >( this->ProcessObject::GetInput(#name) ) ); \
00168     return static_cast< const type * >( this->ProcessObject::GetInput(#name) );                                 \
00169     }
00170 
00171 
00173 #define itkSetDecoratedInputMacro(name, type)                                                                 \
00174   virtual void Set##name##Input(const SimpleDataObjectDecorator< type > *_arg)                                \
00175     {                                                                                                         \
00176     itkDebugMacro("setting input " #name " to " << _arg);                                                     \
00177     if ( _arg != static_cast< SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
00178       {                                                                                                       \
00179       this->ProcessObject::SetInput( #name, const_cast< SimpleDataObjectDecorator< type > * >( _arg ) );      \
00180       this->Modified();                                                                                       \
00181       }                                                                                                       \
00182     }                                                                                                         \
00183   virtual void Set##name(const type &_arg)                           \
00184     {                                                                \
00185     typedef SimpleDataObjectDecorator< type > DecoratorType;         \
00186     itkDebugMacro("setting input " #name " to " << _arg);            \
00187     const DecoratorType *oldInput =                                  \
00188       static_cast< const DecoratorType * >(                          \
00189         this->ProcessObject::GetInput(#name) );                      \
00190     if ( oldInput && oldInput->Get() == _arg )                       \
00191       {                                                              \
00192       return;                                                        \
00193       }                                                              \
00194     typename DecoratorType::Pointer newInput = DecoratorType::New(); \
00195     newInput->Set(_arg);                                             \
00196     this->Set##name##Input(newInput);                                \
00197     }
00198 
00199 
00201 #define itkGetDecoratedInputMacro(name, type)                                                                 \
00202   virtual const SimpleDataObjectDecorator< type > * Get##name##Input() const                                                                 \
00203     {                                                                                                                                        \
00204     itkDebugMacro( "returning input " << #name " of "                                                                                        \
00205                                       << static_cast< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ); \
00206     return static_cast< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) );                                 \
00207     }                                                                \
00208   virtual const type & Get##name() const                             \
00209     {                                                                \
00210     itkDebugMacro("Getting input " #name);                           \
00211     typedef SimpleDataObjectDecorator< type > DecoratorType;         \
00212     const DecoratorType *input =                                     \
00213       static_cast< const DecoratorType * >(                          \
00214         this->ProcessObject::GetInput(#name) );                      \
00215     if( input == NULL )                                              \
00216       {                                                              \
00217       itkExceptionMacro(<<"input" #name " is not set");              \
00218       }                                                              \
00219     return input->Get();                                             \
00220     }
00221 
00222 
00225 #define itkSetGetDecoratedInputMacro(name, type)  \
00226   itkSetDecoratedInputMacro(name, type)           \
00227   itkGetDecoratedInputMacro(name, type)
00228 
00233 #define itkSetDecoratedObjectInputMacro(name, type)          \
00234   virtual void Set##name##Input(const DataObjectDecorator< type > *_arg)                                \
00235     {                                                                                                   \
00236     itkDebugMacro("setting input " #name " to " << _arg);                                               \
00237     if ( _arg != static_cast< DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
00238       {                                                                                                 \
00239       this->ProcessObject::SetInput( #name, const_cast< DataObjectDecorator< type > * >( _arg ) );      \
00240       this->Modified();                                                                                 \
00241       }                                                                                                 \
00242     }                                                                                                   \
00243   virtual void Set##name(const type * _arg)                          \
00244     {                                                                \
00245     typedef DataObjectDecorator< type > DecoratorType;               \
00246     itkDebugMacro("setting input " #name " to " << _arg);            \
00247     const DecoratorType *oldInput =                                  \
00248       static_cast< const DecoratorType * >(                          \
00249         this->ProcessObject::GetInput(#name) );                      \
00250     if ( oldInput && oldInput->Get() == _arg )                       \
00251       {                                                              \
00252       return;                                                        \
00253       }                                                              \
00254     typename DecoratorType::Pointer newInput = DecoratorType::New(); \
00255     newInput->Set(_arg);                                             \
00256     this->Set##name##Input(newInput);                                \
00257     }
00258 
00259 
00264 #define itkGetDecoratedObjectInputMacro(name, type)          \
00265   virtual const DataObjectDecorator< type > * Get##name##Input() const                                                                 \
00266     {                                                                                                                                  \
00267     itkDebugMacro( "returning input " << #name " of "                                                                                  \
00268                                       << static_cast< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ); \
00269     return static_cast< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) );                                 \
00270     }                                                                \
00271   virtual const type * Get##name() const                             \
00272     {                                                                \
00273     itkDebugMacro("Getting input " #name);                           \
00274     typedef DataObjectDecorator< type > DecoratorType;               \
00275     const DecoratorType *input =                                     \
00276       static_cast< const DecoratorType * >(                          \
00277         this->ProcessObject::GetInput(#name) );                      \
00278     if( input == NULL )                                              \
00279       {                                                              \
00280       itkExceptionMacro(<<"input" #name " is not set");              \
00281       }                                                              \
00282     return input->Get();                                             \
00283     }
00284 
00285 
00288 #define itkSetGetDecoratedObjectInputMacro(name, type)  \
00289   itkSetDecoratedObjectInputMacro(name, type)           \
00290   itkGetDecoratedObjectInputMacro(name, type)
00291 
00293 #define itkSetMacro(name, type)                      \
00294   virtual void Set##name (const type _arg)         \
00295     {                                                \
00296     itkDebugMacro("setting " #name " to " << _arg); \
00297     if ( this->m_##name != _arg )                  \
00298       {                                              \
00299       this->m_##name = _arg;                       \
00300       this->Modified();                              \
00301       }                                              \
00302     }
00303 
00304 
00306 #define itkGetMacro(name, type)                                       \
00307   virtual type Get##name ()                                         \
00308     {                                                                 \
00309     return this->m_##name;                                          \
00310     }
00311 
00312 
00316 #define itkGetConstMacro(name, type)                                  \
00317   virtual type Get##name () const                                   \
00318     {                                                                 \
00319     return this->m_##name;                                          \
00320     }
00321 
00322 
00327 #define itkGetConstReferenceMacro(name, type)                         \
00328   virtual const type &Get##name () const                            \
00329     {                                                                 \
00330     return this->m_##name;                                          \
00331     }
00332 
00333 
00338 #define itkSetEnumMacro(name, type)                                           \
00339   virtual void Set##name (const type _arg)                                  \
00340     {                                                                         \
00341     itkDebugMacro( "setting " #name " to " << static_cast< long >( _arg ) ); \
00342     if ( this->m_##name != _arg )                                           \
00343       {                                                                       \
00344       this->m_##name = _arg;                                                \
00345       this->Modified();                                                       \
00346       }                                                                       \
00347     }
00348 
00349 
00354 #define itkGetEnumMacro(name, type)                                           \
00355   virtual type Get##name () const                                             \
00356     {                                                                         \
00357     return this->m_##name;                                                    \
00358     }
00359 
00360 
00364 #define itkSetStringMacro(name)                             \
00365   virtual void Set##name (const char *_arg)               \
00366     {                                                       \
00367     if ( _arg && ( _arg == this->m_##name ) ) { return; } \
00368     if ( _arg )                                             \
00369       {                                                     \
00370       this->m_##name = _arg;                              \
00371       }                                                     \
00372     else                                                    \
00373       {                                                     \
00374       this->m_##name = "";                                \
00375       }                                                     \
00376     this->Modified();                                       \
00377     }                                                       \
00378   virtual void Set##name (const std::string & _arg)       \
00379     {                                                       \
00380     this->Set##name( _arg.c_str() );                      \
00381     }                                                       \
00382 
00383 
00384 
00388 #define itkGetStringMacro(name)            \
00389   virtual const char *Get##name () const \
00390     {                                      \
00391     return this->m_##name.c_str();       \
00392     }
00393 
00397 #define itkSetClampMacro(name, type, min, max)                                    \
00398   virtual void Set##name (type _arg)                                            \
00399     {                                                                             \
00400     itkDebugMacro("setting " << #name " to " << _arg);                           \
00401     if ( this->m_##name != ( _arg < min ? min : ( _arg > max ? max : _arg ) ) ) \
00402       {                                                                           \
00403       this->m_##name = ( _arg < min ? min : ( _arg > max ? max : _arg ) );      \
00404       this->Modified();                                                           \
00405       }                                                                           \
00406     }
00407 
00408 
00413 #define itkSetObjectMacro(name, type)                   \
00414   virtual void Set##name (type * _arg)                \
00415     {                                                   \
00416     itkDebugMacro("setting " << #name " to " << _arg); \
00417     if ( this->m_##name != _arg )                     \
00418       {                                                 \
00419       this->m_##name = _arg;                          \
00420       this->Modified();                                 \
00421       }                                                 \
00422     }
00423 
00424 
00427 #define itkGetObjectMacro(name, type)                                   \
00428   virtual type * Get##name ()                                         \
00429     {                                                                   \
00430     return this->m_##name.GetPointer();                               \
00431     }
00432 
00437 #define itkSetConstObjectMacro(name, type)              \
00438   virtual void Set##name (const type * _arg)          \
00439     {                                                   \
00440     itkDebugMacro("setting " << #name " to " << _arg); \
00441     if ( this->m_##name != _arg )                     \
00442       {                                                 \
00443       this->m_##name = _arg;                          \
00444       this->Modified();                                 \
00445       }                                                 \
00446     }
00447 
00448 
00451 #define itkGetConstObjectMacro(name, type)                              \
00452   virtual const type * Get##name () const                             \
00453     {                                                                   \
00454     return this->m_##name.GetPointer();                               \
00455     }
00456 
00459 #define itkGetConstReferenceObjectMacro(name, type)                     \
00460   virtual const typename type::Pointer & Get##name () const             \
00461     {                                                                   \
00462     return this->m_##name;                                              \
00463     }
00464 
00467 #define itkBooleanMacro(name) \
00468   virtual void name##On ()  \
00469     {                         \
00470     this->Set##name(true);  \
00471     }                         \
00472   virtual void name##Off () \
00473     {                         \
00474     this->Set##name(false); \
00475     }
00476 
00477 
00481 #define itkSetVectorMacro(name, type, count) \
00482   virtual void Set##name(type data[])      \
00483     {                                        \
00484     unsigned int i;                          \
00485     for ( i = 0; i < count; i++ )            \
00486       {                                      \
00487       if ( data[i] != this->m_##name[i] )  \
00488         {                                    \
00489         break;                               \
00490         }                                    \
00491       }                                      \
00492     if ( i < count )                         \
00493       {                                      \
00494       this->Modified();                      \
00495       for ( i = 0; i < count; i++ )          \
00496         {                                    \
00497         this->m_##name[i] = data[i];       \
00498         }                                    \
00499       }                                      \
00500     }
00501 
00502 
00505 #define itkGetVectorMacro(name, type, count) \
00506   virtual type * Get##name () const        \
00507     {                                        \
00508     return this->m_##name;                 \
00509     }
00510 
00531 #define itkNewMacro(x)                                         \
00532   itkSimpleNewMacro(x)                                         \
00533   itkCreateAnotherMacro(x)                                     \
00534   itkCloneMacro(x)
00535 
00536 #define itkSimpleNewMacro(x)                                   \
00537   static Pointer New(void)                                     \
00538     {                                                          \
00539     Pointer smartPtr = ::itk::ObjectFactory< x >::Create();    \
00540     if ( smartPtr.GetPointer() == NULL )                       \
00541       {                                                        \
00542       smartPtr = new x;                                        \
00543       }                                                        \
00544     smartPtr->UnRegister();                                    \
00545     return smartPtr;                                           \
00546     }
00547 
00548 #define itkCreateAnotherMacro(x)                               \
00549   virtual::itk::LightObject::Pointer CreateAnother(void) const \
00550     {                                                          \
00551     ::itk::LightObject::Pointer smartPtr;                      \
00552     smartPtr = x::New().GetPointer();                          \
00553     return smartPtr;                                           \
00554     }
00555 
00556 #define itkCloneMacro(x)                                        \
00557   Pointer Clone() const                             \
00558   {                                                             \
00559     Pointer rval =                                  \
00560       dynamic_cast<x *>(this->InternalClone().GetPointer());    \
00561     return rval;                                                \
00562   }
00563 
00580 #define itkFactorylessNewMacro(x)                              \
00581   static Pointer New(void)                                     \
00582     {                                                          \
00583     Pointer smartPtr;                                          \
00584     x *     rawPtr = new x;                                    \
00585     smartPtr = rawPtr;                                         \
00586     rawPtr->UnRegister();                                      \
00587     return smartPtr;                                           \
00588     }                                                          \
00589   virtual::itk::LightObject::Pointer CreateAnother(void) const \
00590     {                                                          \
00591     ::itk::LightObject::Pointer smartPtr;                      \
00592     smartPtr = x::New().GetPointer();                          \
00593     return smartPtr;                                           \
00594     }
00595 
00596 
00599 #define itkTypeMacro(thisClass, superclass)  \
00600   virtual const char *GetNameOfClass() const \
00601     {                                        \
00602     return #thisClass;                      \
00603     }
00604 
00605 namespace itk
00606 {
00613 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char *);
00615 
00616 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char *);
00617 
00618 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char *);
00619 
00620 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char *);
00621 
00622 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char *);
00623 } // end namespace itk
00624 
00628 #if defined( NDEBUG )
00629 #define itkDebugMacro(x)
00630 #define itkDebugStatement(x)
00631 #else
00632 #define itkDebugMacro(x)                                                \
00633     {                                                                   \
00634     if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
00635       {                                                                 \
00636       std::ostringstream itkmsg;                                        \
00637       itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n"     \
00638              << this->GetNameOfClass() << " (" << this << "): " x       \
00639              << "\n\n";                                                 \
00640       ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() );      \
00641       }                                                                 \
00642     }
00643 
00644 
00645 //The itkDebugStatement is to be used ot protect code that is only
00646 //used in the itkDebugMacro
00647 #define itkDebugStatement(x) x
00648 #endif
00649 
00653 #define itkWarningMacro(x)                                            \
00654     {                                                                 \
00655     if ( ::itk::Object::GetGlobalWarningDisplay() )                   \
00656       {                                                               \
00657       std::ostringstream itkmsg;                                      \
00658       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00659              << this->GetNameOfClass() << " (" << this << "): " x     \
00660              << "\n\n";                                               \
00661       ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() );  \
00662       }                                                               \
00663     }
00664 
00665 
00666 //The itkDebugStatement is to be used ot protect code that is only
00667 //used in the itkDebugMacro
00668 #define itkWarningStatement(x) x
00669 
00670 #if defined( ITK_CPP_FUNCTION )
00671   #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( CABLE_CONFIGURATION ) \
00672   && !defined( CSWIG )
00673     #define ITK_LOCATION __FUNCSIG__
00674   #elif defined( __GNUC__ )
00675     #define ITK_LOCATION __PRETTY_FUNCTION__
00676   #else
00677     #define ITK_LOCATION __FUNCTION__
00678   #endif
00679 #else
00680   #define ITK_LOCATION "unknown"
00681 #endif
00682 
00683 #include "itkExceptionObject.h"
00684 
00688 #define itkExceptionMacro(x)                                                            \
00689     {                                                                                   \
00690     std::ostringstream message;                                                         \
00691     message << "itk::ERROR: " << this->GetNameOfClass()                                 \
00692             << "(" << this << "): " x;                                                  \
00693     ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
00694     throw e_; /* Explicit naming to work around Intel compiler bug.  */                 \
00695     }
00696 
00697 
00698 #define itkGenericExceptionMacro(x)                                                     \
00699     {                                                                                   \
00700     std::ostringstream message;                                                         \
00701     message << "itk::ERROR: " x;                                                        \
00702     ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
00703     throw e_; /* Explicit naming to work around Intel compiler bug.  */                 \
00704     }
00705 
00706 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage)                        \
00707 namespace itk {                                                                         \
00708 class ITK_EXPORT newexcp : public parentexcp                                            \
00709 {                                                                                       \
00710 public:                                                                                 \
00711 newexcp( const char *file, unsigned int lineNumber ) :                                  \
00712 parentexcp( file, lineNumber )                                                          \
00713 {                                                                                       \
00714   this->SetDescription( whatmessage );                                                  \
00715 }                                                                                       \
00716 newexcp( const std::string & file, unsigned int lineNumber ) :                          \
00717 parentexcp( file, lineNumber )                                                          \
00718 {                                                                                       \
00719   this->SetDescription( whatmessage );                                                  \
00720 }                                                                                       \
00721 itkTypeMacro(newexcp, parentexcp);                                                      \
00722 };                                                                                      \
00723 }
00724 
00725 #define itkSpecializedExceptionMacro(exceptiontype)                                     \
00726     {                                                                                   \
00727     ::itk::exceptiontype e_(__FILE__, __LINE__);                                        \
00728     e_.SetLocation(ITK_LOCATION);                                                       \
00729     throw e_; /* Explicit naming to work around Intel compiler bug.  */                 \
00730     }
00731 
00732 #define itkSpecializedMessageExceptionMacro(exceptiontype,x)                            \
00733     {                                                                                   \
00734     ::itk::exceptiontype e_(__FILE__, __LINE__);                                        \
00735     std::ostringstream message;                                                         \
00736     message << "itk::ERROR: " x;                                                        \
00737     e_.SetDescription(message.str().c_str());                                           \
00738     e_.SetLocation(ITK_LOCATION);                                                       \
00739     throw e_; /* Explicit naming to work around Intel compiler bug.  */                 \
00740     }
00741 
00742 
00743 #define itkGenericOutputMacro(x)                                           \
00744     {                                                                      \
00745     if ( ::itk::Object::GetGlobalWarningDisplay() )                        \
00746       {                                                                    \
00747       std::ostringstream itkmsg;                                           \
00748       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n"      \
00749       x << "\n\n";                                                         \
00750       ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \
00751       }                                                                    \
00752     }
00753 
00754 //----------------------------------------------------------------------------
00755 // Macros for simplifying the use of logging
00756 //
00757 #define itkLogMacro(x, y)                                \
00758     {                                                    \
00759     if ( this->GetLogger() )                             \
00760       {                                                  \
00761       this->GetLogger()->Write(::itk::LoggerBase::x, y); \
00762       }                                                  \
00763     }
00764 
00765 #define itkLogMacroStatic(obj, x, y)                    \
00766     {                                                   \
00767     if ( obj->GetLogger() )                             \
00768       {                                                 \
00769       obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
00770       }                                                 \
00771     }
00772 
00773 //----------------------------------------------------------------------------
00774 // Setup legacy code policy.
00775 //
00776 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted
00777 // They may be used to completely remove legacy code or silence the
00778 // warnings.  The default is to warn about their use.
00779 //
00780 // Source files that test the legacy code may define ITK_LEGACY_TEST
00781 // like this:
00782 //
00783 //  #define ITK_LEGACY_TEST
00784 //  #include "itkClassWithDeprecatedMethod.h"
00785 //
00786 // in order to silence the warnings for calling deprecated methods.
00787 // No other source files in ITK should call the methods since they are
00788 // provided only for compatibility with older user code.
00789 
00790 // Define itkLegacyMacro to mark legacy methods where they are
00791 // declared in their class.  Example usage:
00792 //
00793 //   // @deprecated Replaced by MyOtherMethod() as of ITK 2.0.
00794 //   itkLegacyMacro(void MyMethod());
00795 #if defined( ITK_LEGACY_REMOVE )
00796 // Remove legacy methods completely.  Put a bogus declaration in
00797 // place to avoid stray semicolons because this is an error for some
00798 // compilers.  Using a class forward declaration allows any number
00799 // of repeats in any context without generating unique names.
00800 #define itkLegacyMacro(method) class itkLegacyMethodRemoved /* no ';' */
00801 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( CSWIG )
00802 // Provide legacy methods with no warnings.
00803 #define itkLegacyMacro(method) method
00804 #else
00805 // Setup compile-time warnings for uses of deprecated methods if
00806 // possible on this compiler.
00807 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) )
00808 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) )
00809 #elif defined( _MSC_VER )
00810 #define itkLegacyMacro(method) __declspec(deprecated) method
00811 #else
00812 #define itkLegacyMacro(method) method
00813 #endif
00814 #endif
00815 
00816 // Macros to create runtime deprecation warning messages in function
00817 // bodies.  Example usage:
00818 //
00819 //   void itkMyClass::MyOldMethod()
00820 //     {
00821 //     itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
00822 //     }
00823 //
00824 //   void itkMyClass::MyMethod()
00825 //     {
00826 //     itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
00827 //                               itkMyClass::MyOtherMethod);
00828 //     }
00829 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT )
00830 #define itkLegacyBodyMacro(method, version)
00831 #define itkLegacyReplaceBodyMacro(method, version, replace)
00832 #define itkGenericLegacyBodyMacro(method, version)
00833 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)
00834 #else
00835 #define itkLegacyBodyMacro(method, version) \
00836   itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00837 #define itkLegacyReplaceBodyMacro(method, version, replace)                                                   \
00838   itkWarningMacro(                                                                                            \
00839     #method " was deprecated for ITK " #version " and will be removed in a future version.  Use " #replace \
00840     " instead.")
00841 #define itkGenericLegacyBodyMacro(method, version) \
00842   itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00843 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)                                            \
00844   itkGenericOutputMacro(                                                                                      \
00845     #method " was deprecated for ITK " #version " and will be removed in a future version.  Use " #replace \
00846     " instead.")
00847 #endif
00848 
00849 //=============================================================================
00850 /* Define a common way of declaring a templated function as a friend inside a class.
00851   - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
00852 
00853   The following templated function
00854 
00855             template <T>
00856             T add(const T & a, const T & b);
00857 
00858   is declared as friend in some compilers as:
00859 
00860             class A
00861               {
00862               public:
00863                 friend Self add<Self>( const Self & a, const Self & b );
00864               }
00865 
00866    while other compilers will do
00867 
00868             class A
00869               {
00870               public:
00871                 friend Self add<>( const Self & a, const Self & b );
00872               }
00873 
00874    This characteristic of the compiler is checked by a TRY_COMPILE
00875    command defined in Insight/CMake/itkTestFriendTemplatedFunction.cxx
00876 
00877 */
00878 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_NULL_STRING )
00879 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
00880 #else
00881 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_EMPTY_BRACKETS )
00882 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)  < >
00883 #else
00884 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_TEMPLATE_ARGUMENTS )
00885 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)  < T >
00886 #endif
00887 #endif
00888 #endif
00889 // THIS IS A TEMPORARY PATCH FOR Visual Studio 10. The correct solution must
00890 // be implemented in Insight/CMake/itkTestFriendTemplatedFunction.cxx
00891 #if ( defined ( _MSC_VER ) && ( _MSC_VER >= 1600 ) )
00892 #ifdef  ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
00893 #undef  ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
00894 #endif
00895 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
00896 #endif
00897 
00898 //=============================================================================
00899 /* Choose a way to prevent template instantiation on this platform.
00900   - ITK_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
00901                                       prevent instantiation
00902   - ITK_TEMPLATE_EXTERN = use extern template to prevent instantiation
00903 
00904    Note that VS 6 supports extern template instantiation but it is
00905    hard to block the resulting warning because its stream headers
00906    re-enable it.  Therefore we just disable support for now.
00907 */
00908 #if defined( __INTEL_COMPILER ) && __INTEL_COMPILER >= 700
00909 #define ITK_TEMPLATE_EXTERN 1
00910 #elif defined( __GNUC__ ) && __GNUC__ >= 3
00911 #define ITK_TEMPLATE_EXTERN 1
00912 #elif defined( _MSC_VER )
00913 #define ITK_TEMPLATE_EXTERN 1
00914 #endif
00915 #if !defined( ITK_TEMPLATE_DO_NOT_INSTANTIATE )
00916 #define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
00917 #endif
00918 #if !defined( ITK_TEMPLATE_EXTERN )
00919 #define ITK_TEMPLATE_EXTERN 0
00920 #endif
00921 
00922 /* Define a macro to explicitly instantiate a template.
00923   - ITK_TEMPLATE_EXPORT(X) =
00924       Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
00925       examples: ITK_TEMPLATE_EXPORT(1(class Foo<int>))
00926                 ITK_TEMPLATE_EXPORT(2(class Bar<int, char>))
00927       Use one level of expansion delay to allow user code to have
00928       a macro determining the number of arguments. */
00929 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
00930 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
00931 
00932 /* Define a macro to prevent template instantiations.
00933   - ITK_TEMPLATE_IMPORT(X) =
00934       Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
00935       examples: ITK_TEMPLATE_IMPORT(1(class Foo<int>))
00936                 ITK_TEMPLATE_IMPORT(2(class Bar<int, char>))
00937       Use one level of expansion delay to allow user code to have
00938       a macro determining the number of arguments.
00939 */
00940 #if ITK_TEMPLATE_EXTERN
00941 #define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
00942 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
00943 #define ITK_TEMPLATE_IMPORT_DELAY(x) \
00944   ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
00945 #define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00946 #endif
00947 #if defined( ITK_TEMPLATE_IMPORT_DELAY )
00948 #define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
00949 #define ITK_TEMPLATE_IMPORT_WORKS 1
00950 #else
00951 #define ITK_TEMPLATE_IMPORT(x)
00952 #define ITK_TEMPLATE_IMPORT_WORKS 0
00953 #endif
00954 
01020 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \
01021   ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y)
01022 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \
01023   ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y)
01024 #define ITK_EMPTY
01025 
01026 /* Define macros to support passing a variable number of arguments
01027    throug other macros.  This is used by ITK_TEMPLATE_EXPORT,
01028    ITK_TEMPLATE_IMPORT, and by each template's instantiation
01029    macro.  */
01030 #define ITK_TEMPLATE_1(x1)                         x1
01031 #define ITK_TEMPLATE_2(x1, x2)                      x1, x2
01032 #define ITK_TEMPLATE_3(x1, x2, x3)                   x1, x2, x3
01033 #define ITK_TEMPLATE_4(x1, x2, x3, x4)                x1, x2, x3, x4
01034 #define ITK_TEMPLATE_5(x1, x2, x3, x4, x5)             x1, x2, x3, x4, x5
01035 #define ITK_TEMPLATE_6(x1, x2, x3, x4, x5, x6)          x1, x2, x3, x4, x5, x6
01036 #define ITK_TEMPLATE_7(x1, x2, x3, x4, x5, x6, x7)       x1, x2, x3, x4, x5, x6, x7
01037 #define ITK_TEMPLATE_8(x1, x2, x3, x4, x5, x6, x7, x8)    x1, x2, x3, x4, x5, x6, x7, x8
01038 #define ITK_TEMPLATE_9(x1, x2, x3, x4, x5, x6, x7, x8, x9) x1, x2, x3, x4, x5, x6, x7, x8, x9
01039 
01040 /* In order to support both implicit and explicit instantation a .h
01041    file needs to know whether it should include its .hxx file
01042    containing the template definitions.  Define a macro to tell
01043    it.  Typical usage in itkFoo.h:
01044      #if ITK_TEMPLATE_TXX
01045      #include "itkFoo.hxx"
01046      #endif
01047 */
01048 #ifndef ITK_TEMPLATE_CXX //At this point this variable MUST be defined
01049 #define ITK_TEMPLATE_CXX 0
01050 #endif
01051 #ifndef ITK_TEMPLATE_TYPE
01052 #define ITK_TEMPLATE_TYPE 0
01053 #endif
01054 #if defined( ITK_MANUAL_INSTANTIATION )
01055 #define ITK_TEMPLATE_TXX 0
01056 #else
01057 #define ITK_TEMPLATE_TXX !( ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE )
01058 #endif
01059 
01060 /* All explicit instantiation source files define ITK_TEMPLATE_CXX.
01061    Define ITK_MANUAL_INSTANTIATION to tell .h files that have not been
01062    converted to this explicit instantiation scheme to not include
01063    their .hxx files.  Also disable warnings that commonly occur in
01064    these files but are not useful.  */
01065 #if ITK_TEMPLATE_CXX
01066 #undef ITK_MANUAL_INSTANTIATION
01067 #define ITK_MANUAL_INSTANTIATION
01068 #endif
01069 //=============================================================================
01070 
01071 /* Define macros to export and import template instantiations for each
01072    library in ITK.  */
01073 #define ITK_EXPORT_ITKCommon(c, x, n) \
01074   ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
01075 #define ITK_IMPORT_ITKCommon(c, x, n) \
01076   ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
01077 
01078 /* Define a macro to decide whether to block instantiation of ITK
01079    templates.  They should be blocked only if the platform supports
01080    blocking template instantiation and the explicit instantiations are
01081    available.
01082 
01083    - ITK_TEMPLATE_EXPLICIT =
01084       Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
01085       instantiations of templates explicitly instantiated elsewhere.
01086       Typical usage in itkFoo.h:
01087         #if ITK_TEMPLATE_EXPLICIT
01088         #include "itkFoo+-.h"
01089         #endif
01090 */
01091 #if ITK_TEMPLATE_IMPORT_WORKS && defined( ITK_EXPLICIT_INSTANTIATION )
01092 #define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX
01093 #else
01094 #define ITK_TEMPLATE_EXPLICIT 0
01095 #endif
01096 
01097 //--------------------------------------------------------------------------------
01098 //  Helper macros for Template Meta-Programming techniques of for-loops
01099 // unrolling
01100 //--------------------------------------------------------------------------------
01101 
01102 //--------------------------------------------------------------------------------
01103 // Macro that generates an unrolled for loop for assigning elements of one array
01104 // to elements of another array The array are assumed to be of same length
01105 // (dimension), and this is also assumed to be the value of NumberOfIterations.
01106 // No verification of size is performed. Casting is perfomed as part of the
01107 // assignment, by using the DestinationElementType as the casting type.
01108 // Source and destination array types must have defined opearator[] in their
01109 // API.
01110 #define itkForLoopAssignmentMacro(DestinationType,                                 \
01111                                   SourceType,                                      \
01112                                   DestinationElementType,                          \
01113                                   DestinationArray,                                \
01114                                   SourceArray,                                     \
01115                                   NumberOfIterations)                              \
01116   for ( unsigned int i = 0; i < NumberOfIterations; ++i )                          \
01117     {                                                                              \
01118     DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
01119     }
01120 
01121 //--------------------------------------------------------------------------------
01122 // Macro that generates an unrolled for loop for rounding and assigning
01123 // elements of one array to elements of another array The array are assumed to
01124 // be of same length (dimension), and this is also assumed to be the value of
01125 // NumberOfIterations.  No verification of size is performed. Casting is
01126 // perfomed as part of the assignment, by using the DestinationElementType as
01127 // the casting type.
01128 // Source and destination array types must have defined opearator[] in their
01129 // API.
01130 #define itkForLoopRoundingAndAssignmentMacro(DestinationType,                         \
01131                                              Sourcrnd_halfintup,                      \
01132                                              DestinationElementType,                  \
01133                                              DestinationArray,                        \
01134                                              SourceArray,                             \
01135                                              NumberOfIterations)                      \
01136   for ( unsigned int i = 0; i < NumberOfIterations; ++i )                             \
01137     {                                                                                 \
01138     DestinationArray[i] = itk::Math::Round< DestinationElementType >(SourceArray[i]); \
01139     }
01140 
01141 // end of Template Meta Programming helper macros
01142 
01143 #ifndef NDEBUG
01144 
01145 #ifdef _POSIX_SOURCE
01146 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
01147 #else
01148 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
01149 #endif
01150 
01151 #else
01152 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
01153 #endif
01154 
01155 #define itkAssertOrThrowMacro(test, message)                       \
01156   if ( !( test ) )                                                 \
01157     {                                                              \
01158     std::ostringstream msgstr;                                     \
01159     msgstr << message;                                             \
01160     itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
01161     }
01162 
01163 #ifndef NDEBUG
01164 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
01165 #else
01166 #define itkAssertInDebugAndIgnoreInReleaseMacro(X)
01167 #endif
01168 
01169 #ifdef ITKV3_COMPATIBILITY
01170 // As of MSVS++ 7.1 and greater, typename is supported in templates
01171 // All ITKv4 compilers support the typename keyword, but this is
01172 // needed to ease transition from ITKv3.
01173 #define ITK_TYPENAME typename
01174 #endif
01175 
01176 
01177 #endif //end of itkMacro.h
01178