Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

igtlMacro.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Open IGT Link Library
00004   Module:    $HeadURL: http://svn.na-mic.org/NAMICSandBox/trunk/OpenIGTLink/Source/igtlMacro.h $
00005   Language:  C++
00006   Date:      $Date: 2008-12-22 19:05:42 -0500 (Mon, 22 Dec 2008) $
00007   Version:   $Revision: 3460 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010 
00011   This software is distributed WITHOUT ANY WARRANTY; without even
00012   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00013   PURPOSE.  See the above copyright notices for more information.
00014 
00015 =========================================================================*/
00016 /*=========================================================================
00017 
00018   Program:   Insight Segmentation & Registration Toolkit
00019   Module:    $RCSfile: itkMacro.h,v $
00020   Language:  C++
00021   Date:      $Date: 2008-12-22 19:05:42 -0500 (Mon, 22 Dec 2008) $
00022   Version:   $Revision: 3460 $
00023 
00024   Copyright (c) Insight Software Consortium. All rights reserved.
00025   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00026 
00027   Portions of this code are covered under the VTK copyright.
00028   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
00029 
00030      This software is distributed WITHOUT ANY WARRANTY; without even 
00031      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00032      PURPOSE.  See the above copyright notices for more information.
00033 
00034 =========================================================================*/
00045 #ifndef __igtlMacro_h
00046 #define __igtlMacro_h
00047 
00048 #include "igtlWin32Header.h"
00049 //#include "igtlConfigure.h"
00050 
00051 #include <string>
00052 
00053 // Determine type of string stream to use.
00054 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
00055 #  include <sstream>
00056 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
00057 #  include <strstream>
00058 #  define IGTL_NO_ANSI_STRING_STREAM
00059 #else
00060 #  include <strstream.h>
00061 #  define IGTL_NO_ANSI_STRING_STREAM
00062 #endif
00063 
00068 namespace igtl
00069 {
00070 } // end namespace igtl - this is here for documentation purposes
00071 
00074 #define igtlNotUsed(x)
00075 
00090 #if defined(_MSC_VER) && (_MSC_VER <= 1300) 
00091 #   define IGTL_NO_INCLASS_MEMBER_INITIALIZATION
00092 #endif
00093 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x540)
00094 #   define IGTL_NO_INCLASS_MEMBER_INITIALIZATION
00095 #endif
00096 #if defined(__SVR4) && !defined(__SUNPRO_CC)
00097 #   define IGTL_NO_INCLASS_MEMBER_INITIALIZATION
00098 #endif
00099 
00100 // A class template like this will not instantiate on GCC 2.95:
00101 //   template<class T> struct A
00102 //   {
00103 //     static const int N = 1;
00104 //     enum { S = sizeof(A::N) };
00105 //   };
00106 // We need to use enum for static constants instead.
00107 #if defined(__GNUC__)
00108 # define IGTL_NO_SIZEOF_CONSTANT_LOOKUP
00109 #endif
00110 
00111 #if defined(_MSC_VER) && (_MSC_VER <= 1300) 
00112 #define IGTL_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
00113 #endif
00114 
00115 #if defined(IGTL_NO_INCLASS_MEMBER_INITIALIZATION) || \
00116     defined(IGTL_NO_SIZEOF_CONSTANT_LOOKUP)
00117 #   define igtlStaticConstMacro(name,type,value) enum { name = value }
00118 #else
00119 #   define igtlStaticConstMacro(name,type,value) static const type name = value
00120 #endif
00121 
00122 #ifdef IGTL_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
00123 #   define igtlGetStaticConstMacro(name) name
00124 #else
00125 #   define igtlGetStaticConstMacro(name) (Self::name)
00126 #endif
00127 
00129 #define igtlSetInputMacro(name, type, number) \
00130   virtual void Set##name##Input(const type *_arg) \
00131   { \
00132     igtlDebugMacro("setting input " #name " to " << _arg); \
00133     if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \
00134       { \
00135       this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \
00136       } \
00137   } \
00138   virtual void SetInput##number(const type *_arg) \
00139   { \
00140     igtlDebugMacro("setting input " #number " to " << _arg); \
00141     if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \
00142       { \
00143       this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \
00144       } \
00145   } 
00146 
00147 
00149 #define igtlSuperclassTraitMacro(traitnameType) \
00150   typedef typename Superclass::traitnameType traitnameType;
00151 
00153 #define igtlGetInputMacro(name, type, number) \
00154   virtual const type * Get##name##Input() const \
00155   { \
00156     igtlDebugMacro("returning input " << #name " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
00157     return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
00158   } \
00159   virtual const type * GetInput##number() const \
00160   { \
00161     igtlDebugMacro("returning input " << #number " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
00162     return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
00163   } 
00164 
00165 
00168 #define igtlSetDecoratedInputMacro(name, type, number) \
00169   igtlSetInputMacro(name, SimpleDataObjectDecorator<type>, number); \
00170   igtlGetInputMacro(name, SimpleDataObjectDecorator<type>, number); \
00171   virtual void Set##name(const type &_arg) \
00172   { \
00173     typedef SimpleDataObjectDecorator< type > DecoratorType; \
00174     igtlDebugMacro("setting input " #name " to " << _arg); \
00175     const DecoratorType * oldInput = \
00176       static_cast< const DecoratorType * >( \
00177         this->ProcessObject::GetInput(number) ); \
00178     if( oldInput && oldInput->Get() == _arg ) \
00179       { \
00180       return; \
00181       } \
00182     typename DecoratorType::Pointer newInput = DecoratorType::New(); \
00183     newInput->Set( _arg ); \
00184     this->Set##name##Input( newInput ); \
00185   }
00186 
00187 
00191 #define igtlSetDecoratedObjectInputMacro(name, type, number) \
00192   igtlSetInputMacro(name, DataObjectDecorator<type>, number); \
00193   igtlGetInputMacro(name, DataObjectDecorator<type>, number); \
00194   virtual void Set##name(const type *_arg) \
00195   { \
00196     typedef DataObjectDecorator< type > DecoratorType; \
00197     igtlDebugMacro("setting input " #name " to " << _arg); \
00198     const DecoratorType * oldInput = \
00199       static_cast< const DecoratorType * >( \
00200         this->ProcessObject::GetInput(number) ); \
00201     if( oldInput && oldInput->Get() == _arg ) \
00202       { \
00203       return; \
00204       } \
00205     typename DecoratorType::Pointer newInput = DecoratorType::New(); \
00206     newInput->Set( _arg ); \
00207     this->Set##name##Input( newInput ); \
00208   }
00209 
00210 
00211 
00213 #define igtlSetMacro(name,type) \
00214   virtual void Set##name (const type _arg) \
00215   { \
00216     igtlDebugMacro("setting " #name " to " << _arg); \
00217     if (this->m_##name != _arg) \
00218       { \
00219       this->m_##name = _arg; \
00220       } \
00221   } 
00222 
00223 
00225 #define igtlGetMacro(name,type) \
00226   virtual type Get##name () \
00227   { \
00228     igtlDebugMacro("returning " << #name " of " << this->m_##name ); \
00229     return this->m_##name; \
00230   }
00231 
00232 
00236 #define igtlGetConstMacro(name,type) \
00237   virtual type Get##name () const \
00238   { \
00239     igtlDebugMacro("returning " << #name " of " << this->m_##name ); \
00240     return this->m_##name; \
00241   }
00242 
00243 
00248 #define igtlGetConstReferenceMacro(name,type) \
00249   virtual const type & Get##name () const \
00250   { \
00251     igtlDebugMacro("returning " << #name " of " << this->m_##name ); \
00252     return this->m_##name; \
00253   }
00254 
00255 
00259 #define igtlSetEnumMacro(name,type) \
00260   virtual void Set##name (const type _arg) \
00261   { \
00262     igtlDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
00263     if (this->m_##name != _arg) \
00264       { \
00265       this->m_##name = _arg; \
00266       } \
00267   } 
00268 
00269 
00273 #define igtlGetEnumMacro(name,type) \
00274   virtual type Get##name () const \
00275   { \
00276     igtlDebugMacro("returning " << #name " of " << static_cast<long>(this->m_##name) ); \
00277     return this->m_##name; \
00278   }
00279 
00280 
00284 #define igtlSetStringMacro(name) \
00285   virtual void Set##name (const char* _arg) \
00286   { \
00287     if ( _arg && (_arg == this->m_##name) ) { return;} \
00288     if (_arg) \
00289       { \
00290       this->m_##name = _arg;\
00291       } \
00292      else \
00293       { \
00294       this->m_##name = ""; \
00295       } \
00296   } \
00297   virtual void Set##name (const std::string & _arg) \
00298   { \
00299     this->Set##name( _arg.c_str() ); \
00300   } \
00301 
00302 
00303 
00307 #define igtlGetStringMacro(name) \
00308   virtual const char* Get##name () const \
00309   { \
00310     return this->m_##name.c_str(); \
00311   }
00312 
00316 #define igtlSetClampMacro(name,type,min,max) \
00317   virtual void Set##name (type _arg) \
00318   { \
00319     igtlDebugMacro("setting " << #name " to " << _arg ); \
00320     if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
00321       { \
00322       this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
00323       } \
00324   } 
00325 
00326 
00331 #define igtlSetObjectMacro(name,type) \
00332   virtual void Set##name (type* _arg) \
00333   { \
00334     igtlDebugMacro("setting " << #name " to " << _arg ); \
00335     if (this->m_##name != _arg) \
00336       { \
00337       this->m_##name = _arg; \
00338       } \
00339   } 
00340 
00341 
00344 #define igtlGetObjectMacro(name,type) \
00345   virtual type * Get##name () \
00346   { \
00347     igtlDebugMacro("returning " #name " address " << this->m_##name ); \
00348     return this->m_##name.GetPointer(); \
00349   } 
00350 
00351 
00356 #define igtlSetConstObjectMacro(name,type) \
00357   virtual void Set##name (const type* _arg) \
00358   { \
00359     igtlDebugMacro("setting " << #name " to " << _arg ); \
00360     if (this->m_##name != _arg) \
00361       { \
00362       this->m_##name = _arg; \
00363       } \
00364   } 
00365 
00366 
00367 
00370 #define igtlGetConstObjectMacro(name,type) \
00371   virtual const type * Get##name () const \
00372   { \
00373     igtlDebugMacro("returning " #name " address " << this->m_##name ); \
00374     return this->m_##name.GetPointer(); \
00375   } 
00376 
00377 
00380 #define igtlGetConstReferenceObjectMacro(name,type) \
00381   virtual const typename type::Pointer & Get##name () const \
00382   { \
00383     igtlDebugMacro("returning " #name " address " << this->m_##name ); \
00384     return this->m_##name; \
00385   } 
00386 
00387 
00390 #define igtlBooleanMacro(name) \
00391   virtual void name##On () { this->Set##name(true);} \
00392   virtual void name##Off () { this->Set##name(false);}
00393 
00394 
00398 #define igtlSetVectorMacro(name,type,count) \
00399   virtual void Set##name(type data[]) \
00400   { \
00401     unsigned int i; \
00402     for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
00403     if ( i < count ) \
00404       { \
00405       for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
00406       } \
00407   }
00408 
00409 
00412 #define igtlGetVectorMacro(name,type,count) \
00413   virtual type *Get##name () const \
00414   { \
00415     return this->m_##name; \
00416   } 
00417 
00434 #define igtlNewMacro(x) \
00435 static Pointer New(void) \
00436 { \
00437   Pointer smartPtr = ::igtl::ObjectFactory<x>::Create(); \
00438   if(smartPtr.GetPointer() == NULL) \
00439     { \
00440     smartPtr = new x; \
00441     } \
00442   smartPtr->UnRegister(); \
00443   return smartPtr; \
00444 } \
00445 virtual ::igtl::LightObject::Pointer CreateAnother(void) const \
00446 { \
00447   ::igtl::LightObject::Pointer smartPtr; \
00448   smartPtr = x::New().GetPointer(); \
00449   return smartPtr; \
00450 }
00451 
00452 
00453 
00470 #define igtlFactorylessNewMacro(x) \
00471 static Pointer New(void) \
00472 { \
00473   Pointer smartPtr; \
00474   x *rawPtr = new x; \
00475   smartPtr = rawPtr; \
00476   rawPtr->UnRegister(); \
00477   return smartPtr; \
00478 } \
00479   virtual ::igtl::LightObject::Pointer CreateAnother(void) const \
00480 { \
00481   ::igtl::LightObject::Pointer smartPtr;         \
00482   smartPtr = x::New().GetPointer(); \
00483   return smartPtr; \
00484 }
00485 
00486 
00489 #define igtlTypeMacro(thisClass,superclass) \
00490     virtual const char *GetNameOfClass() const \
00491         {return #thisClass;} 
00492 
00493 
00494 //namespace igtl
00495 //{
00502 //extern IGTLCommon_EXPORT void OutputWindowDisplayText(const char*);
00503 //extern IGTLCommon_EXPORT void OutputWindowDisplayErrorText(const char*);
00504 //extern IGTLCommon_EXPORT void OutputWindowDisplayWarningText(const char*);
00505 //extern IGTLCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char*);
00506 //extern IGTLCommon_EXPORT void OutputWindowDisplayDebugText(const char*);
00507 //} // end namespace igtl
00509 
00513 #if defined(IGTL_LEAN_AND_MEAN) || defined(__BORLANDC__)
00514 #define igtlDebugMacro(x)
00515 #else
00516 #define igtlDebugMacro(x) \
00517   { if (this->GetDebug() /*&& ::igtl::Object::GetGlobalWarningDisplay()*/)   \
00518     { ::igtl::OStringStream igtlmsg; \
00519       igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00520              << this->GetNameOfClass() << " (" << this << "): " x  \
00521              << "\n\n"; \
00522       std::cerr << igtlmsg; /*::igtl::OutputWindowDisplayDebugText(igtlmsg.str().c_str());*/} \
00523 }
00524 #endif
00525 
00526 
00527 
00531 #ifdef IGTL_LEAN_AND_MEAN
00532 #define igtlWarningMacro(x)
00533 #else
00534 #define igtlWarningMacro(x) \
00535   { if ( 1/*::igtl::Object::GetGlobalWarningDisplay()*/)  \
00536     { ::igtl::OStringStream igtlmsg; \
00537       igtlmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00538              << this->GetNameOfClass() << " (" << this << "): " x  \
00539              << "\n\n"; \
00540       std::cerr << igtlmsg; /*::igtl::OutputWindowDisplayWarningText(igtlmsg.str().c_str());*/} \
00541 }
00542 #endif
00543 
00544 
00545 namespace igtl
00546 {
00547 
00553 #if !defined(IGTL_NO_ANSI_STRING_STREAM)
00554 class OStringStream: public std::ostringstream
00555 {
00556 public:
00557   OStringStream() {}
00558 private:
00559   OStringStream(const OStringStream&);
00560   void operator=(const OStringStream&);
00561 };
00562 #else
00563 namespace OStringStreamDetail
00564 {
00565   class Cleanup
00566   {
00567   public:
00568     Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
00569     ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
00570     static void IgnoreUnusedVariable(const Cleanup&) {}
00571   protected:
00572     std::ostrstream& m_OStrStream;
00573   };
00574 }//namespace OStringStreamDetail
00576 
00577 class OStringStream: public std::ostrstream
00578 {
00579 public:
00580   typedef std::ostrstream Superclass;
00581   OStringStream() {}
00582   std::string str()
00583     {
00584       OStringStreamDetail::Cleanup cleanup(*this);
00585       OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
00586       int pcount = this->pcount();
00587       const char* ptr = this->Superclass::str();
00588       return std::string(ptr?ptr:"", pcount);
00589     }
00590 private:
00591   OStringStream(const OStringStream&);
00592   void operator=(const OStringStream&);
00593 };
00594 #endif
00595 
00596 }//namespace igtl
00597 
00598 #if defined(IGTL_CPP_FUNCTION)
00599   #if defined(__BORLANDC__)
00600     #define IGTL_LOCATION __FUNC__
00601   #elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(CABLE_CONFIGURATION) && !defined(CSWIG)
00602     #define IGTL_LOCATION __FUNCSIG__
00603   #elif defined(__GNUC__)
00604     #define IGTL_LOCATION __PRETTY_FUNCTION__
00605   #else
00606     #define IGTL_LOCATION __FUNCTION__
00607   #endif
00608 #else
00609   #define IGTL_LOCATION "unknown"
00610 #endif
00611 
00612 #define igtlExceptionMacro(x) \
00613   { \
00614   ::igtl::OStringStream igtlmsg;                                 \
00615   igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00616           << this->GetNameOfClass() << " (" << this << "): " x   \
00617           << "\n\n";                                             \
00618   std::cerr << igtlmsg; /*::igtl::OutputWindowDisplayDebugText(igtlmsg.str().c_str());*/ \
00619 }
00620 
00621 #define igtlErrorMacro(x) \
00622   { \
00623   ::igtl::OStringStream igtlmsg;                                 \
00624   igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
00625           << this->GetNameOfClass() << " (" << this << "): " x   \
00626           << "\n\n";                                             \
00627   std::cerr << igtlmsg; /*::igtl::OutputWindowDisplayDebugText(igtlmsg.str().c_str());*/ \
00628 }
00629 
00630 
00631 
00632 
00633 #ifdef IGTL_LEAN_AND_MEAN
00634 #define igtlGenericOutputMacro(x)
00635 #else
00636 #define igtlGenericOutputMacro(x) \
00637   { if (1/*::igtl::Object::GetGlobalWarningDisplay()*/) \
00638     { ::igtl::OStringStream igtlmsg; \
00639       igtlmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00640              x << "\n\n"; \
00641       std::cerr << igtlmsg;/*::igtl::OutputWindowDisplayGenericOutputText(igtlmsg.str().c_str());*/} \
00642 }
00643 #endif
00644 
00645 
00646 
00647 //----------------------------------------------------------------------------
00648 // Macros for simplifying the use of logging
00649 //
00650 #define igtlLogMacro( x, y)  \
00651 {         \
00652   if (this->GetLogger() ) \
00653     {  \
00654     this->GetLogger()->Write(::igtl::LoggerBase::x, y); \
00655     }  \
00656 }
00657 
00658 
00659 #define igtlLogMacroStatic( obj, x, y)  \
00660 {         \
00661   if (obj->GetLogger() ) \
00662     {  \
00663     obj->GetLogger()->Write(::igtl::LoggerBase::x, y); \
00664     }  \
00665 }
00666 
00667 
00668 //----------------------------------------------------------------------------
00669 // Setup legacy code policy.
00670 //
00671 // CMake options IGTL_LEGACY_REMOVE and IGTL_LEGACY_SILENT are converted
00672 // to definitions (or non-defs) in igtlConfigure.h and tested below.
00673 // They may be used to completely remove legacy code or silence the
00674 // warnings.  The default is to warn about their use.
00675 //
00676 // Source files that test the legacy code may define IGTL_LEGACY_TEST
00677 // like this:
00678 //
00679 //  #define IGTL_LEGACY_TEST
00680 //  #include "igtlClassWithDeprecatedMethod.h"
00681 //
00682 // in order to silence the warnings for calling deprecated methods.
00683 // No other source files in IGTL should call the methods since they are
00684 // provided only for compatibility with older user code.
00685 
00686 // Define igtlLegacyMacro to mark legacy methods where they are
00687 // declared in their class.  Example usage:
00688 //
00689 //   // @deprecated Replaced by MyOtherMethod() as of IGTL 2.0.
00690 //   igtlLegacyMacro(void MyMethod());
00691 #if defined(IGTL_LEGACY_REMOVE)
00692 // Remove legacy methods completely.  Put a bogus declaration in
00693 // place to avoid stray semicolons because this is an error for some
00694 // compilers.  Using a class forward declaration allows any number
00695 // of repeats in any context without generating unique names.
00696 # define igtlLegacyMacro(method) class igtlLegacyMethodRemoved /* no ';' */
00697 #elif defined(IGTL_LEGACY_SILENT) || defined(IGTL_LEGACY_TEST) || defined(CSWIG)
00698   // Provide legacy methods with no warnings.
00699 # define igtlLegacyMacro(method) method
00700 #else
00701   // Setup compile-time warnings for uses of deprecated methods if
00702   // possible on this compiler.
00703 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00704 #  define igtlLegacyMacro(method) method __attribute__((deprecated))
00705 # elif defined(_MSC_VER) && _MSC_VER >= 1300
00706 #  define igtlLegacyMacro(method) __declspec(deprecated) method
00707 # else
00708 #  define igtlLegacyMacro(method) method
00709 # endif
00710 #endif
00711 
00712 // Macros to create runtime deprecation warning messages in function
00713 // bodies.  Example usage:
00714 //
00715 //   void igtlMyClass::MyOldMethod()
00716 //     {
00717 //     igtlLegacyBodyMacro(igtlMyClass::MyOldMethod, 2.0);
00718 //     }
00719 //
00720 //   void igtlMyClass::MyMethod()
00721 //     {
00722 //     igtlLegacyReplaceBodyMacro(igtlMyClass::MyMethod, 2.0,
00723 //                               igtlMyClass::MyOtherMethod);
00724 //     }
00725 #if defined(IGTL_LEGACY_REMOVE) || defined(IGTL_LEGACY_SILENT)
00726 # define igtlLegacyBodyMacro(method, version)
00727 # define igtlLegacyReplaceBodyMacro(method, version, replace)
00728 #else
00729 # define igtlLegacyBodyMacro(method, version) \
00730   igtlWarningMacro(#method " was deprecated for IGTL " #version " and will be removed in a future version.")
00731 # define igtlLegacyReplaceBodyMacro(method, version, replace) \
00732   igtlWarningMacro(#method " was deprecated for IGTL " #version " and will be removed in a future version.  Use " #replace " instead.")
00733 #endif
00734 
00735 #if defined(__INTEL_COMPILER)
00736 # pragma warning (disable: 193) /* #if testing undefined identifier */
00737 #endif
00738 
00739 //=============================================================================
00740 /* Choose a way to prevent template instantiation on this platform.
00741   - IGTL_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
00742                                       prevent instantiation
00743   - IGTL_TEMPLATE_EXTERN = use extern template to prevent instantiation
00744 
00745    Note that VS 6 supports extern template instantiation but it is
00746    hard to block the resulting warning because its stream headers
00747    re-enable it.  Therefore we just disable support for now.
00748 */
00749 #if defined(__sgi) && defined(_COMPILER_VERSION)
00750 # define IGTL_TEMPLATE_DO_NOT_INSTANTIATE 1
00751 #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
00752 # define IGTL_TEMPLATE_EXTERN 1
00753 #elif defined(__GNUC__) && __GNUC__ >= 3
00754 # define IGTL_TEMPLATE_EXTERN 1
00755 #elif defined(_MSC_VER) && _MSC_VER >= 1300
00756 # define IGTL_TEMPLATE_EXTERN 1
00757 #endif
00758 #if !defined(IGTL_TEMPLATE_DO_NOT_INSTANTIATE)
00759 # define IGTL_TEMPLATE_DO_NOT_INSTANTIATE 0
00760 #endif
00761 #if !defined(IGTL_TEMPLATE_EXTERN)
00762 # define IGTL_TEMPLATE_EXTERN 0
00763 #endif
00764 
00765 /* Define a macro to explicitly instantiate a template.
00766   - IGTL_TEMPLATE_EXPORT(X) =
00767       Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
00768       examples: IGTL_TEMPLATE_EXPORT(1(class Foo<int>))
00769                 IGTL_TEMPLATE_EXPORT(2(class Bar<int, char>))
00770       Use one level of expansion delay to allow user code to have
00771       a macro determining the number of arguments. */
00772 #define IGTL_TEMPLATE_EXPORT(x) IGTL_TEMPLATE_EXPORT_DELAY(x)
00773 #define IGTL_TEMPLATE_EXPORT_DELAY(x) template IGTL_TEMPLATE_##x;
00774 
00775 /* Define a macro to prevent template instantiations.
00776   - IGTL_TEMPLATE_IMPORT(X) =
00777       Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
00778       examples: IGTL_TEMPLATE_IMPORT(1(class Foo<int>))
00779                 IGTL_TEMPLATE_IMPORT(2(class Bar<int, char>))
00780       Use one level of expansion delay to allow user code to have
00781       a macro determining the number of arguments.
00782 */
00783 #if IGTL_TEMPLATE_EXTERN
00784 # define IGTL_TEMPLATE_IMPORT_DELAY(x) extern template IGTL_TEMPLATE_##x;
00785 # if defined(_MSC_VER)
00786 #  pragma warning (disable: 4231) /* extern template extension */
00787 # endif
00788 #elif IGTL_TEMPLATE_DO_NOT_INSTANTIATE
00789 # define IGTL_TEMPLATE_IMPORT_DELAY(x) \
00790          IGTL_TEMPLATE_IMPORT_IMPL(do_not_instantiate IGTL_TEMPLATE_##x)
00791 # define IGTL_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00792 #endif
00793 #if defined(IGTL_TEMPLATE_IMPORT_DELAY)
00794 # define IGTL_TEMPLATE_IMPORT(x) IGTL_TEMPLATE_IMPORT_DELAY(x)
00795 # define IGTL_TEMPLATE_IMPORT_WORKS 1
00796 #else
00797 # define IGTL_TEMPLATE_IMPORT(x)
00798 # define IGTL_TEMPLATE_IMPORT_WORKS 0
00799 #endif
00800 
00801 /* Define macros to export and import template instantiations.  These
00802    depend on each class providing a macro defining the instantiations
00803    given template arguments in X.  The argument X is of the form
00804    N(a1[,a2...,aN]).  The argument Y is a valid preprocessing token
00805    unique to the template arguments given in X.  Typical usage is
00806 
00807      IGTL_EXPORT_TEMPLATE(igtlfoo_EXPORT, Foo, (int), I)
00808      IGTL_EXPORT_TEMPLATE(igtlfoo_EXPORT, Bar, (int, char), IC)
00809 
00810    The IGTL_TEMPLATE_<name> macro should be defined in igtl<name>.h and
00811    is of the following form:
00812 
00813      #define IGTL_TEMPLATE_<name>(_, EXPORT, x, y) namespace igtl { \
00814        _(<n>(class EXPORT <name>< IGTL_TEMPLATE_<n> x >)) \
00815        namespace Templates { typedef <name>< IGTL_TEMPLATE_<n> x > <name>##y; }\
00816      }
00817 
00818    The argument "_" will be replaced by another macro such as
00819    IGTL_TEMPLATE_EXPORT or IGTL_TEMPLATE_IMPORT, so it should be used as
00820    if calling one of these macros.  The argument "EXPORT" will be
00821    replaced by a dllexport/dllimport macro such as IGTLCommon_EXPORT.
00822    The argument "x" is a paren-enclosed list of template arguments.
00823    The argument "y" is a preprocessing token corresponding to the
00824    given template arguments and should be used to construct typedef
00825    names for the instantiations.
00826 
00827    Note the use of IGTL_TEMPLATE_<n>, where <n> is the number of
00828    template arguments for the class template.  Note also that the
00829    number of template arguments is usually the length of the list
00830    nested within the inner parentheses, so the instantiation is listed
00831    with the form <n>(...).  Example definitions:
00832 
00833      #define IGTL_TEMPLATE_Foo(_, EXPORT, x, y) namespace igtl { \
00834        _(1(class EXPORT Foo< IGTL_TEMPLATE_1 x >)) \
00835        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00836                                            const Foo< IGTL_TEMPLATE_1 x >&))) \
00837        namespace Templates { typedef Foo< IGTL_TEMPLATE_1 x > Foo##y; }\
00838      }
00839 
00840      #define IGTL_TEMPLATE_Bar(_, EXPORT, x, y) namespace igtl { \
00841        _(2(class EXPORT Bar< IGTL_TEMPLATE_2 x >)) \
00842        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00843                                            const Bar< IGTL_TEMPLATE_2 x >&))) \
00844        namespace Templates { typedef Bar< IGTL_TEMPLATE_2 x > Bar##y; }\
00845      }
00846 
00847    Note that in the stream operator for template Bar there is a "1" at
00848    the beginning even though two arguments are taken.  This is because
00849    the expression "IGTL_TEMPLATE_2 x" is contained inside the
00850    parentheses of the function signature which protects the resulting
00851    comma from separating macro arguments.  Therefore the nested
00852    parentheses contain a list of only one macro argument.
00853 
00854    The IGTL_EMPTY macro used in these definitions is a hack to work
00855    around a VS 6.0 preprocessor bug when EXPORT is empty.
00856 */
00857 #define IGTL_EXPORT_TEMPLATE(EXPORT, c, x, y) \
00858         IGTL_TEMPLATE_##c(IGTL_TEMPLATE_EXPORT, EXPORT IGTL_EMPTY, x, y)
00859 #define IGTL_IMPORT_TEMPLATE(EXPORT, c, x, y) \
00860         IGTL_TEMPLATE_##c(IGTL_TEMPLATE_IMPORT, EXPORT IGTL_EMPTY, x, y)
00861 #define IGTL_EMPTY
00862 
00863 /* Define macros to support passing a variable number of arguments
00864    throug other macros.  This is used by IGTL_TEMPLATE_EXPORT,
00865    IGTL_TEMPLATE_IMPORT, and by each template's instantiation
00866    macro.  */
00867 #define IGTL_TEMPLATE_1(x1)                         x1
00868 #define IGTL_TEMPLATE_2(x1,x2)                      x1,x2
00869 #define IGTL_TEMPLATE_3(x1,x2,x3)                   x1,x2,x3
00870 #define IGTL_TEMPLATE_4(x1,x2,x3,x4)                x1,x2,x3,x4
00871 #define IGTL_TEMPLATE_5(x1,x2,x3,x4,x5)             x1,x2,x3,x4,x5
00872 #define IGTL_TEMPLATE_6(x1,x2,x3,x4,x5,x6)          x1,x2,x3,x4,x5,x6
00873 #define IGTL_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7)       x1,x2,x3,x4,x5,x6,x7
00874 #define IGTL_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8)    x1,x2,x3,x4,x5,x6,x7,x8
00875 #define IGTL_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
00876 
00877 /* In order to support both implicit and explicit instantation a .h
00878    file needs to know whether it should include its .txx file
00879    containing the template definitions.  Define a macro to tell
00880    it.  Typical usage in igtlFoo.h:
00881      #if IGTL_TEMPLATE_TXX
00882      # include "igtlFoo.txx"
00883      #endif
00884 */
00885 #if defined(IGTL_MANUAL_INSTANTIATION)
00886 # define IGTL_TEMPLATE_TXX 0
00887 #else
00888 # define IGTL_TEMPLATE_TXX !(IGTL_TEMPLATE_CXX || IGTL_TEMPLATE_TYPE)
00889 #endif
00890 
00891 /* All explicit instantiation source files define IGTL_TEMPLATE_CXX.
00892    Define IGTL_MANUAL_INSTANTIATION to tell .h files that have not been
00893    converted to this explicit instantiation scheme to not include
00894    their .txx files.  Also disable warnings that commonly occur in
00895    these files but are not useful.  */
00896 #if IGTL_TEMPLATE_CXX
00897 # undef IGTL_MANUAL_INSTANTIATION
00898 # define IGTL_MANUAL_INSTANTIATION
00899 # if defined(_MSC_VER)
00900 #  pragma warning (disable: 4275) /* non dll-interface base */
00901 #  pragma warning (disable: 4661) /* no definition available */
00902 # endif
00903 #endif
00904 //=============================================================================
00905 
00906 /* Define macros to export and import template instantiations for each
00907    library in IGTL.  */
00908 #define IGTL_EXPORT_IGTLCommon(c, x, n) \
00909         IGTL_EXPORT_TEMPLATE(IGTLCommon_EXPORT, c, x, n)
00910 #define IGTL_IMPORT_IGTLCommon(c, x, n) \
00911         IGTL_IMPORT_TEMPLATE(IGTLCommon_EXPORT, c, x, n)
00912 
00913 /* Define a macro to decide whether to block instantiation of IGTL
00914    templates.  They should be blocked only if the platform supports
00915    blocking template instantiation and the explicit instantiations are
00916    available.
00917 
00918    - IGTL_TEMPLATE_EXPLICIT =
00919       Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
00920       instantiations of templates explicitly instantiated elsewhere.
00921       Typical usage in igtlFoo.h:
00922         #if IGTL_TEMPLATE_EXPLICIT
00923         # include "igtlFoo+-.h"
00924         #endif
00925 */
00926 #if IGTL_TEMPLATE_IMPORT_WORKS && defined(IGTL_EXPLICIT_INSTANTIATION)
00927 # define IGTL_TEMPLATE_EXPLICIT !IGTL_TEMPLATE_CXX
00928 #else
00929 # define IGTL_TEMPLATE_EXPLICIT 0
00930 #endif
00931 
00932 
00933 //----------------------------------------------------------------------------
00934 // Macro to declare that a function does not return. __attribute__((noreturn))
00935 //    On some compiler, functions that do not return (ex: exit(0)) must
00936 //    have the noreturn attribute. Otherwise, a warning is raised. Use
00937 //    that macro to avoid those warnings. GCC defines the attribute
00938 //    noreturn for versions 2.5 and higher.
00939 #if defined(__GNUC__)
00940 #  if (((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 3))
00941 #    define IGTL_NO_RETURN \
00942        __attribute__ ((noreturn))
00943 #  endif
00944 #else
00945 #  define IGTL_NO_RETURN
00946 #endif
00947 
00948 
00949 #ifdef IGTL_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
00950 //--------------------------------------------------------------------------------
00951 //  Helper macros for Template Meta-Programming techniques of for-loops unrolling
00952 //--------------------------------------------------------------------------------
00953 
00954 //--------------------------------------------------------------------------------
00955 // Macro that generates an unrolled for loop for assigning elements of one array
00956 // to elements of another array The array are assumed to be of same length
00957 // (dimension), and this is also assumed to be the value of NumberOfIterations.
00958 // No verification of size is performed. Casting is perfomed as part of the
00959 // assignment, by using the DestinationElementType as the casting type. 
00960 // Source and destination array types must have defined opearator[] in their API.
00961 #define igtlFoorLoopAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
00962     for(unsigned int i=0;i < NumberOfIterations; ++i) \
00963       { \
00964       DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
00965       }
00966 
00967 //--------------------------------------------------------------------------------
00968 // Macro that generates an unrolled for loop for rounding and assigning
00969 // elements of one array to elements of another array The array are assumed to
00970 // be of same length (dimension), and this is also assumed to be the value of
00971 // NumberOfIterations.  No verification of size is performed. Casting is
00972 // perfomed as part of the assignment, by using the DestinationElementType as
00973 // the casting type. 
00974 // Source and destination array types must have defined opearator[] in their API.
00975 #define igtlFoorLoopRoundingAndAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
00976     for(unsigned int i=0;i < NumberOfIterations; ++i) \
00977       { \
00978       DestinationArray[i] = static_cast< DestinationElementType >( vnl_math_rnd( SourceArray[i] ) ); \
00979       }
00980 
00981 #endif
00982 // end of Template Meta Programming helper macros
00983 
00984 
00985 #endif //end of igtlMacro.h
00986 

Generated at Sat May 9 04:47:23 2009 for OpenIGTLink by doxygen 1.5.9 written by Dimitri van Heesch, © 1997-2000