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: 2009-05-22 15:29:17 -0400 (Fri, 22 May 2009) $
00007   Version:   $Revision: 4248 $
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: 2009-05-22 15:29:17 -0400 (Fri, 22 May 2009) $
00022   Version:   $Revision: 4248 $
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.str(); /*::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.str(); /*::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.str(); /*::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.str(); /*::igtl::OutputWindowDisplayDebugText(igtlmsg.str().c_str());*/ \
00628 }
00629 
00630 
00631 #ifdef IGTL_LEAN_AND_MEAN
00632 #define igtlGenericOutputMacro(x)
00633 #else
00634 #define igtlGenericOutputMacro(x) \
00635   { if (1/*::igtl::Object::GetGlobalWarningDisplay()*/) \
00636     { ::igtl::OStringStream igtlmsg; \
00637       igtlmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
00638              x << "\n\n"; \
00639       std::cerr << igtlmsg.str();/*::igtl::OutputWindowDisplayGenericOutputText(igtlmsg.str().c_str());*/} \
00640 }
00641 #endif
00642 
00643 
00644 
00645 //----------------------------------------------------------------------------
00646 // Macros for simplifying the use of logging
00647 //
00648 #define igtlLogMacro( x, y)  \
00649 {         \
00650   if (this->GetLogger() ) \
00651     {  \
00652     this->GetLogger()->Write(::igtl::LoggerBase::x, y); \
00653     }  \
00654 }
00655 
00656 
00657 #define igtlLogMacroStatic( obj, x, y)  \
00658 {         \
00659   if (obj->GetLogger() ) \
00660     {  \
00661     obj->GetLogger()->Write(::igtl::LoggerBase::x, y); \
00662     }  \
00663 }
00664 
00665 
00666 //----------------------------------------------------------------------------
00667 // Setup legacy code policy.
00668 //
00669 // CMake options IGTL_LEGACY_REMOVE and IGTL_LEGACY_SILENT are converted
00670 // to definitions (or non-defs) in igtlConfigure.h and tested below.
00671 // They may be used to completely remove legacy code or silence the
00672 // warnings.  The default is to warn about their use.
00673 //
00674 // Source files that test the legacy code may define IGTL_LEGACY_TEST
00675 // like this:
00676 //
00677 //  #define IGTL_LEGACY_TEST
00678 //  #include "igtlClassWithDeprecatedMethod.h"
00679 //
00680 // in order to silence the warnings for calling deprecated methods.
00681 // No other source files in IGTL should call the methods since they are
00682 // provided only for compatibility with older user code.
00683 
00684 // Define igtlLegacyMacro to mark legacy methods where they are
00685 // declared in their class.  Example usage:
00686 //
00687 //   // @deprecated Replaced by MyOtherMethod() as of IGTL 2.0.
00688 //   igtlLegacyMacro(void MyMethod());
00689 #if defined(IGTL_LEGACY_REMOVE)
00690 // Remove legacy methods completely.  Put a bogus declaration in
00691 // place to avoid stray semicolons because this is an error for some
00692 // compilers.  Using a class forward declaration allows any number
00693 // of repeats in any context without generating unique names.
00694 # define igtlLegacyMacro(method) class igtlLegacyMethodRemoved /* no ';' */
00695 #elif defined(IGTL_LEGACY_SILENT) || defined(IGTL_LEGACY_TEST) || defined(CSWIG)
00696   // Provide legacy methods with no warnings.
00697 # define igtlLegacyMacro(method) method
00698 #else
00699   // Setup compile-time warnings for uses of deprecated methods if
00700   // possible on this compiler.
00701 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
00702 #  define igtlLegacyMacro(method) method __attribute__((deprecated))
00703 # elif defined(_MSC_VER) && _MSC_VER >= 1300
00704 #  define igtlLegacyMacro(method) __declspec(deprecated) method
00705 # else
00706 #  define igtlLegacyMacro(method) method
00707 # endif
00708 #endif
00709 
00710 // Macros to create runtime deprecation warning messages in function
00711 // bodies.  Example usage:
00712 //
00713 //   void igtlMyClass::MyOldMethod()
00714 //     {
00715 //     igtlLegacyBodyMacro(igtlMyClass::MyOldMethod, 2.0);
00716 //     }
00717 //
00718 //   void igtlMyClass::MyMethod()
00719 //     {
00720 //     igtlLegacyReplaceBodyMacro(igtlMyClass::MyMethod, 2.0,
00721 //                               igtlMyClass::MyOtherMethod);
00722 //     }
00723 #if defined(IGTL_LEGACY_REMOVE) || defined(IGTL_LEGACY_SILENT)
00724 # define igtlLegacyBodyMacro(method, version)
00725 # define igtlLegacyReplaceBodyMacro(method, version, replace)
00726 #else
00727 # define igtlLegacyBodyMacro(method, version) \
00728   igtlWarningMacro(#method " was deprecated for IGTL " #version " and will be removed in a future version.")
00729 # define igtlLegacyReplaceBodyMacro(method, version, replace) \
00730   igtlWarningMacro(#method " was deprecated for IGTL " #version " and will be removed in a future version.  Use " #replace " instead.")
00731 #endif
00732 
00733 #if defined(__INTEL_COMPILER)
00734 # pragma warning (disable: 193) /* #if testing undefined identifier */
00735 #endif
00736 
00737 //=============================================================================
00738 /* Choose a way to prevent template instantiation on this platform.
00739   - IGTL_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
00740                                       prevent instantiation
00741   - IGTL_TEMPLATE_EXTERN = use extern template to prevent instantiation
00742 
00743    Note that VS 6 supports extern template instantiation but it is
00744    hard to block the resulting warning because its stream headers
00745    re-enable it.  Therefore we just disable support for now.
00746 */
00747 #if defined(__sgi) && defined(_COMPILER_VERSION)
00748 # define IGTL_TEMPLATE_DO_NOT_INSTANTIATE 1
00749 #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
00750 # define IGTL_TEMPLATE_EXTERN 1
00751 #elif defined(__GNUC__) && __GNUC__ >= 3
00752 # define IGTL_TEMPLATE_EXTERN 1
00753 #elif defined(_MSC_VER) && _MSC_VER >= 1300
00754 # define IGTL_TEMPLATE_EXTERN 1
00755 #endif
00756 #if !defined(IGTL_TEMPLATE_DO_NOT_INSTANTIATE)
00757 # define IGTL_TEMPLATE_DO_NOT_INSTANTIATE 0
00758 #endif
00759 #if !defined(IGTL_TEMPLATE_EXTERN)
00760 # define IGTL_TEMPLATE_EXTERN 0
00761 #endif
00762 
00763 /* Define a macro to explicitly instantiate a template.
00764   - IGTL_TEMPLATE_EXPORT(X) =
00765       Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
00766       examples: IGTL_TEMPLATE_EXPORT(1(class Foo<int>))
00767                 IGTL_TEMPLATE_EXPORT(2(class Bar<int, char>))
00768       Use one level of expansion delay to allow user code to have
00769       a macro determining the number of arguments. */
00770 #define IGTL_TEMPLATE_EXPORT(x) IGTL_TEMPLATE_EXPORT_DELAY(x)
00771 #define IGTL_TEMPLATE_EXPORT_DELAY(x) template IGTL_TEMPLATE_##x;
00772 
00773 /* Define a macro to prevent template instantiations.
00774   - IGTL_TEMPLATE_IMPORT(X) =
00775       Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
00776       examples: IGTL_TEMPLATE_IMPORT(1(class Foo<int>))
00777                 IGTL_TEMPLATE_IMPORT(2(class Bar<int, char>))
00778       Use one level of expansion delay to allow user code to have
00779       a macro determining the number of arguments.
00780 */
00781 #if IGTL_TEMPLATE_EXTERN
00782 # define IGTL_TEMPLATE_IMPORT_DELAY(x) extern template IGTL_TEMPLATE_##x;
00783 # if defined(_MSC_VER)
00784 #  pragma warning (disable: 4231) /* extern template extension */
00785 # endif
00786 #elif IGTL_TEMPLATE_DO_NOT_INSTANTIATE
00787 # define IGTL_TEMPLATE_IMPORT_DELAY(x) \
00788          IGTL_TEMPLATE_IMPORT_IMPL(do_not_instantiate IGTL_TEMPLATE_##x)
00789 # define IGTL_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
00790 #endif
00791 #if defined(IGTL_TEMPLATE_IMPORT_DELAY)
00792 # define IGTL_TEMPLATE_IMPORT(x) IGTL_TEMPLATE_IMPORT_DELAY(x)
00793 # define IGTL_TEMPLATE_IMPORT_WORKS 1
00794 #else
00795 # define IGTL_TEMPLATE_IMPORT(x)
00796 # define IGTL_TEMPLATE_IMPORT_WORKS 0
00797 #endif
00798 
00799 /* Define macros to export and import template instantiations.  These
00800    depend on each class providing a macro defining the instantiations
00801    given template arguments in X.  The argument X is of the form
00802    N(a1[,a2...,aN]).  The argument Y is a valid preprocessing token
00803    unique to the template arguments given in X.  Typical usage is
00804 
00805      IGTL_EXPORT_TEMPLATE(igtlfoo_EXPORT, Foo, (int), I)
00806      IGTL_EXPORT_TEMPLATE(igtlfoo_EXPORT, Bar, (int, char), IC)
00807 
00808    The IGTL_TEMPLATE_<name> macro should be defined in igtl<name>.h and
00809    is of the following form:
00810 
00811      #define IGTL_TEMPLATE_<name>(_, EXPORT, x, y) namespace igtl { \
00812        _(<n>(class EXPORT <name>< IGTL_TEMPLATE_<n> x >)) \
00813        namespace Templates { typedef <name>< IGTL_TEMPLATE_<n> x > <name>##y; }\
00814      }
00815 
00816    The argument "_" will be replaced by another macro such as
00817    IGTL_TEMPLATE_EXPORT or IGTL_TEMPLATE_IMPORT, so it should be used as
00818    if calling one of these macros.  The argument "EXPORT" will be
00819    replaced by a dllexport/dllimport macro such as IGTLCommon_EXPORT.
00820    The argument "x" is a paren-enclosed list of template arguments.
00821    The argument "y" is a preprocessing token corresponding to the
00822    given template arguments and should be used to construct typedef
00823    names for the instantiations.
00824 
00825    Note the use of IGTL_TEMPLATE_<n>, where <n> is the number of
00826    template arguments for the class template.  Note also that the
00827    number of template arguments is usually the length of the list
00828    nested within the inner parentheses, so the instantiation is listed
00829    with the form <n>(...).  Example definitions:
00830 
00831      #define IGTL_TEMPLATE_Foo(_, EXPORT, x, y) namespace igtl { \
00832        _(1(class EXPORT Foo< IGTL_TEMPLATE_1 x >)) \
00833        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00834                                            const Foo< IGTL_TEMPLATE_1 x >&))) \
00835        namespace Templates { typedef Foo< IGTL_TEMPLATE_1 x > Foo##y; }\
00836      }
00837 
00838      #define IGTL_TEMPLATE_Bar(_, EXPORT, x, y) namespace igtl { \
00839        _(2(class EXPORT Bar< IGTL_TEMPLATE_2 x >)) \
00840        _(1(EXPORT std::ostream& operator<<(std::ostream&, \
00841                                            const Bar< IGTL_TEMPLATE_2 x >&))) \
00842        namespace Templates { typedef Bar< IGTL_TEMPLATE_2 x > Bar##y; }\
00843      }
00844 
00845    Note that in the stream operator for template Bar there is a "1" at
00846    the beginning even though two arguments are taken.  This is because
00847    the expression "IGTL_TEMPLATE_2 x" is contained inside the
00848    parentheses of the function signature which protects the resulting
00849    comma from separating macro arguments.  Therefore the nested
00850    parentheses contain a list of only one macro argument.
00851 
00852    The IGTL_EMPTY macro used in these definitions is a hack to work
00853    around a VS 6.0 preprocessor bug when EXPORT is empty.
00854 */
00855 #define IGTL_EXPORT_TEMPLATE(EXPORT, c, x, y) \
00856         IGTL_TEMPLATE_##c(IGTL_TEMPLATE_EXPORT, EXPORT IGTL_EMPTY, x, y)
00857 #define IGTL_IMPORT_TEMPLATE(EXPORT, c, x, y) \
00858         IGTL_TEMPLATE_##c(IGTL_TEMPLATE_IMPORT, EXPORT IGTL_EMPTY, x, y)
00859 #define IGTL_EMPTY
00860 
00861 /* Define macros to support passing a variable number of arguments
00862    throug other macros.  This is used by IGTL_TEMPLATE_EXPORT,
00863    IGTL_TEMPLATE_IMPORT, and by each template's instantiation
00864    macro.  */
00865 #define IGTL_TEMPLATE_1(x1)                         x1
00866 #define IGTL_TEMPLATE_2(x1,x2)                      x1,x2
00867 #define IGTL_TEMPLATE_3(x1,x2,x3)                   x1,x2,x3
00868 #define IGTL_TEMPLATE_4(x1,x2,x3,x4)                x1,x2,x3,x4
00869 #define IGTL_TEMPLATE_5(x1,x2,x3,x4,x5)             x1,x2,x3,x4,x5
00870 #define IGTL_TEMPLATE_6(x1,x2,x3,x4,x5,x6)          x1,x2,x3,x4,x5,x6
00871 #define IGTL_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7)       x1,x2,x3,x4,x5,x6,x7
00872 #define IGTL_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8)    x1,x2,x3,x4,x5,x6,x7,x8
00873 #define IGTL_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
00874 
00875 /* In order to support both implicit and explicit instantation a .h
00876    file needs to know whether it should include its .txx file
00877    containing the template definitions.  Define a macro to tell
00878    it.  Typical usage in igtlFoo.h:
00879      #if IGTL_TEMPLATE_TXX
00880      # include "igtlFoo.txx"
00881      #endif
00882 */
00883 #if defined(IGTL_MANUAL_INSTANTIATION)
00884 # define IGTL_TEMPLATE_TXX 0
00885 #else
00886 # define IGTL_TEMPLATE_TXX !(IGTL_TEMPLATE_CXX || IGTL_TEMPLATE_TYPE)
00887 #endif
00888 
00889 /* All explicit instantiation source files define IGTL_TEMPLATE_CXX.
00890    Define IGTL_MANUAL_INSTANTIATION to tell .h files that have not been
00891    converted to this explicit instantiation scheme to not include
00892    their .txx files.  Also disable warnings that commonly occur in
00893    these files but are not useful.  */
00894 #if IGTL_TEMPLATE_CXX
00895 # undef IGTL_MANUAL_INSTANTIATION
00896 # define IGTL_MANUAL_INSTANTIATION
00897 # if defined(_MSC_VER)
00898 #  pragma warning (disable: 4275) /* non dll-interface base */
00899 #  pragma warning (disable: 4661) /* no definition available */
00900 # endif
00901 #endif
00902 //=============================================================================
00903 
00904 /* Define macros to export and import template instantiations for each
00905    library in IGTL.  */
00906 #define IGTL_EXPORT_IGTLCommon(c, x, n) \
00907         IGTL_EXPORT_TEMPLATE(IGTLCommon_EXPORT, c, x, n)
00908 #define IGTL_IMPORT_IGTLCommon(c, x, n) \
00909         IGTL_IMPORT_TEMPLATE(IGTLCommon_EXPORT, c, x, n)
00910 
00911 /* Define a macro to decide whether to block instantiation of IGTL
00912    templates.  They should be blocked only if the platform supports
00913    blocking template instantiation and the explicit instantiations are
00914    available.
00915 
00916    - IGTL_TEMPLATE_EXPLICIT =
00917       Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
00918       instantiations of templates explicitly instantiated elsewhere.
00919       Typical usage in igtlFoo.h:
00920         #if IGTL_TEMPLATE_EXPLICIT
00921         # include "igtlFoo+-.h"
00922         #endif
00923 */
00924 #if IGTL_TEMPLATE_IMPORT_WORKS && defined(IGTL_EXPLICIT_INSTANTIATION)
00925 # define IGTL_TEMPLATE_EXPLICIT !IGTL_TEMPLATE_CXX
00926 #else
00927 # define IGTL_TEMPLATE_EXPLICIT 0
00928 #endif
00929 
00930 
00931 //----------------------------------------------------------------------------
00932 // Macro to declare that a function does not return. __attribute__((noreturn))
00933 //    On some compiler, functions that do not return (ex: exit(0)) must
00934 //    have the noreturn attribute. Otherwise, a warning is raised. Use
00935 //    that macro to avoid those warnings. GCC defines the attribute
00936 //    noreturn for versions 2.5 and higher.
00937 #if defined(__GNUC__)
00938 #  if (((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 3))
00939 #    define IGTL_NO_RETURN \
00940        __attribute__ ((noreturn))
00941 #  endif
00942 #else
00943 #  define IGTL_NO_RETURN
00944 #endif
00945 
00946 
00947 #ifdef IGTL_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
00948 //--------------------------------------------------------------------------------
00949 //  Helper macros for Template Meta-Programming techniques of for-loops unrolling
00950 //--------------------------------------------------------------------------------
00951 
00952 //--------------------------------------------------------------------------------
00953 // Macro that generates an unrolled for loop for assigning elements of one array
00954 // to elements of another array The array are assumed to be of same length
00955 // (dimension), and this is also assumed to be the value of NumberOfIterations.
00956 // No verification of size is performed. Casting is perfomed as part of the
00957 // assignment, by using the DestinationElementType as the casting type. 
00958 // Source and destination array types must have defined opearator[] in their API.
00959 #define igtlFoorLoopAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
00960     for(unsigned int i=0;i < NumberOfIterations; ++i) \
00961       { \
00962       DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
00963       }
00964 
00965 //--------------------------------------------------------------------------------
00966 // Macro that generates an unrolled for loop for rounding and assigning
00967 // elements of one array to elements of another array The array are assumed to
00968 // be of same length (dimension), and this is also assumed to be the value of
00969 // NumberOfIterations.  No verification of size is performed. Casting is
00970 // perfomed as part of the assignment, by using the DestinationElementType as
00971 // the casting type. 
00972 // Source and destination array types must have defined opearator[] in their API.
00973 #define igtlFoorLoopRoundingAndAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
00974     for(unsigned int i=0;i < NumberOfIterations; ++i) \
00975       { \
00976       DestinationArray[i] = static_cast< DestinationElementType >( vnl_math_rnd( SourceArray[i] ) ); \
00977       }
00978 
00979 #endif
00980 // end of Template Meta Programming helper macros
00981 
00982 
00983 #endif //end of igtlMacro.h
00984 

Generated at Sat Apr 17 12:12:15 2010 for OpenIGTLink by doxygen 1.6.3 written by Dimitri van Heesch, © 1997-2000