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
65namespace 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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
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 }
384
387#define igtlBooleanMacro(name) \
388 virtual void name##On () { this->Set##name(true);} \
389 virtual void name##Off () { this->Set##name(false);}
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 }
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) \
432static 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} \
442virtual ::igtl::LightObject::Pointer CreateAnother(void) const \
443{ \
444 return x::New().GetPointer(); \
445} \
446
447
448
465#define igtlFactorylessNewMacro(x) \
466static Pointer New(void) \
467{ \
468 Pointer smartPtr; \
469 x *rawPtr = new x; \
470 smartPtr = rawPtr; \
471 rawPtr->UnRegister(); \
472 return smartPtr; \
473} \
474 virtual ::igtl::LightObject::Pointer CreateAnother(void) const \
475{ \
476 ::igtl::LightObject::Pointer smartPtr; \
477 smartPtr = x::New().GetPointer(); \
478 return smartPtr; \
479}
481
484#define igtlTypeMacro(thisClass,superclass) \
485 virtual const char *GetNameOfClass() const \
486 {return #thisClass;}
487
488
489//namespace igtl
490//{
497//extern IGTLCommon_EXPORT void OutputWindowDisplayText(const char*);
498//extern IGTLCommon_EXPORT void OutputWindowDisplayErrorText(const char*);
499//extern IGTLCommon_EXPORT void OutputWindowDisplayWarningText(const char*);
500//extern IGTLCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char*);
501//extern IGTLCommon_EXPORT void OutputWindowDisplayDebugText(const char*);
502//} // end namespace igtl
504
508#if defined(IGTL_LEAN_AND_MEAN) || defined(__BORLANDC__)
509#define igtlDebugMacro(x)
510#else
511#define igtlDebugMacro(x) \
512 { if (this->GetDebug() /*&& ::igtl::Object::GetGlobalWarningDisplay()*/) \
513 { ::igtl::OStringStream igtlmsg; \
514 igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
515 << this->GetNameOfClass() << " (" << this << "): " x \
516 << "\n\n"; \
517 std::cerr << igtlmsg.str(); /*::igtl::OutputWindowDisplayDebugText(igtlmsg.str().c_str());*/} \
518}
519#endif
521
522
526#ifdef IGTL_LEAN_AND_MEAN
527#define igtlWarningMacro(x)
528#else
529#define igtlWarningMacro(x) \
530 { if ( 1/*::igtl::Object::GetGlobalWarningDisplay()*/) \
531 { ::igtl::OStringStream igtlmsg; \
532 igtlmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
533 << this->GetNameOfClass() << " (" << this << "): " x \
534 << "\n\n"; \
535 std::cerr << igtlmsg.str(); /*::igtl::OutputWindowDisplayWarningText(igtlmsg.str().c_str());*/} \
536}
537#endif
539
540namespace igtl
541{
542
548#if !defined(IGTL_NO_ANSI_STRING_STREAM)
549class OStringStream: public std::ostringstream
550{
551public:
553private:
555 void operator=(const OStringStream&);
556};
557#else
558namespace OStringStreamDetail
559{
560 class Cleanup
561 {
562 public:
563 Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
564 ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
565 static void IgnoreUnusedVariable(const Cleanup&) {}
566 protected:
567 std::ostrstream& m_OStrStream;
568 };
569}//namespace OStringStreamDetail
571
572class OStringStream: public std::ostrstream
573{
574public:
575 typedef std::ostrstream Superclass;
576 OStringStream() {}
577 std::string str()
578 {
579 OStringStreamDetail::Cleanup cleanup(*this);
580 OStringStreamDetail::Cleanup::IgnoreUnusedVariable(cleanup);
581 int pcount = this->pcount();
582 const char* ptr = this->Superclass::str();
583 return std::string(ptr?ptr:"", pcount);
584 }
585private:
587 void operator=(const OStringStream&);
588};
589#endif
590
591}//namespace igtl
592
593#if defined(IGTL_CPP_FUNCTION)
594 #if defined(__BORLANDC__)
595 #define IGTL_LOCATION __FUNC__
596 #elif defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(CABLE_CONFIGURATION) && !defined(CSWIG)
597 #define IGTL_LOCATION __FUNCSIG__
598 #elif defined(__GNUC__)
599 #define IGTL_LOCATION __PRETTY_FUNCTION__
600 #else
601 #define IGTL_LOCATION __FUNCTION__
602 #endif
603#else
604 #define IGTL_LOCATION "unknown"
605#endif
606
607#define igtlExceptionMacro(x) \
608 { \
609 ::igtl::OStringStream igtlmsg; \
610 igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
611 << this->GetNameOfClass() << " (" << this << "): " x \
612 << "\n\n"; \
613 std::cerr << igtlmsg.str(); /*::igtl::OutputWindowDisplayDebugText(igtlmsg.str().c_str());*/ \
614}
615
616#define igtlErrorMacro(x) \
617 { \
618 ::igtl::OStringStream igtlmsg; \
619 igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
620 << this->GetNameOfClass() << " (" << this << "): " x \
621 << "\n\n"; \
622 std::cerr << igtlmsg.str(); /*::igtl::OutputWindowDisplayDebugText(igtlmsg.str().c_str());*/ \
623}
624
625
626#ifdef IGTL_LEAN_AND_MEAN
627#define igtlGenericOutputMacro(x)
628#else
629#define igtlGenericOutputMacro(x) \
630 { if (1/*::igtl::Object::GetGlobalWarningDisplay()*/) \
631 { ::igtl::OStringStream igtlmsg; \
632 igtlmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
633 x << "\n\n"; \
634 std::cerr << igtlmsg.str();/*::igtl::OutputWindowDisplayGenericOutputText(igtlmsg.str().c_str());*/} \
635}
636#endif
637
638
639
640//----------------------------------------------------------------------------
641// Macros for simplifying the use of logging
642//
643#define igtlLogMacro( x, y) \
644{ \
645 if (this->GetLogger() ) \
646 { \
647 this->GetLogger()->Write(::igtl::LoggerBase::x, y); \
648 } \
649}
650
651
652#define igtlLogMacroStatic( obj, x, y) \
653{ \
654 if (obj->GetLogger() ) \
655 { \
656 obj->GetLogger()->Write(::igtl::LoggerBase::x, y); \
657 } \
658}
659
660
661//----------------------------------------------------------------------------
662// Setup legacy code policy.
663//
664// CMake options IGTL_LEGACY_REMOVE and IGTL_LEGACY_SILENT are converted
665// to definitions (or non-defs) in igtlConfigure.h and tested below.
666// They may be used to completely remove legacy code or silence the
667// warnings. The default is to warn about their use.
668//
669// Source files that test the legacy code may define IGTL_LEGACY_TEST
670// like this:
671//
672// #define IGTL_LEGACY_TEST
673// #include "igtlClassWithDeprecatedMethod.h"
674//
675// in order to silence the warnings for calling deprecated methods.
676// No other source files in IGTL should call the methods since they are
677// provided only for compatibility with older user code.
678
679// Define igtlLegacyMacro to mark legacy methods where they are
680// declared in their class. Example usage:
681//
682// // @deprecated Replaced by MyOtherMethod() as of IGTL 2.0.
683// igtlLegacyMacro(void MyMethod());
684#if defined(IGTL_LEGACY_REMOVE)
685// Remove legacy methods completely. Put a bogus declaration in
686// place to avoid stray semicolons because this is an error for some
687// compilers. Using a class forward declaration allows any number
688// of repeats in any context without generating unique names.
689# define igtlLegacyMacro(method) class igtlLegacyMethodRemoved /* no ';' */
690#elif defined(IGTL_LEGACY_SILENT) || defined(IGTL_LEGACY_TEST) || defined(CSWIG)
691 // Provide legacy methods with no warnings.
692# define igtlLegacyMacro(method) method
693#else
694 // Setup compile-time warnings for uses of deprecated methods if
695 // possible on this compiler.
696# if defined(__GNUC__) && !defined(__INTEL_COMPILER) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
697# define igtlLegacyMacro(method) method __attribute__((deprecated))
698# elif defined(_MSC_VER) && _MSC_VER >= 1300
699# define igtlLegacyMacro(method) __declspec(deprecated) method
700# else
701# define igtlLegacyMacro(method) method
702# endif
703#endif
704
705// Macros to create runtime deprecation warning messages in function
706// bodies. Example usage:
707//
708// void igtlMyClass::MyOldMethod()
709// {
710// igtlLegacyBodyMacro(igtlMyClass::MyOldMethod, 2.0);
711// }
712//
713// void igtlMyClass::MyMethod()
714// {
715// igtlLegacyReplaceBodyMacro(igtlMyClass::MyMethod, 2.0,
716// igtlMyClass::MyOtherMethod);
717// }
718#if defined(IGTL_LEGACY_REMOVE) || defined(IGTL_LEGACY_SILENT)
719# define igtlLegacyBodyMacro(method, version)
720# define igtlLegacyReplaceBodyMacro(method, version, replace)
721#else
722# define igtlLegacyBodyMacro(method, version) \
723 igtlWarningMacro(#method " was deprecated for IGTL " #version " and will be removed in a future version.")
724# define igtlLegacyReplaceBodyMacro(method, version, replace) \
725 igtlWarningMacro(#method " was deprecated for IGTL " #version " and will be removed in a future version. Use " #replace " instead.")
726#endif
727
728#if defined(__INTEL_COMPILER)
729# pragma warning (disable: 193) /* #if testing undefined identifier */
730#endif
731
732//=============================================================================
733/* Choose a way to prevent template instantiation on this platform.
734 - IGTL_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
735 prevent instantiation
736 - IGTL_TEMPLATE_EXTERN = use extern template to prevent instantiation
737
738 Note that VS 6 supports extern template instantiation but it is
739 hard to block the resulting warning because its stream headers
740 re-enable it. Therefore we just disable support for now.
741*/
742#if defined(__sgi) && defined(_COMPILER_VERSION)
743# define IGTL_TEMPLATE_DO_NOT_INSTANTIATE 1
744#elif defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 700
745# define IGTL_TEMPLATE_EXTERN 1
746#elif defined(__GNUC__) && __GNUC__ >= 3
747# define IGTL_TEMPLATE_EXTERN 1
748#elif defined(_MSC_VER) && _MSC_VER >= 1300
749# define IGTL_TEMPLATE_EXTERN 1
750#endif
751#if !defined(IGTL_TEMPLATE_DO_NOT_INSTANTIATE)
752# define IGTL_TEMPLATE_DO_NOT_INSTANTIATE 0
753#endif
754#if !defined(IGTL_TEMPLATE_EXTERN)
755# define IGTL_TEMPLATE_EXTERN 0
756#endif
757
758/* Define a macro to explicitly instantiate a template.
759 - IGTL_TEMPLATE_EXPORT(X) =
760 Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
761 examples: IGTL_TEMPLATE_EXPORT(1(class Foo<int>))
762 IGTL_TEMPLATE_EXPORT(2(class Bar<int, char>))
763 Use one level of expansion delay to allow user code to have
764 a macro determining the number of arguments. */
765#define IGTL_TEMPLATE_EXPORT(x) IGTL_TEMPLATE_EXPORT_DELAY(x)
766#define IGTL_TEMPLATE_EXPORT_DELAY(x) template IGTL_TEMPLATE_##x;
767
768/* Define a macro to prevent template instantiations.
769 - IGTL_TEMPLATE_IMPORT(X) =
770 Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
771 examples: IGTL_TEMPLATE_IMPORT(1(class Foo<int>))
772 IGTL_TEMPLATE_IMPORT(2(class Bar<int, char>))
773 Use one level of expansion delay to allow user code to have
774 a macro determining the number of arguments.
775*/
776#if IGTL_TEMPLATE_EXTERN
777# define IGTL_TEMPLATE_IMPORT_DELAY(x) extern template IGTL_TEMPLATE_##x;
778# if defined(_MSC_VER)
779# pragma warning (disable: 4231) /* extern template extension */
780# endif
781#elif IGTL_TEMPLATE_DO_NOT_INSTANTIATE
782# define IGTL_TEMPLATE_IMPORT_DELAY(x) \
783 IGTL_TEMPLATE_IMPORT_IMPL(do_not_instantiate IGTL_TEMPLATE_##x)
784# define IGTL_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
785#endif
786#if defined(IGTL_TEMPLATE_IMPORT_DELAY)
787# define IGTL_TEMPLATE_IMPORT(x) IGTL_TEMPLATE_IMPORT_DELAY(x)
788# define IGTL_TEMPLATE_IMPORT_WORKS 1
789#else
790# define IGTL_TEMPLATE_IMPORT(x)
791# define IGTL_TEMPLATE_IMPORT_WORKS 0
792#endif
793
794/* Define macros to export and import template instantiations. These
795 depend on each class providing a macro defining the instantiations
796 given template arguments in X. The argument X is of the form
797 N(a1[,a2...,aN]). The argument Y is a valid preprocessing token
798 unique to the template arguments given in X. Typical usage is
799
800 IGTL_EXPORT_TEMPLATE(igtlfoo_EXPORT, Foo, (int), I)
801 IGTL_EXPORT_TEMPLATE(igtlfoo_EXPORT, Bar, (int, char), IC)
802
803 The IGTL_TEMPLATE_<name> macro should be defined in igtl<name>.h and
804 is of the following form:
805
806 #define IGTL_TEMPLATE_<name>(_, EXPORT, x, y) namespace igtl { \
807 _(<n>(class EXPORT <name>< IGTL_TEMPLATE_<n> x >)) \
808 namespace Templates { typedef <name>< IGTL_TEMPLATE_<n> x > <name>##y; }\
809 }
810
811 The argument "_" will be replaced by another macro such as
812 IGTL_TEMPLATE_EXPORT or IGTL_TEMPLATE_IMPORT, so it should be used as
813 if calling one of these macros. The argument "EXPORT" will be
814 replaced by a dllexport/dllimport macro such as IGTLCommon_EXPORT.
815 The argument "x" is a paren-enclosed list of template arguments.
816 The argument "y" is a preprocessing token corresponding to the
817 given template arguments and should be used to construct typedef
818 names for the instantiations.
819
820 Note the use of IGTL_TEMPLATE_<n>, where <n> is the number of
821 template arguments for the class template. Note also that the
822 number of template arguments is usually the length of the list
823 nested within the inner parentheses, so the instantiation is listed
824 with the form <n>(...). Example definitions:
825
826 #define IGTL_TEMPLATE_Foo(_, EXPORT, x, y) namespace igtl { \
827 _(1(class EXPORT Foo< IGTL_TEMPLATE_1 x >)) \
828 _(1(EXPORT std::ostream& operator<<(std::ostream&, \
829 const Foo< IGTL_TEMPLATE_1 x >&))) \
830 namespace Templates { typedef Foo< IGTL_TEMPLATE_1 x > Foo##y; }\
831 }
832
833 #define IGTL_TEMPLATE_Bar(_, EXPORT, x, y) namespace igtl { \
834 _(2(class EXPORT Bar< IGTL_TEMPLATE_2 x >)) \
835 _(1(EXPORT std::ostream& operator<<(std::ostream&, \
836 const Bar< IGTL_TEMPLATE_2 x >&))) \
837 namespace Templates { typedef Bar< IGTL_TEMPLATE_2 x > Bar##y; }\
838 }
839
840 Note that in the stream operator for template Bar there is a "1" at
841 the beginning even though two arguments are taken. This is because
842 the expression "IGTL_TEMPLATE_2 x" is contained inside the
843 parentheses of the function signature which protects the resulting
844 comma from separating macro arguments. Therefore the nested
845 parentheses contain a list of only one macro argument.
846
847 The IGTL_EMPTY macro used in these definitions is a hack to work
848 around a VS 6.0 preprocessor bug when EXPORT is empty.
849*/
850#define IGTL_EXPORT_TEMPLATE(EXPORT, c, x, y) \
851 IGTL_TEMPLATE_##c(IGTL_TEMPLATE_EXPORT, EXPORT IGTL_EMPTY, x, y)
852#define IGTL_IMPORT_TEMPLATE(EXPORT, c, x, y) \
853 IGTL_TEMPLATE_##c(IGTL_TEMPLATE_IMPORT, EXPORT IGTL_EMPTY, x, y)
854#define IGTL_EMPTY
855
856/* Define macros to support passing a variable number of arguments
857 throug other macros. This is used by IGTL_TEMPLATE_EXPORT,
858 IGTL_TEMPLATE_IMPORT, and by each template's instantiation
859 macro. */
860#define IGTL_TEMPLATE_1(x1) x1
861#define IGTL_TEMPLATE_2(x1,x2) x1,x2
862#define IGTL_TEMPLATE_3(x1,x2,x3) x1,x2,x3
863#define IGTL_TEMPLATE_4(x1,x2,x3,x4) x1,x2,x3,x4
864#define IGTL_TEMPLATE_5(x1,x2,x3,x4,x5) x1,x2,x3,x4,x5
865#define IGTL_TEMPLATE_6(x1,x2,x3,x4,x5,x6) x1,x2,x3,x4,x5,x6
866#define IGTL_TEMPLATE_7(x1,x2,x3,x4,x5,x6,x7) x1,x2,x3,x4,x5,x6,x7
867#define IGTL_TEMPLATE_8(x1,x2,x3,x4,x5,x6,x7,x8) x1,x2,x3,x4,x5,x6,x7,x8
868#define IGTL_TEMPLATE_9(x1,x2,x3,x4,x5,x6,x7,x8,x9) x1,x2,x3,x4,x5,x6,x7,x8,x9
869
870/* In order to support both implicit and explicit instantation a .h
871 file needs to know whether it should include its .txx file
872 containing the template definitions. Define a macro to tell
873 it. Typical usage in igtlFoo.h:
874 #if IGTL_TEMPLATE_TXX
875 # include "igtlFoo.txx"
876 #endif
877*/
878#if defined(IGTL_MANUAL_INSTANTIATION)
879# define IGTL_TEMPLATE_TXX 0
880#else
881# define IGTL_TEMPLATE_TXX !(IGTL_TEMPLATE_CXX || IGTL_TEMPLATE_TYPE)
882#endif
883
884/* All explicit instantiation source files define IGTL_TEMPLATE_CXX.
885 Define IGTL_MANUAL_INSTANTIATION to tell .h files that have not been
886 converted to this explicit instantiation scheme to not include
887 their .txx files. Also disable warnings that commonly occur in
888 these files but are not useful. */
889#if IGTL_TEMPLATE_CXX
890# undef IGTL_MANUAL_INSTANTIATION
891# define IGTL_MANUAL_INSTANTIATION
892# if defined(_MSC_VER)
893# pragma warning (disable: 4275) /* non dll-interface base */
894# pragma warning (disable: 4661) /* no definition available */
895# endif
896#endif
897//=============================================================================
898
899/* Define macros to export and import template instantiations for each
900 library in IGTL. */
901#define IGTL_EXPORT_IGTLCommon(c, x, n) \
902 IGTL_EXPORT_TEMPLATE(IGTLCommon_EXPORT, c, x, n)
903#define IGTL_IMPORT_IGTLCommon(c, x, n) \
904 IGTL_IMPORT_TEMPLATE(IGTLCommon_EXPORT, c, x, n)
905
906/* Define a macro to decide whether to block instantiation of IGTL
907 templates. They should be blocked only if the platform supports
908 blocking template instantiation and the explicit instantiations are
909 available.
910
911 - IGTL_TEMPLATE_EXPLICIT =
912 Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
913 instantiations of templates explicitly instantiated elsewhere.
914 Typical usage in igtlFoo.h:
915 #if IGTL_TEMPLATE_EXPLICIT
916 # include "igtlFoo+-.h"
917 #endif
918*/
919#if IGTL_TEMPLATE_IMPORT_WORKS && defined(IGTL_EXPLICIT_INSTANTIATION)
920# define IGTL_TEMPLATE_EXPLICIT !IGTL_TEMPLATE_CXX
921#else
922# define IGTL_TEMPLATE_EXPLICIT 0
923#endif
924
925
926//----------------------------------------------------------------------------
927// Macro to declare that a function does not return. __attribute__((noreturn))
928// On some compiler, functions that do not return (ex: exit(0)) must
929// have the noreturn attribute. Otherwise, a warning is raised. Use
930// that macro to avoid those warnings. GCC defines the attribute
931// noreturn for versions 2.5 and higher.
932#if defined(__GNUC__)
933# if (((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 3))
934# define IGTL_NO_RETURN \
935 __attribute__ ((noreturn))
936# endif
937#else
938# define IGTL_NO_RETURN
939#endif
940
941
942#ifdef IGTL_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
943//--------------------------------------------------------------------------------
944// Helper macros for Template Meta-Programming techniques of for-loops unrolling
945//--------------------------------------------------------------------------------
946
947//--------------------------------------------------------------------------------
948// Macro that generates an unrolled for loop for assigning elements of one array
949// to elements of another array The array are assumed to be of same length
950// (dimension), and this is also assumed to be the value of NumberOfIterations.
951// No verification of size is performed. Casting is perfomed as part of the
952// assignment, by using the DestinationElementType as the casting type.
953// Source and destination array types must have defined opearator[] in their API.
954#define igtlFoorLoopAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
955 for(unsigned int i=0;i < NumberOfIterations; ++i) \
956 { \
957 DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
958 }
959
960//--------------------------------------------------------------------------------
961// Macro that generates an unrolled for loop for rounding and assigning
962// elements of one array to elements of another array The array are assumed to
963// be of same length (dimension), and this is also assumed to be the value of
964// NumberOfIterations. No verification of size is performed. Casting is
965// perfomed as part of the assignment, by using the DestinationElementType as
966// the casting type.
967// Source and destination array types must have defined opearator[] in their API.
968#define igtlFoorLoopRoundingAndAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
969 for(unsigned int i=0;i < NumberOfIterations; ++i) \
970 { \
971 DestinationArray[i] = static_cast< DestinationElementType >( vnl_math_rnd( SourceArray[i] ) ); \
972 }
973
974#endif
975// end of Template Meta Programming helper macros
976
977
978#endif //end of igtlMacro.h
The "igtl" namespace contains all OpenIGTLink classes. There are several nested namespaces within the...

Generated for OpenIGTLink by Doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2012