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

Generated at Thu Mar 20 2014 16:32:06 for OpenIGTLink by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2000