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.
1 /*=========================================================================
2 
3  Program: The OpenIGTLink Library
4  Language: C++
5  Web page: http://openigtlink.org/
6 
7  Copyright (c) Insight Software Consortium. All rights reserved.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notices for more information.
12 
13 =========================================================================*/
14 /*=========================================================================
15 
16  Program: Insight Segmentation & Registration Toolkit
17  Module: $RCSfile: itkMacro.h,v $
18  Language: C++
19  Date: $Date: 2009-05-22 15:29:17 -0400 (Fri, 22 May 2009) $
20  Version: $Revision: 4248 $
21 
22  Copyright (c) Insight Software Consortium. All rights reserved.
23  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
24 
25  Portions of this code are covered under the VTK copyright.
26  See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
27 
28  This software is distributed WITHOUT ANY WARRANTY; without even
29  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
30  PURPOSE. See the above copyright notices for more information.
31 
32 =========================================================================*/
43 #ifndef __igtlMacro_h
44 #define __igtlMacro_h
45 
46 #include "igtlWin32Header.h"
47 //#include "igtlConfigure.h"
48 
49 #include <string>
50 
51 // Determine type of string stream to use.
52 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
53 # include <sstream>
54 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
55 # include <strstream>
56 # define IGTL_NO_ANSI_STRING_STREAM
57 #else
58 # include <strstream.h>
59 # define IGTL_NO_ANSI_STRING_STREAM
60 #endif
61 
65 namespace igtl
66 {
67 } // end namespace igtl - this is here for documentation purposes
68 
71 #define igtlNotUsed(x)
72 
87 #if defined(_MSC_VER) && (_MSC_VER <= 1300)
88 # define IGTL_NO_INCLASS_MEMBER_INITIALIZATION
89 #endif
90 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x540)
91 # define IGTL_NO_INCLASS_MEMBER_INITIALIZATION
92 #endif
93 #if defined(__SVR4) && !defined(__SUNPRO_CC)
94 # define IGTL_NO_INCLASS_MEMBER_INITIALIZATION
95 #endif
96 
97 // A class template like this will not instantiate on GCC 2.95:
98 // template<class T> struct A
99 // {
100 // static const int N = 1;
101 // enum { S = sizeof(A::N) };
102 // };
103 // We need to use enum for static constants instead.
104 #if defined(__GNUC__)
105 # define IGTL_NO_SIZEOF_CONSTANT_LOOKUP
106 #endif
107 
108 #if defined(_MSC_VER) && (_MSC_VER <= 1300)
109 #define IGTL_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
110 #endif
111 
112 #if defined(IGTL_NO_INCLASS_MEMBER_INITIALIZATION) || \
113  defined(IGTL_NO_SIZEOF_CONSTANT_LOOKUP)
114 # define igtlStaticConstMacro(name,type,value) enum { name = value }
115 #else
116 # define igtlStaticConstMacro(name,type,value) static const type name = value
117 #endif
118 
119 #ifdef IGTL_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
120 # define igtlGetStaticConstMacro(name) name
121 #else
122 # define igtlGetStaticConstMacro(name) (Self::name)
123 #endif
124 
126 #define igtlSetInputMacro(name, type, number) \
127  virtual void Set##name##Input(const type *_arg) \
128  { \
129  igtlDebugMacro("setting input " #name " to " << _arg); \
130  if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \
131  { \
132  this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \
133  } \
134  } \
135  virtual void SetInput##number(const type *_arg) \
136  { \
137  igtlDebugMacro("setting input " #number " to " << _arg); \
138  if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \
139  { \
140  this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \
141  } \
142  }
143 
144 
146 #define igtlSuperclassTraitMacro(traitnameType) \
147  typedef typename Superclass::traitnameType traitnameType;
148 
150 #define igtlGetInputMacro(name, type, number) \
151  virtual const type * Get##name##Input() const \
152  { \
153  igtlDebugMacro("returning input " << #name " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
154  return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
155  } \
156  virtual const type * GetInput##number() const \
157  { \
158  igtlDebugMacro("returning input " << #number " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
159  return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
160  }
161 
162 
165 #define igtlSetDecoratedInputMacro(name, type, number) \
166  igtlSetInputMacro(name, SimpleDataObjectDecorator<type>, number); \
167  igtlGetInputMacro(name, SimpleDataObjectDecorator<type>, number); \
168  virtual void Set##name(const type &_arg) \
169  { \
170  typedef SimpleDataObjectDecorator< type > DecoratorType; \
171  igtlDebugMacro("setting input " #name " to " << _arg); \
172  const DecoratorType * oldInput = \
173  static_cast< const DecoratorType * >( \
174  this->ProcessObject::GetInput(number) ); \
175  if( oldInput && oldInput->Get() == _arg ) \
176  { \
177  return; \
178  } \
179  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
180  newInput->Set( _arg ); \
181  this->Set##name##Input( newInput ); \
182  }
183 
184 
188 #define igtlSetDecoratedObjectInputMacro(name, type, number) \
189  igtlSetInputMacro(name, DataObjectDecorator<type>, number); \
190  igtlGetInputMacro(name, DataObjectDecorator<type>, number); \
191  virtual void Set##name(const type *_arg) \
192  { \
193  typedef DataObjectDecorator< type > DecoratorType; \
194  igtlDebugMacro("setting input " #name " to " << _arg); \
195  const DecoratorType * oldInput = \
196  static_cast< const DecoratorType * >( \
197  this->ProcessObject::GetInput(number) ); \
198  if( oldInput && oldInput->Get() == _arg ) \
199  { \
200  return; \
201  } \
202  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
203  newInput->Set( _arg ); \
204  this->Set##name##Input( newInput ); \
205  }
206 
207 
208 
210 #define igtlSetMacro(name,type) \
211  virtual void Set##name (const type _arg) \
212  { \
213  igtlDebugMacro("setting " #name " to " << _arg); \
214  if (this->m_##name != _arg) \
215  { \
216  this->m_##name = _arg; \
217  } \
218  }
219 
220 
222 #define igtlGetMacro(name,type) \
223  virtual type Get##name () \
224  { \
225  igtlDebugMacro("returning " << #name " of " << this->m_##name ); \
226  return this->m_##name; \
227  }
228 
229 
233 #define igtlGetConstMacro(name,type) \
234  virtual type Get##name () const \
235  { \
236  igtlDebugMacro("returning " << #name " of " << this->m_##name ); \
237  return this->m_##name; \
238  }
239 
240 
245 #define igtlGetConstReferenceMacro(name,type) \
246  virtual const type & Get##name () const \
247  { \
248  igtlDebugMacro("returning " << #name " of " << this->m_##name ); \
249  return this->m_##name; \
250  }
251 
252 
256 #define igtlSetEnumMacro(name,type) \
257  virtual void Set##name (const type _arg) \
258  { \
259  igtlDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
260  if (this->m_##name != _arg) \
261  { \
262  this->m_##name = _arg; \
263  } \
264  }
265 
266 
270 #define igtlGetEnumMacro(name,type) \
271  virtual type Get##name () const \
272  { \
273  igtlDebugMacro("returning " << #name " of " << static_cast<long>(this->m_##name) ); \
274  return this->m_##name; \
275  }
276 
277 
281 #define igtlSetStringMacro(name) \
282  virtual void Set##name (const char* _arg) \
283  { \
284  if ( _arg && (_arg == this->m_##name) ) { return;} \
285  if (_arg) \
286  { \
287  this->m_##name = _arg;\
288  } \
289  else \
290  { \
291  this->m_##name = ""; \
292  } \
293  } \
294  virtual void Set##name (const std::string & _arg) \
295  { \
296  this->Set##name( _arg.c_str() ); \
297  } \
298 
299 
300 
304 #define igtlGetStringMacro(name) \
305  virtual const char* Get##name () const \
306  { \
307  return this->m_##name.c_str(); \
308  }
309 
313 #define igtlSetClampMacro(name,type,min,max) \
314  virtual void Set##name (type _arg) \
315  { \
316  igtlDebugMacro("setting " << #name " to " << _arg ); \
317  if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
318  { \
319  this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
320  } \
321  }
322 
323 
328 #define igtlSetObjectMacro(name,type) \
329  virtual void Set##name (type* _arg) \
330  { \
331  igtlDebugMacro("setting " << #name " to " << _arg ); \
332  if (this->m_##name != _arg) \
333  { \
334  this->m_##name = _arg; \
335  } \
336  }
337 
338 
341 #define igtlGetObjectMacro(name,type) \
342  virtual type * Get##name () \
343  { \
344  igtlDebugMacro("returning " #name " address " << this->m_##name ); \
345  return this->m_##name.GetPointer(); \
346  }
347 
348 
353 #define igtlSetConstObjectMacro(name,type) \
354  virtual void Set##name (const type* _arg) \
355  { \
356  igtlDebugMacro("setting " << #name " to " << _arg ); \
357  if (this->m_##name != _arg) \
358  { \
359  this->m_##name = _arg; \
360  } \
361  }
362 
363 
364 
367 #define igtlGetConstObjectMacro(name,type) \
368  virtual const type * Get##name () const \
369  { \
370  igtlDebugMacro("returning " #name " address " << this->m_##name ); \
371  return this->m_##name.GetPointer(); \
372  }
373 
374 
377 #define igtlGetConstReferenceObjectMacro(name,type) \
378  virtual const typename type::Pointer & Get##name () const \
379  { \
380  igtlDebugMacro("returning " #name " address " << this->m_##name ); \
381  return this->m_##name; \
382  }
383 
384 
387 #define igtlBooleanMacro(name) \
388  virtual void name##On () { this->Set##name(true);} \
389  virtual void name##Off () { this->Set##name(false);}
390 
391 
395 #define igtlSetVectorMacro(name,type,count) \
396  virtual void Set##name(type data[]) \
397  { \
398  unsigned int i; \
399  for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
400  if ( i < count ) \
401  { \
402  for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
403  } \
404  }
405 
406 
409 #define igtlGetVectorMacro(name,type,count) \
410  virtual type *Get##name () const \
411  { \
412  return this->m_##name; \
413  }
414 
431 #define igtlNewMacro(x) \
432 static Pointer New(void) \
433 { \
434  Pointer smartPtr = ::igtl::ObjectFactory<x>::Create(); \
435  if(smartPtr.GetPointer() == NULL) \
436  { \
437  smartPtr = new x; \
438  } \
439  smartPtr->UnRegister(); \
440  return smartPtr; \
441 } \
442 virtual ::igtl::LightObject::Pointer CreateAnother(void) const \
443 { \
444  ::igtl::LightObject::Pointer smartPtr; \
445  smartPtr = x::New().GetPointer(); \
446  return smartPtr; \
447 }
448 
449 
450 
467 #define igtlFactorylessNewMacro(x) \
468 static Pointer New(void) \
469 { \
470  Pointer smartPtr; \
471  x *rawPtr = new x; \
472  smartPtr = rawPtr; \
473  rawPtr->UnRegister(); \
474  return smartPtr; \
475 } \
476  virtual ::igtl::LightObject::Pointer CreateAnother(void) const \
477 { \
478  ::igtl::LightObject::Pointer smartPtr; \
479  smartPtr = x::New().GetPointer(); \
480  return smartPtr; \
481 }
482 
483 
486 #define igtlTypeMacro(thisClass,superclass) \
487  virtual const char *GetNameOfClass() const \
488  {return #thisClass;}
489 
490 
491 //namespace igtl
492 //{
499 //extern IGTLCommon_EXPORT void OutputWindowDisplayText(const char*);
500 //extern IGTLCommon_EXPORT void OutputWindowDisplayErrorText(const char*);
501 //extern IGTLCommon_EXPORT void OutputWindowDisplayWarningText(const char*);
502 //extern IGTLCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char*);
503 //extern IGTLCommon_EXPORT void OutputWindowDisplayDebugText(const char*);
504 //} // end namespace igtl
506 
510 #if defined(IGTL_LEAN_AND_MEAN) || defined(__BORLANDC__)
511 #define igtlDebugMacro(x)
512 #else
513 #define igtlDebugMacro(x) \
514  { if (this->GetDebug() /*&& ::igtl::Object::GetGlobalWarningDisplay()*/) \
515  { ::igtl::OStringStream igtlmsg; \
516  igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
517  << this->GetNameOfClass() << " (" << this << "): " x \
518  << "\n\n"; \
519  std::cerr << igtlmsg.str(); /*::igtl::OutputWindowDisplayDebugText(igtlmsg.str().c_str());*/} \
520 }
521 #endif
522 
523 
524 
528 #ifdef IGTL_LEAN_AND_MEAN
529 #define igtlWarningMacro(x)
530 #else
531 #define igtlWarningMacro(x) \
532  { if ( 1/*::igtl::Object::GetGlobalWarningDisplay()*/) \
533  { ::igtl::OStringStream igtlmsg; \
534  igtlmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
535  << this->GetNameOfClass() << " (" << this << "): " x \
536  << "\n\n"; \
537  std::cerr << igtlmsg.str(); /*::igtl::OutputWindowDisplayWarningText(igtlmsg.str().c_str());*/} \
538 }
539 #endif
540 
541 
542 namespace igtl
543 {
544 
550 #if !defined(IGTL_NO_ANSI_STRING_STREAM)
551 class OStringStream: public std::ostringstream
552 {
553 public:
555 private:
557  void operator=(const OStringStream&);
558 };
559 #else
560 namespace OStringStreamDetail
561 {
562  class Cleanup
563  {
564  public:
565  Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
566  ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
567  static void IgnoreUnusedVariable(const Cleanup&) {}
568  protected:
569  std::ostrstream& m_OStrStream;
570  };
571 }//namespace OStringStreamDetail
573 
574 class OStringStream: public std::ostrstream
575 {
576 public:
577  typedef std::ostrstream Superclass;
578  OStringStream() {}
579  std::string str()
580  {
581  OStringStreamDetail::Cleanup cleanup(*this);
582  OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
583  int pcount = this->pcount();
584  const char* ptr = this->Superclass::str();
585  return std::string(ptr?ptr:"", pcount);
586  }
587 private:
589  void operator=(const OStringStream&);
590 };
591 #endif
592 
593 }//namespace igtl
594 
595 #if defined(IGTL_CPP_FUNCTION)
596  #if defined(__BORLANDC__)
597  #define IGTL_LOCATION __FUNC__
598  #elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(CABLE_CONFIGURATION) && !defined(CSWIG)
599  #define IGTL_LOCATION __FUNCSIG__
600  #elif defined(__GNUC__)
601  #define IGTL_LOCATION __PRETTY_FUNCTION__
602  #else
603  #define IGTL_LOCATION __FUNCTION__
604  #endif
605 #else
606  #define IGTL_LOCATION "unknown"
607 #endif
608 
609 #define igtlExceptionMacro(x) \
610  { \
611  ::igtl::OStringStream igtlmsg; \
612  igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
613  << this->GetNameOfClass() << " (" << this << "): " x \
614  << "\n\n"; \
615  std::cerr << igtlmsg.str(); /*::igtl::OutputWindowDisplayDebugText(igtlmsg.str().c_str());*/ \
616 }
617 
618 #define igtlErrorMacro(x) \
619  { \
620  ::igtl::OStringStream igtlmsg; \
621  igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
622  << this->GetNameOfClass() << " (" << this << "): " x \
623  << "\n\n"; \
624  std::cerr << igtlmsg.str(); /*::igtl::OutputWindowDisplayDebugText(igtlmsg.str().c_str());*/ \
625 }
626 
627 
628 #ifdef IGTL_LEAN_AND_MEAN
629 #define igtlGenericOutputMacro(x)
630 #else
631 #define igtlGenericOutputMacro(x) \
632  { if (1/*::igtl::Object::GetGlobalWarningDisplay()*/) \
633  { ::igtl::OStringStream igtlmsg; \
634  igtlmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
635  x << "\n\n"; \
636  std::cerr << igtlmsg.str();/*::igtl::OutputWindowDisplayGenericOutputText(igtlmsg.str().c_str());*/} \
637 }
638 #endif
639 
640 
641 
642 //----------------------------------------------------------------------------
643 // Macros for simplifying the use of logging
644 //
645 #define igtlLogMacro( x, y) \
646 { \
647  if (this->GetLogger() ) \
648  { \
649  this->GetLogger()->Write(::igtl::LoggerBase::x, y); \
650  } \
651 }
652 
653 
654 #define igtlLogMacroStatic( obj, x, y) \
655 { \
656  if (obj->GetLogger() ) \
657  { \
658  obj->GetLogger()->Write(::igtl::LoggerBase::x, y); \
659  } \
660 }
661 
662 
663 //----------------------------------------------------------------------------
664 // Setup legacy code policy.
665 //
666 // CMake options IGTL_LEGACY_REMOVE and IGTL_LEGACY_SILENT are converted
667 // to definitions (or non-defs) in igtlConfigure.h and tested below.
668 // They may be used to completely remove legacy code or silence the
669 // warnings. The default is to warn about their use.
670 //
671 // Source files that test the legacy code may define IGTL_LEGACY_TEST
672 // like this:
673 //
674 // #define IGTL_LEGACY_TEST
675 // #include "igtlClassWithDeprecatedMethod.h"
676 //
677 // in order to silence the warnings for calling deprecated methods.
678 // No other source files in IGTL should call the methods since they are
679 // provided only for compatibility with older user code.
680 
681 // Define igtlLegacyMacro to mark legacy methods where they are
682 // declared in their class. Example usage:
683 //
684 // // @deprecated Replaced by MyOtherMethod() as of IGTL 2.0.
685 // igtlLegacyMacro(void MyMethod());
686 #if defined(IGTL_LEGACY_REMOVE)
687 // Remove legacy methods completely. Put a bogus declaration in
688 // place to avoid stray semicolons because this is an error for some
689 // compilers. Using a class forward declaration allows any number
690 // of repeats in any context without generating unique names.
691 # define igtlLegacyMacro(method) class igtlLegacyMethodRemoved /* no ';' */
692 #elif defined(IGTL_LEGACY_SILENT) || defined(IGTL_LEGACY_TEST) || defined(CSWIG)
693  // Provide legacy methods with no warnings.
694 # define igtlLegacyMacro(method) method
695 #else
696  // Setup compile-time warnings for uses of deprecated methods if
697  // possible on this compiler.
698 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
699 # define igtlLegacyMacro(method) method __attribute__((deprecated))
700 # elif defined(_MSC_VER) && _MSC_VER >= 1300
701 # define igtlLegacyMacro(method) __declspec(deprecated) method
702 # else
703 # define igtlLegacyMacro(method) method
704 # endif
705 #endif
706 
707 // Macros to create runtime deprecation warning messages in function
708 // bodies. Example usage:
709 //
710 // void igtlMyClass::MyOldMethod()
711 // {
712 // igtlLegacyBodyMacro(igtlMyClass::MyOldMethod, 2.0);
713 // }
714 //
715 // void igtlMyClass::MyMethod()
716 // {
717 // igtlLegacyReplaceBodyMacro(igtlMyClass::MyMethod, 2.0,
718 // igtlMyClass::MyOtherMethod);
719 // }
720 #if defined(IGTL_LEGACY_REMOVE) || defined(IGTL_LEGACY_SILENT)
721 # define igtlLegacyBodyMacro(method, version)
722 # define igtlLegacyReplaceBodyMacro(method, version, replace)
723 #else
724 # define igtlLegacyBodyMacro(method, version) \
725  igtlWarningMacro(#method " was deprecated for IGTL " #version " and will be removed in a future version.")
726 # define igtlLegacyReplaceBodyMacro(method, version, replace) \
727  igtlWarningMacro(#method " was deprecated for IGTL " #version " and will be removed in a future version. Use " #replace " instead.")
728 #endif
729 
730 #if defined(__INTEL_COMPILER)
731 # pragma warning (disable: 193) /* #if testing undefined identifier */
732 #endif
733 
734 //=============================================================================
735 /* Choose a way to prevent template instantiation on this platform.
736  - IGTL_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
737  prevent instantiation
738  - IGTL_TEMPLATE_EXTERN = use extern template to prevent instantiation
739 
740  Note that VS 6 supports extern template instantiation but it is
741  hard to block the resulting warning because its stream headers
742  re-enable it. Therefore we just disable support for now.
743 */
744 #if defined(__sgi) && defined(_COMPILER_VERSION)
745 # define IGTL_TEMPLATE_DO_NOT_INSTANTIATE 1
746 #elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
747 # define IGTL_TEMPLATE_EXTERN 1
748 #elif defined(__GNUC__) && __GNUC__ >= 3
749 # define IGTL_TEMPLATE_EXTERN 1
750 #elif defined(_MSC_VER) && _MSC_VER >= 1300
751 # define IGTL_TEMPLATE_EXTERN 1
752 #endif
753 #if !defined(IGTL_TEMPLATE_DO_NOT_INSTANTIATE)
754 # define IGTL_TEMPLATE_DO_NOT_INSTANTIATE 0
755 #endif
756 #if !defined(IGTL_TEMPLATE_EXTERN)
757 # define IGTL_TEMPLATE_EXTERN 0
758 #endif
759 
760 /* Define a macro to explicitly instantiate a template.
761  - IGTL_TEMPLATE_EXPORT(X) =
762  Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
763  examples: IGTL_TEMPLATE_EXPORT(1(class Foo<int>))
764  IGTL_TEMPLATE_EXPORT(2(class Bar<int, char>))
765  Use one level of expansion delay to allow user code to have
766  a macro determining the number of arguments. */
767 #define IGTL_TEMPLATE_EXPORT(x) IGTL_TEMPLATE_EXPORT_DELAY(x)
768 #define IGTL_TEMPLATE_EXPORT_DELAY(x) template IGTL_TEMPLATE_##x;
769 
770 /* Define a macro to prevent template instantiations.
771  - IGTL_TEMPLATE_IMPORT(X) =
772  Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
773  examples: IGTL_TEMPLATE_IMPORT(1(class Foo<int>))
774  IGTL_TEMPLATE_IMPORT(2(class Bar<int, char>))
775  Use one level of expansion delay to allow user code to have
776  a macro determining the number of arguments.
777 */
778 #if IGTL_TEMPLATE_EXTERN
779 # define IGTL_TEMPLATE_IMPORT_DELAY(x) extern template IGTL_TEMPLATE_##x;
780 # if defined(_MSC_VER)
781 # pragma warning (disable: 4231) /* extern template extension */
782 # endif
783 #elif IGTL_TEMPLATE_DO_NOT_INSTANTIATE
784 # define IGTL_TEMPLATE_IMPORT_DELAY(x) \
785  IGTL_TEMPLATE_IMPORT_IMPL(do_not_instantiate IGTL_TEMPLATE_##x)
786 # define IGTL_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
787 #endif
788 #if defined(IGTL_TEMPLATE_IMPORT_DELAY)
789 # define IGTL_TEMPLATE_IMPORT(x) IGTL_TEMPLATE_IMPORT_DELAY(x)
790 # define IGTL_TEMPLATE_IMPORT_WORKS 1
791 #else
792 # define IGTL_TEMPLATE_IMPORT(x)
793 # define IGTL_TEMPLATE_IMPORT_WORKS 0
794 #endif
795 
796 /* Define macros to export and import template instantiations. These
797  depend on each class providing a macro defining the instantiations
798  given template arguments in X. The argument X is of the form
799  N(a1[,a2...,aN]). The argument Y is a valid preprocessing token
800  unique to the template arguments given in X. Typical usage is
801 
802  IGTL_EXPORT_TEMPLATE(igtlfoo_EXPORT, Foo, (int), I)
803  IGTL_EXPORT_TEMPLATE(igtlfoo_EXPORT, Bar, (int, char), IC)
804 
805  The IGTL_TEMPLATE_<name> macro should be defined in igtl<name>.h and
806  is of the following form:
807 
808  #define IGTL_TEMPLATE_<name>(_, EXPORT, x, y) namespace igtl { \
809  _(<n>(class EXPORT <name>< IGTL_TEMPLATE_<n> x >)) \
810  namespace Templates { typedef <name>< IGTL_TEMPLATE_<n> x > <name>##y; }\
811  }
812 
813  The argument "_" will be replaced by another macro such as
814  IGTL_TEMPLATE_EXPORT or IGTL_TEMPLATE_IMPORT, so it should be used as
815  if calling one of these macros. The argument "EXPORT" will be
816  replaced by a dllexport/dllimport macro such as IGTLCommon_EXPORT.
817  The argument "x" is a paren-enclosed list of template arguments.
818  The argument "y" is a preprocessing token corresponding to the
819  given template arguments and should be used to construct typedef
820  names for the instantiations.
821 
822  Note the use of IGTL_TEMPLATE_<n>, where <n> is the number of
823  template arguments for the class template. Note also that the
824  number of template arguments is usually the length of the list
825  nested within the inner parentheses, so the instantiation is listed
826  with the form <n>(...). Example definitions:
827 
828  #define IGTL_TEMPLATE_Foo(_, EXPORT, x, y) namespace igtl { \
829  _(1(class EXPORT Foo< IGTL_TEMPLATE_1 x >)) \
830  _(1(EXPORT std::ostream& operator<<(std::ostream&, \
831  const Foo< IGTL_TEMPLATE_1 x >&))) \
832  namespace Templates { typedef Foo< IGTL_TEMPLATE_1 x > Foo##y; }\
833  }
834 
835  #define IGTL_TEMPLATE_Bar(_, EXPORT, x, y) namespace igtl { \
836  _(2(class EXPORT Bar< IGTL_TEMPLATE_2 x >)) \
837  _(1(EXPORT std::ostream& operator<<(std::ostream&, \
838  const Bar< IGTL_TEMPLATE_2 x >&))) \
839  namespace Templates { typedef Bar< IGTL_TEMPLATE_2 x > Bar##y; }\
840  }
841 
842  Note that in the stream operator for template Bar there is a "1" at
843  the beginning even though two arguments are taken. This is because
844  the expression "IGTL_TEMPLATE_2 x" is contained inside the
845  parentheses of the function signature which protects the resulting
846  comma from separating macro arguments. Therefore the nested
847  parentheses contain a list of only one macro argument.
848 
849  The IGTL_EMPTY macro used in these definitions is a hack to work
850  around a VS 6.0 preprocessor bug when EXPORT is empty.
851 */
852 #define IGTL_EXPORT_TEMPLATE(EXPORT, c, x, y) \
853  IGTL_TEMPLATE_##c(IGTL_TEMPLATE_EXPORT, EXPORT IGTL_EMPTY, x, y)
854 #define IGTL_IMPORT_TEMPLATE(EXPORT, c, x, y) \
855  IGTL_TEMPLATE_##c(IGTL_TEMPLATE_IMPORT, EXPORT IGTL_EMPTY, x, y)
856 #define IGTL_EMPTY
857 
858 /* Define macros to support passing a variable number of arguments
859  throug other macros. This is used by IGTL_TEMPLATE_EXPORT,
860  IGTL_TEMPLATE_IMPORT, and by each template's instantiation
861  macro. */
862 #define IGTL_TEMPLATE_1(x1) x1
863 #define IGTL_TEMPLATE_2(x1,x2) x1,x2
864 #define IGTL_TEMPLATE_3(x1,x2,x3) x1,x2,x3
865 #define IGTL_TEMPLATE_4(x1,x2,x3,x4) x1,x2,x3,x4
866 #define IGTL_TEMPLATE_5(x1,x2,x3,x4,x5) x1,x2,x3,x4,x5
867 #define IGTL_TEMPLATE_6(x1,x2,x3,x4,x5,x6) x1,x2,x3,x4,x5,x6
868 #define IGTL_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7) x1,x2,x3,x4,x5,x6,x7
869 #define IGTL_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8) x1,x2,x3,x4,x5,x6,x7,x8
870 #define IGTL_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
871 
872 /* In order to support both implicit and explicit instantation a .h
873  file needs to know whether it should include its .txx file
874  containing the template definitions. Define a macro to tell
875  it. Typical usage in igtlFoo.h:
876  #if IGTL_TEMPLATE_TXX
877  # include "igtlFoo.txx"
878  #endif
879 */
880 #if defined(IGTL_MANUAL_INSTANTIATION)
881 # define IGTL_TEMPLATE_TXX 0
882 #else
883 # define IGTL_TEMPLATE_TXX !(IGTL_TEMPLATE_CXX || IGTL_TEMPLATE_TYPE)
884 #endif
885 
886 /* All explicit instantiation source files define IGTL_TEMPLATE_CXX.
887  Define IGTL_MANUAL_INSTANTIATION to tell .h files that have not been
888  converted to this explicit instantiation scheme to not include
889  their .txx files. Also disable warnings that commonly occur in
890  these files but are not useful. */
891 #if IGTL_TEMPLATE_CXX
892 # undef IGTL_MANUAL_INSTANTIATION
893 # define IGTL_MANUAL_INSTANTIATION
894 # if defined(_MSC_VER)
895 # pragma warning (disable: 4275) /* non dll-interface base */
896 # pragma warning (disable: 4661) /* no definition available */
897 # endif
898 #endif
899 //=============================================================================
900 
901 /* Define macros to export and import template instantiations for each
902  library in IGTL. */
903 #define IGTL_EXPORT_IGTLCommon(c, x, n) \
904  IGTL_EXPORT_TEMPLATE(IGTLCommon_EXPORT, c, x, n)
905 #define IGTL_IMPORT_IGTLCommon(c, x, n) \
906  IGTL_IMPORT_TEMPLATE(IGTLCommon_EXPORT, c, x, n)
907 
908 /* Define a macro to decide whether to block instantiation of IGTL
909  templates. They should be blocked only if the platform supports
910  blocking template instantiation and the explicit instantiations are
911  available.
912 
913  - IGTL_TEMPLATE_EXPLICIT =
914  Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
915  instantiations of templates explicitly instantiated elsewhere.
916  Typical usage in igtlFoo.h:
917  #if IGTL_TEMPLATE_EXPLICIT
918  # include "igtlFoo+-.h"
919  #endif
920 */
921 #if IGTL_TEMPLATE_IMPORT_WORKS && defined(IGTL_EXPLICIT_INSTANTIATION)
922 # define IGTL_TEMPLATE_EXPLICIT !IGTL_TEMPLATE_CXX
923 #else
924 # define IGTL_TEMPLATE_EXPLICIT 0
925 #endif
926 
927 
928 //----------------------------------------------------------------------------
929 // Macro to declare that a function does not return. __attribute__((noreturn))
930 // On some compiler, functions that do not return (ex: exit(0)) must
931 // have the noreturn attribute. Otherwise, a warning is raised. Use
932 // that macro to avoid those warnings. GCC defines the attribute
933 // noreturn for versions 2.5 and higher.
934 #if defined(__GNUC__)
935 # if (((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 3))
936 # define IGTL_NO_RETURN \
937  __attribute__ ((noreturn))
938 # endif
939 #else
940 # define IGTL_NO_RETURN
941 #endif
942 
943 
944 #ifdef IGTL_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
945 //--------------------------------------------------------------------------------
946 // Helper macros for Template Meta-Programming techniques of for-loops unrolling
947 //--------------------------------------------------------------------------------
948 
949 //--------------------------------------------------------------------------------
950 // Macro that generates an unrolled for loop for assigning elements of one array
951 // to elements of another array The array are assumed to be of same length
952 // (dimension), and this is also assumed to be the value of NumberOfIterations.
953 // No verification of size is performed. Casting is perfomed as part of the
954 // assignment, by using the DestinationElementType as the casting type.
955 // Source and destination array types must have defined opearator[] in their API.
956 #define igtlFoorLoopAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
957  for(unsigned int i=0;i < NumberOfIterations; ++i) \
958  { \
959  DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
960  }
961 
962 //--------------------------------------------------------------------------------
963 // Macro that generates an unrolled for loop for rounding and assigning
964 // elements of one array to elements of another array The array are assumed to
965 // be of same length (dimension), and this is also assumed to be the value of
966 // NumberOfIterations. No verification of size is performed. Casting is
967 // perfomed as part of the assignment, by using the DestinationElementType as
968 // the casting type.
969 // Source and destination array types must have defined opearator[] in their API.
970 #define igtlFoorLoopRoundingAndAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
971  for(unsigned int i=0;i < NumberOfIterations; ++i) \
972  { \
973  DestinationArray[i] = static_cast< DestinationElementType >( vnl_math_rnd( SourceArray[i] ) ); \
974  }
975 
976 #endif
977 // end of Template Meta Programming helper macros
978 
979 
980 #endif //end of igtlMacro.h
The "igtl" namespace contains all OpenIGTLink classes. There are several nested namespaces within the...

Generated at Mon Dec 23 2019 00:49:23 for OpenIGTLink by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2012