54 #if !defined(CMAKE_NO_ANSI_STRING_STREAM)
56 #elif !defined(CMAKE_NO_ANSI_STREAM_HEADERS)
58 # define IGTL_NO_ANSI_STRING_STREAM
60 # include <strstream.h>
61 # define IGTL_NO_ANSI_STRING_STREAM
74 #define igtlNotUsed(x)
90 #if defined(_MSC_VER) && (_MSC_VER <= 1300)
91 # define IGTL_NO_INCLASS_MEMBER_INITIALIZATION
93 #if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x540)
94 # define IGTL_NO_INCLASS_MEMBER_INITIALIZATION
96 #if defined(__SVR4) && !defined(__SUNPRO_CC)
97 # define IGTL_NO_INCLASS_MEMBER_INITIALIZATION
107 #if defined(__GNUC__)
108 # define IGTL_NO_SIZEOF_CONSTANT_LOOKUP
111 #if defined(_MSC_VER) && (_MSC_VER <= 1300)
112 #define IGTL_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
115 #if defined(IGTL_NO_INCLASS_MEMBER_INITIALIZATION) || \
116 defined(IGTL_NO_SIZEOF_CONSTANT_LOOKUP)
117 # define igtlStaticConstMacro(name,type,value) enum { name = value }
119 # define igtlStaticConstMacro(name,type,value) static const type name = value
122 #ifdef IGTL_NO_SELF_AS_TRAIT_IN_TEMPLATE_ARGUMENTS
123 # define igtlGetStaticConstMacro(name) name
125 # define igtlGetStaticConstMacro(name) (Self::name)
129 #define igtlSetInputMacro(name, type, number) \
130 virtual void Set##name##Input(const type *_arg) \
132 igtlDebugMacro("setting input " #name " to " << _arg); \
133 if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \
135 this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \
138 virtual void SetInput##number(const type *_arg) \
140 igtlDebugMacro("setting input " #number " to " << _arg); \
141 if (_arg != static_cast<type *>(this->ProcessObject::GetInput( number ))) \
143 this->ProcessObject::SetNthInput( number, const_cast<type *>(_arg) ); \
149 #define igtlSuperclassTraitMacro(traitnameType) \
150 typedef typename Superclass::traitnameType traitnameType;
153 #define igtlGetInputMacro(name, type, number) \
154 virtual const type * Get##name##Input() const \
156 igtlDebugMacro("returning input " << #name " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
157 return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
159 virtual const type * GetInput##number() const \
161 igtlDebugMacro("returning input " << #number " of " << static_cast<const type *>(this->ProcessObject::GetInput( number )) ); \
162 return static_cast<const type *>(this->ProcessObject::GetInput( number )); \
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) \
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 ) \
182 typename DecoratorType::Pointer newInput = DecoratorType::New(); \
183 newInput->Set( _arg ); \
184 this->Set##name##Input( newInput ); \
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) \
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 ) \
205 typename DecoratorType::Pointer newInput = DecoratorType::New(); \
206 newInput->Set( _arg ); \
207 this->Set##name##Input( newInput ); \
213 #define igtlSetMacro(name,type) \
214 virtual void Set##name (const type _arg) \
216 igtlDebugMacro("setting " #name " to " << _arg); \
217 if (this->m_##name != _arg) \
219 this->m_##name = _arg; \
225 #define igtlGetMacro(name,type) \
226 virtual type Get##name () \
228 igtlDebugMacro("returning " << #name " of " << this->m_##name ); \
229 return this->m_##name; \
236 #define igtlGetConstMacro(name,type) \
237 virtual type Get##name () const \
239 igtlDebugMacro("returning " << #name " of " << this->m_##name ); \
240 return this->m_##name; \
248 #define igtlGetConstReferenceMacro(name,type) \
249 virtual const type & Get##name () const \
251 igtlDebugMacro("returning " << #name " of " << this->m_##name ); \
252 return this->m_##name; \
259 #define igtlSetEnumMacro(name,type) \
260 virtual void Set##name (const type _arg) \
262 igtlDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
263 if (this->m_##name != _arg) \
265 this->m_##name = _arg; \
273 #define igtlGetEnumMacro(name,type) \
274 virtual type Get##name () const \
276 igtlDebugMacro("returning " << #name " of " << static_cast<long>(this->m_##name) ); \
277 return this->m_##name; \
284 #define igtlSetStringMacro(name) \
285 virtual void Set##name (const char* _arg) \
287 if ( _arg && (_arg == this->m_##name) ) { return;} \
290 this->m_##name = _arg;\
294 this->m_##name = ""; \
297 virtual void Set##name (const std::string & _arg) \
299 this->Set##name( _arg.c_str() ); \
307 #define igtlGetStringMacro(name) \
308 virtual const char* Get##name () const \
310 return this->m_##name.c_str(); \
316 #define igtlSetClampMacro(name,type,min,max) \
317 virtual void Set##name (type _arg) \
319 igtlDebugMacro("setting " << #name " to " << _arg ); \
320 if (this->m_##name != (_arg<min?min:(_arg>max?max:_arg))) \
322 this->m_##name = (_arg<min?min:(_arg>max?max:_arg)); \
331 #define igtlSetObjectMacro(name,type) \
332 virtual void Set##name (type* _arg) \
334 igtlDebugMacro("setting " << #name " to " << _arg ); \
335 if (this->m_##name != _arg) \
337 this->m_##name = _arg; \
344 #define igtlGetObjectMacro(name,type) \
345 virtual type * Get##name () \
347 igtlDebugMacro("returning " #name " address " << this->m_##name ); \
348 return this->m_##name.GetPointer(); \
356 #define igtlSetConstObjectMacro(name,type) \
357 virtual void Set##name (const type* _arg) \
359 igtlDebugMacro("setting " << #name " to " << _arg ); \
360 if (this->m_##name != _arg) \
362 this->m_##name = _arg; \
370 #define igtlGetConstObjectMacro(name,type) \
371 virtual const type * Get##name () const \
373 igtlDebugMacro("returning " #name " address " << this->m_##name ); \
374 return this->m_##name.GetPointer(); \
380 #define igtlGetConstReferenceObjectMacro(name,type) \
381 virtual const typename type::Pointer & Get##name () const \
383 igtlDebugMacro("returning " #name " address " << this->m_##name ); \
384 return this->m_##name; \
390 #define igtlBooleanMacro(name) \
391 virtual void name##On () { this->Set##name(true);} \
392 virtual void name##Off () { this->Set##name(false);}
398 #define igtlSetVectorMacro(name,type,count) \
399 virtual void Set##name(type data[]) \
402 for (i=0; i<count; i++) { if ( data[i] != this->m_##name[i] ) { break; }} \
405 for (i=0; i<count; i++) { this->m_##name[i] = data[i]; }\
412 #define igtlGetVectorMacro(name,type,count) \
413 virtual type *Get##name () const \
415 return this->m_##name; \
434 #define igtlNewMacro(x) \
435 static Pointer New(void) \
437 Pointer smartPtr = ::igtl::ObjectFactory<x>::Create(); \
438 if(smartPtr.GetPointer() == NULL) \
442 smartPtr->UnRegister(); \
445 virtual ::igtl::LightObject::Pointer CreateAnother(void) const \
447 ::igtl::LightObject::Pointer smartPtr; \
448 smartPtr = x::New().GetPointer(); \
470 #define igtlFactorylessNewMacro(x) \
471 static Pointer New(void) \
476 rawPtr->UnRegister(); \
479 virtual ::igtl::LightObject::Pointer CreateAnother(void) const \
481 ::igtl::LightObject::Pointer smartPtr; \
482 smartPtr = x::New().GetPointer(); \
489 #define igtlTypeMacro(thisClass,superclass) \
490 virtual const char *GetNameOfClass() const \
513 #if defined(IGTL_LEAN_AND_MEAN) || defined(__BORLANDC__)
514 #define igtlDebugMacro(x)
516 #define igtlDebugMacro(x) \
517 { if (this->GetDebug() ) \
518 { ::igtl::OStringStream igtlmsg; \
519 igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
520 << this->GetNameOfClass() << " (" << this << "): " x \
522 std::cerr << igtlmsg.str(); } \
531 #ifdef IGTL_LEAN_AND_MEAN
532 #define igtlWarningMacro(x)
534 #define igtlWarningMacro(x) \
536 { ::igtl::OStringStream igtlmsg; \
537 igtlmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
538 << this->GetNameOfClass() << " (" << this << "): " x \
540 std::cerr << igtlmsg.str(); } \
553 #if !defined(IGTL_NO_ANSI_STRING_STREAM)
563 namespace OStringStreamDetail
568 Cleanup(std::ostrstream& ostr): m_OStrStream(ostr) {}
569 ~Cleanup() { m_OStrStream.rdbuf()->freeze(0); }
570 static void IgnoreUnusedVariable(
const Cleanup&) {}
572 std::ostrstream& m_OStrStream;
577 class OStringStream:
public std::ostrstream
580 typedef std::ostrstream Superclass;
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);
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__
606 #define IGTL_LOCATION __FUNCTION__
609 #define IGTL_LOCATION "unknown"
612 #define igtlExceptionMacro(x) \
614 ::igtl::OStringStream igtlmsg; \
615 igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
616 << this->GetNameOfClass() << " (" << this << "): " x \
618 std::cerr << igtlmsg.str(); \
621 #define igtlErrorMacro(x) \
623 ::igtl::OStringStream igtlmsg; \
624 igtlmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
625 << this->GetNameOfClass() << " (" << this << "): " x \
627 std::cerr << igtlmsg.str(); \
631 #ifdef IGTL_LEAN_AND_MEAN
632 #define igtlGenericOutputMacro(x)
634 #define igtlGenericOutputMacro(x) \
636 { ::igtl::OStringStream igtlmsg; \
637 igtlmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
639 std::cerr << igtlmsg.str();} \
648 #define igtlLogMacro( x, y) \
650 if (this->GetLogger() ) \
652 this->GetLogger()->Write(::igtl::LoggerBase::x, y); \
657 #define igtlLogMacroStatic( obj, x, y) \
659 if (obj->GetLogger() ) \
661 obj->GetLogger()->Write(::igtl::LoggerBase::x, y); \
689 #if defined(IGTL_LEGACY_REMOVE)
694 # define igtlLegacyMacro(method) class igtlLegacyMethodRemoved
695 #elif defined(IGTL_LEGACY_SILENT) || defined(IGTL_LEGACY_TEST) || defined(CSWIG)
697 # define igtlLegacyMacro(method) method
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
706 # define igtlLegacyMacro(method) method
723 #if defined(IGTL_LEGACY_REMOVE) || defined(IGTL_LEGACY_SILENT)
724 # define igtlLegacyBodyMacro(method, version)
725 # define igtlLegacyReplaceBodyMacro(method, version, replace)
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.")
733 #if defined(__INTEL_COMPILER)
734 # pragma warning (disable: 193)
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
756 #if !defined(IGTL_TEMPLATE_DO_NOT_INSTANTIATE)
757 # define IGTL_TEMPLATE_DO_NOT_INSTANTIATE 0
759 #if !defined(IGTL_TEMPLATE_EXTERN)
760 # define IGTL_TEMPLATE_EXTERN 0
770 #define IGTL_TEMPLATE_EXPORT(x) IGTL_TEMPLATE_EXPORT_DELAY(x)
771 #define IGTL_TEMPLATE_EXPORT_DELAY(x) template IGTL_TEMPLATE_##x;
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)
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)
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
795 # define IGTL_TEMPLATE_IMPORT(x)
796 # define IGTL_TEMPLATE_IMPORT_WORKS 0
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)
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
883 #if defined(IGTL_MANUAL_INSTANTIATION)
884 # define IGTL_TEMPLATE_TXX 0
886 # define IGTL_TEMPLATE_TXX !(IGTL_TEMPLATE_CXX || IGTL_TEMPLATE_TYPE)
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)
899 # pragma warning (disable: 4661)
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)
924 #if IGTL_TEMPLATE_IMPORT_WORKS && defined(IGTL_EXPLICIT_INSTANTIATION)
925 # define IGTL_TEMPLATE_EXPLICIT !IGTL_TEMPLATE_CXX
927 # define IGTL_TEMPLATE_EXPLICIT 0
937 #if defined(__GNUC__)
938 # if (((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 3))
939 # define IGTL_NO_RETURN \
940 __attribute__ ((noreturn))
943 # define IGTL_NO_RETURN
947 #ifdef IGTL_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
959 #define igtlFoorLoopAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
960 for(unsigned int i=0;i < NumberOfIterations; ++i) \
962 DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
973 #define igtlFoorLoopRoundingAndAssignmentMacro(DestinationType,SourceType,DestinationElementType,DestinationArray,SourceArray,NumberOfIterations) \
974 for(unsigned int i=0;i < NumberOfIterations; ++i) \
976 DestinationArray[i] = static_cast< DestinationElementType >( vnl_math_rnd( SourceArray[i] ) ); \
983 #endif //end of igtlMacro.h