ITK  4.2.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 
00514 #define itkGPUKernelClassMacro(kernel)   \
00515 class ITK_EXPORT kernel                  \
00516   {                                      \
00517     public:                              \
00518       static const char* GetOpenCLSource(); \
00519     private:                             \
00520       kernel();                          \
00521       virtual ~kernel();                 \
00522       kernel(const kernel &);            \
00523       void operator=(const kernel &);    \
00524   };
00525 
00526 
00527 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
00528   static const char* GetOpenCLSource() \
00529   {                                 \
00530     return kernel::GetOpenCLSource();  \
00531   }
00532 
00553 #define itkNewMacro(x)                                         \
00554   itkSimpleNewMacro(x)                                         \
00555   itkCreateAnotherMacro(x)                                     \
00556   itkCloneMacro(x)
00557 
00558 #define itkSimpleNewMacro(x)                                   \
00559   static Pointer New(void)                                     \
00560     {                                                          \
00561     Pointer smartPtr = ::itk::ObjectFactory< x >::Create();    \
00562     if ( smartPtr.GetPointer() == NULL )                       \
00563       {                                                        \
00564       smartPtr = new x;                                        \
00565       }                                                        \
00566     smartPtr->UnRegister();                                    \
00567     return smartPtr;                                           \
00568     }
00569 
00570 #define itkCreateAnotherMacro(x)                               \
00571   virtual::itk::LightObject::Pointer CreateAnother(void) const \
00572     {                                                          \
00573     ::itk::LightObject::Pointer smartPtr;                      \
00574     smartPtr = x::New().GetPointer();                          \
00575     return smartPtr;                                           \
00576     }
00577 
00578 #define itkCloneMacro(x)                                        \
00579   Pointer Clone() const                             \
00580   {                                                             \
00581     Pointer rval =                                  \
00582       dynamic_cast<x *>(this->InternalClone().GetPointer());    \
00583     return rval;                                                \
00584   }
00585 
00602 #define itkFactorylessNewMacro(x)                              \
00603   static Pointer New(void)                                     \
00604     {                                                          \
00605     Pointer smartPtr;                                          \
00606     x *     rawPtr = new x;                                    \
00607     smartPtr = rawPtr;                                         \
00608     rawPtr->UnRegister();                                      \
00609     return smartPtr;                                           \
00610     }                                                          \
00611   virtual::itk::LightObject::Pointer CreateAnother(void) const \
00612     {                                                          \
00613     ::itk::LightObject::Pointer smartPtr;                      \
00614     smartPtr = x::New().GetPointer();                          \
00615     return smartPtr;                                           \
00616     }
00617 
00618 
00621 #define itkTypeMacro(thisClass, superclass)  \
00622   virtual const char *GetNameOfClass() const \
00623     {                                        \
00624     return #thisClass;                      \
00625     }
00626 
00627 namespace itk
00628 {
00635 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char *);
00637 
00638 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char *);
00639 
00640 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char *);
00641 
00642 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char *);
00643 
00644 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char *);
00645 } // end namespace itk
00646 
00650 #if defined( NDEBUG )
00651 #define itkDebugMacro(x)
00652 #define itkDebugStatement(x)
00653 #else
00654 #define itkDebugMacro(x)                                                \
00655     {                                                                   \
00656     if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
00657       {                                                                 \
00658       std::ostringstream itkmsg;                                        \
00659       itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n"     \
00660              << this->GetNameOfClass() << " (" << this << "): " x       \
00661              << "\n\n";                                                 \
00662       ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() );      \
00663       }                                                                 \
00664     }
00665 
00666 
00667 //The itkDebugStatement is to be used ot protect code that is only
00668 //used in the itkDebugMacro
00669 #define itkDebugStatement(x) x
00670 #endif
00671 
00675 #define itkWarningMacro(x)                                            \
00676     {                                                                 \
00677     if ( ::itk::Object::GetGlobalWarningDisplay() )                   \
00678       {                                                               \
00679       std::ostringstream itkmsg;                                      \
00680       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00681              << this->GetNameOfClass() << " (" << this << "): " x     \
00682              << "\n\n";                                               \
00683       ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() );  \
00684       }                                                               \
00685     }
00686 
00687 
00688 //The itkDebugStatement is to be used ot protect code that is only
00689 //used in the itkDebugMacro
00690 #define itkWarningStatement(x) x
00691 
00692 #if defined( ITK_CPP_FUNCTION )
00693   #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( CABLE_CONFIGURATION ) \
00694   && !defined( CSWIG )
00695     #define ITK_LOCATION __FUNCSIG__
00696   #elif defined( __GNUC__ )
00697     #define ITK_LOCATION __PRETTY_FUNCTION__
00698   #else
00699     #define ITK_LOCATION __FUNCTION__
00700   #endif
00701 #else
00702   #define ITK_LOCATION "unknown"
00703 #endif
00704 
00705 #include "itkExceptionObject.h"
00706 
00710 #define itkExceptionMacro(x)                                                            \
00711     {                                                                                   \
00712     std::ostringstream message;                                                         \
00713     message << "itk::ERROR: " << this->GetNameOfClass()                                 \
00714             << "(" << this << "): " x;                                                  \
00715     ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
00716     throw e_; /* Explicit naming to work around Intel compiler bug.  */                 \
00717     }
00718 
00719 
00720 #define itkGenericExceptionMacro(x)                                                     \
00721     {                                                                                   \
00722     std::ostringstream message;                                                         \
00723     message << "itk::ERROR: " x;                                                        \
00724     ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
00725     throw e_; /* Explicit naming to work around Intel compiler bug.  */                 \
00726     }
00727 
00728 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage)                        \
00729 namespace itk {                                                                         \
00730 class ITK_EXPORT newexcp : public parentexcp                                            \
00731 {                                                                                       \
00732 public:                                                                                 \
00733 newexcp( const char *file, unsigned int lineNumber ) :                                  \
00734 parentexcp( file, lineNumber )                                                          \
00735 {                                                                                       \
00736   this->SetDescription( whatmessage );                                                  \
00737 }                                                                                       \
00738 newexcp( const std::string & file, unsigned int lineNumber ) :                          \
00739 parentexcp( file, lineNumber )                                                          \
00740 {                                                                                       \
00741   this->SetDescription( whatmessage );                                                  \
00742 }                                                                                       \
00743 itkTypeMacro(newexcp, parentexcp);                                                      \
00744 };                                                                                      \
00745 }
00746 
00747 #define itkSpecializedExceptionMacro(exceptiontype)                                     \
00748     {                                                                                   \
00749     ::itk::exceptiontype e_(__FILE__, __LINE__);                                        \
00750     e_.SetLocation(ITK_LOCATION);                                                       \
00751     throw e_; /* Explicit naming to work around Intel compiler bug.  */                 \
00752     }
00753 
00754 #define itkSpecializedMessageExceptionMacro(exceptiontype,x)                            \
00755     {                                                                                   \
00756     ::itk::exceptiontype e_(__FILE__, __LINE__);                                        \
00757     std::ostringstream message;                                                         \
00758     message << "itk::ERROR: " x;                                                        \
00759     e_.SetDescription(message.str().c_str());                                           \
00760     e_.SetLocation(ITK_LOCATION);                                                       \
00761     throw e_; /* Explicit naming to work around Intel compiler bug.  */                 \
00762     }
00763 
00764 
00765 #define itkGenericOutputMacro(x)                                           \
00766     {                                                                      \
00767     if ( ::itk::Object::GetGlobalWarningDisplay() )                        \
00768       {                                                                    \
00769       std::ostringstream itkmsg;                                           \
00770       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n"      \
00771       x << "\n\n";                                                         \
00772       ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \
00773       }                                                                    \
00774     }
00775 
00776 //----------------------------------------------------------------------------
00777 // Macros for simplifying the use of logging
00778 //
00779 #define itkLogMacro(x, y)                                \
00780     {                                                    \
00781     if ( this->GetLogger() )                             \
00782       {                                                  \
00783       this->GetLogger()->Write(::itk::LoggerBase::x, y); \
00784       }                                                  \
00785     }
00786 
00787 #define itkLogMacroStatic(obj, x, y)                    \
00788     {                                                   \
00789     if ( obj->GetLogger() )                             \
00790       {                                                 \
00791       obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
00792       }                                                 \
00793     }
00794 
00795 //----------------------------------------------------------------------------
00796 // Setup legacy code policy.
00797 //
00798 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted
00799 // They may be used to completely remove legacy code or silence the
00800 // warnings.  The default is to warn about their use.
00801 //
00802 // Source files that test the legacy code may define ITK_LEGACY_TEST
00803 // like this:
00804 //
00805 //  #define ITK_LEGACY_TEST
00806 //  #include "itkClassWithDeprecatedMethod.h"
00807 //
00808 // in order to silence the warnings for calling deprecated methods.
00809 // No other source files in ITK should call the methods since they are
00810 // provided only for compatibility with older user code.
00811 
00812 // Define itkLegacyMacro to mark legacy methods where they are
00813 // declared in their class.  Example usage:
00814 //
00815 //   // @deprecated Replaced by MyOtherMethod() as of ITK 2.0.
00816 //   itkLegacyMacro(void MyMethod());
00817 #if defined( ITK_LEGACY_REMOVE )
00818 // Remove legacy methods completely.  Put a bogus declaration in
00819 // place to avoid stray semicolons because this is an error for some
00820 // compilers.  Using a class forward declaration allows any number
00821 // of repeats in any context without generating unique names.
00822 #define itkLegacyMacro(method) class itkLegacyMethodRemoved /* no ';' */
00823 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( CSWIG )
00824 // Provide legacy methods with no warnings.
00825 #define itkLegacyMacro(method) method
00826 #else
00827 // Setup compile-time warnings for uses of deprecated methods if
00828 // possible on this compiler.
00829 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) )
00830 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) )
00831 #elif defined( _MSC_VER )
00832 #define itkLegacyMacro(method) __declspec(deprecated) method
00833 #else
00834 #define itkLegacyMacro(method) method
00835 #endif
00836 #endif
00837 
00838 // Macros to create runtime deprecation warning messages in function
00839 // bodies.  Example usage:
00840 //
00841 //   void itkMyClass::MyOldMethod()
00842 //     {
00843 //     itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
00844 //     }
00845 //
00846 //   void itkMyClass::MyMethod()
00847 //     {
00848 //     itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
00849 //                               itkMyClass::MyOtherMethod);
00850 //     }
00851 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT )
00852 #define itkLegacyBodyMacro(method, version)
00853 #define itkLegacyReplaceBodyMacro(method, version, replace)
00854 #define itkGenericLegacyBodyMacro(method, version)
00855 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)
00856 #else
00857 #define itkLegacyBodyMacro(method, version) \
00858   itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00859 #define itkLegacyReplaceBodyMacro(method, version, replace)                                                   \
00860   itkWarningMacro(                                                                                            \
00861     #method " was deprecated for ITK " #version " and will be removed in a future version.  Use " #replace \
00862     " instead.")
00863 #define itkGenericLegacyBodyMacro(method, version) \
00864   itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
00865 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)                                            \
00866   itkGenericOutputMacro(                                                                                      \
00867     #method " was deprecated for ITK " #version " and will be removed in a future version.  Use " #replace \
00868     " instead.")
00869 #endif
00870 
00871 //=============================================================================
00872 /* Define a common way of declaring a templated function as a friend inside a class.
00873   - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
00874 
00875   The following templated function
00876 
00877             template <T>
00878             T add(const T & a, const T & b);
00879 
00880   is declared as friend in some compilers as:
00881 
00882             class A
00883               {
00884               public:
00885                 friend Self add<Self>( const Self & a, const Self & b );
00886               }
00887 
00888    while other compilers will do
00889 
00890             class A
00891               {
00892               public:
00893                 friend Self add<>( const Self & a, const Self & b );
00894               }
00895 
00896    This characteristic of the compiler is checked by a TRY_COMPILE
00897    command defined in Insight/CMake/itkTestFriendTemplatedFunction.cxx
00898 
00899 */
00900 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_NULL_STRING )
00901 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
00902 #else
00903 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_EMPTY_BRACKETS )
00904 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)  < >
00905 #else
00906 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_TEMPLATE_ARGUMENTS )
00907 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)  < T >
00908 #endif
00909 #endif
00910 #endif
00911 // THIS IS A TEMPORARY PATCH FOR Visual Studio 10. The correct solution must
00912 // be implemented in Insight/CMake/itkTestFriendTemplatedFunction.cxx
00913 #if ( defined ( _MSC_VER ) && ( _MSC_VER >= 1600 ) )
00914 #ifdef  ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
00915 #undef  ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
00916 #endif
00917 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
00918 #endif
00919 
00920 //=============================================================================
00921 /* Choose a way to prevent template instantiation on this platform.
00922   - ITK_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
00923                                       prevent instantiation
00924   - ITK_TEMPLATE_EXTERN = use extern template to prevent instantiation
00925 
00926    Note that VS 6 supports extern template instantiation but it is
00927    hard to block the resulting warning because its stream headers
00928    re-enable it.  Therefore we just disable support for now.
00929 */
00930 #if defined( __INTEL_COMPILER ) && __INTEL_COMPILER >= 700
00931 #define ITK_TEMPLATE_EXTERN 1
00932 #elif defined( __GNUC__ ) && __GNUC__ >= 3
00933 #define ITK_TEMPLATE_EXTERN 1
00934 #elif defined( _MSC_VER )
00935 #define ITK_TEMPLATE_EXTERN 1
00936 #endif
00937 #if !defined( ITK_TEMPLATE_DO_NOT_INSTANTIATE )
00938 #define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
00939 #endif
00940 #if !defined( ITK_TEMPLATE_EXTERN )
00941 #define ITK_TEMPLATE_EXTERN 0
00942 #endif
00943 
00944 /* Define a macro to explicitly instantiate a template.
00945   - ITK_TEMPLATE_EXPORT(X) =
00946       Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
00947       examples: ITK_TEMPLATE_EXPORT(1(class Foo<int>))
00948                 ITK_TEMPLATE_EXPORT(2(class Bar<int, char>))
00949       Use one level of expansion delay to allow user code to have
00950       a macro determining the number of arguments. */
00951 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
00952 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
00953 
00954 /* Define a macro to prevent template instantiations.
00955   - ITK_TEMPLATE_IMPORT(X) =
00956       Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
00957       examples: ITK_TEMPLATE_IMPORT(1(class Foo<int>))
00958                 ITK_TEMPLATE_IMPORT(2(class Bar<int, char>))
00959       Use one level of expansion delay to allow user code to have
00960       a macro determining the number of arguments.
00961 */
00962 #if ITK_TEMPLATE_EXTERN
00963 #define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
00964 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
00965 #define ITK_TEMPLATE_IMPORT_DELAY(x) \
00966   ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
00967 #define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00968 #endif
00969 #if defined( ITK_TEMPLATE_IMPORT_DELAY )
00970 #define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
00971 #define ITK_TEMPLATE_IMPORT_WORKS 1
00972 #else
00973 #define ITK_TEMPLATE_IMPORT(x)
00974 #define ITK_TEMPLATE_IMPORT_WORKS 0
00975 #endif
00976 
01042 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \
01043   ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y)
01044 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \
01045   ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y)
01046 #define ITK_EMPTY
01047 
01048 /* Define macros to support passing a variable number of arguments
01049    throug other macros.  This is used by ITK_TEMPLATE_EXPORT,
01050    ITK_TEMPLATE_IMPORT, and by each template's instantiation
01051    macro.  */
01052 #define ITK_TEMPLATE_1(x1)                         x1
01053 #define ITK_TEMPLATE_2(x1, x2)                      x1, x2
01054 #define ITK_TEMPLATE_3(x1, x2, x3)                   x1, x2, x3
01055 #define ITK_TEMPLATE_4(x1, x2, x3, x4)                x1, x2, x3, x4
01056 #define ITK_TEMPLATE_5(x1, x2, x3, x4, x5)             x1, x2, x3, x4, x5
01057 #define ITK_TEMPLATE_6(x1, x2, x3, x4, x5, x6)          x1, x2, x3, x4, x5, x6
01058 #define ITK_TEMPLATE_7(x1, x2, x3, x4, x5, x6, x7)       x1, x2, x3, x4, x5, x6, x7
01059 #define ITK_TEMPLATE_8(x1, x2, x3, x4, x5, x6, x7, x8)    x1, x2, x3, x4, x5, x6, x7, x8
01060 #define ITK_TEMPLATE_9(x1, x2, x3, x4, x5, x6, x7, x8, x9) x1, x2, x3, x4, x5, x6, x7, x8, x9
01061 
01062 /* In order to support both implicit and explicit instantation a .h
01063    file needs to know whether it should include its .hxx file
01064    containing the template definitions.  Define a macro to tell
01065    it.  Typical usage in itkFoo.h:
01066      #if ITK_TEMPLATE_TXX
01067      #include "itkFoo.hxx"
01068      #endif
01069 */
01070 #ifndef ITK_TEMPLATE_CXX //At this point this variable MUST be defined
01071 #define ITK_TEMPLATE_CXX 0
01072 #endif
01073 #ifndef ITK_TEMPLATE_TYPE
01074 #define ITK_TEMPLATE_TYPE 0
01075 #endif
01076 #if defined( ITK_MANUAL_INSTANTIATION )
01077 #define ITK_TEMPLATE_TXX 0
01078 #else
01079 #define ITK_TEMPLATE_TXX !( ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE )
01080 #endif
01081 
01082 /* All explicit instantiation source files define ITK_TEMPLATE_CXX.
01083    Define ITK_MANUAL_INSTANTIATION to tell .h files that have not been
01084    converted to this explicit instantiation scheme to not include
01085    their .hxx files.  Also disable warnings that commonly occur in
01086    these files but are not useful.  */
01087 #if ITK_TEMPLATE_CXX
01088 #undef ITK_MANUAL_INSTANTIATION
01089 #define ITK_MANUAL_INSTANTIATION
01090 #endif
01091 //=============================================================================
01092 
01093 /* Define macros to export and import template instantiations for each
01094    library in ITK.  */
01095 #define ITK_EXPORT_ITKCommon(c, x, n) \
01096   ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
01097 #define ITK_IMPORT_ITKCommon(c, x, n) \
01098   ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
01099 
01100 /* Define a macro to decide whether to block instantiation of ITK
01101    templates.  They should be blocked only if the platform supports
01102    blocking template instantiation and the explicit instantiations are
01103    available.
01104 
01105    - ITK_TEMPLATE_EXPLICIT =
01106       Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
01107       instantiations of templates explicitly instantiated elsewhere.
01108       Typical usage in itkFoo.h:
01109         #if ITK_TEMPLATE_EXPLICIT
01110         #include "itkFoo+-.h"
01111         #endif
01112 */
01113 #if ITK_TEMPLATE_IMPORT_WORKS && defined( ITK_EXPLICIT_INSTANTIATION )
01114 #define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX
01115 #else
01116 #define ITK_TEMPLATE_EXPLICIT 0
01117 #endif
01118 
01119 //--------------------------------------------------------------------------------
01120 //  Helper macros for Template Meta-Programming techniques of for-loops
01121 // unrolling
01122 //--------------------------------------------------------------------------------
01123 
01124 //--------------------------------------------------------------------------------
01125 // Macro that generates an unrolled for loop for assigning elements of one array
01126 // to elements of another array The array are assumed to be of same length
01127 // (dimension), and this is also assumed to be the value of NumberOfIterations.
01128 // No verification of size is performed. Casting is perfomed as part of the
01129 // assignment, by using the DestinationElementType as the casting type.
01130 // Source and destination array types must have defined opearator[] in their
01131 // API.
01132 #define itkForLoopAssignmentMacro(DestinationType,                                 \
01133                                   SourceType,                                      \
01134                                   DestinationElementType,                          \
01135                                   DestinationArray,                                \
01136                                   SourceArray,                                     \
01137                                   NumberOfIterations)                              \
01138   for ( unsigned int i = 0; i < NumberOfIterations; ++i )                          \
01139     {                                                                              \
01140     DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
01141     }
01142 
01143 //--------------------------------------------------------------------------------
01144 // Macro that generates an unrolled for loop for rounding and assigning
01145 // elements of one array to elements of another array The array are assumed to
01146 // be of same length (dimension), and this is also assumed to be the value of
01147 // NumberOfIterations.  No verification of size is performed. Casting is
01148 // perfomed as part of the assignment, by using the DestinationElementType as
01149 // the casting type.
01150 // Source and destination array types must have defined opearator[] in their
01151 // API.
01152 #define itkForLoopRoundingAndAssignmentMacro(DestinationType,                         \
01153                                              Sourcrnd_halfintup,                      \
01154                                              DestinationElementType,                  \
01155                                              DestinationArray,                        \
01156                                              SourceArray,                             \
01157                                              NumberOfIterations)                      \
01158   for ( unsigned int i = 0; i < NumberOfIterations; ++i )                             \
01159     {                                                                                 \
01160     DestinationArray[i] = itk::Math::Round< DestinationElementType >(SourceArray[i]); \
01161     }
01162 
01163 // end of Template Meta Programming helper macros
01164 
01165 #ifndef NDEBUG
01166 
01167 #ifdef _POSIX_SOURCE
01168 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
01169 #else
01170 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
01171 #endif
01172 
01173 #else
01174 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
01175 #endif
01176 
01177 #define itkAssertOrThrowMacro(test, message)                       \
01178   if ( !( test ) )                                                 \
01179     {                                                              \
01180     std::ostringstream msgstr;                                     \
01181     msgstr << message;                                             \
01182     itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
01183     }
01184 
01185 #ifndef NDEBUG
01186 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
01187 #else
01188 #define itkAssertInDebugAndIgnoreInReleaseMacro(X)
01189 #endif
01190 
01191 #ifdef ITKV3_COMPATIBILITY
01192 // As of MSVS++ 7.1 and greater, typename is supported in templates
01193 // All ITKv4 compilers support the typename keyword, but this is
01194 // needed to ease transition from ITKv3.
01195 #define ITK_TYPENAME typename
01196 #endif
01197 
01198 
01199 #endif //end of itkMacro.h
01200