42 #include "itkConfigure.h"
43 #include "ITKCommonExport.h"
55 #include <type_traits>
81 #define ITK_NOOP_STATEMENT static_assert(true, "")
92 #define ITK_MACROEND_NOOP_STATEMENT ITK_NOOP_STATEMENT
99 #define ITK_PRAGMA(x) _Pragma(#x)
106 #if defined(__GNUC__)
107 # define ITK_GCC_PRAGMA_PUSH ITK_PRAGMA(GCC diagnostic push)
108 # define ITK_GCC_PRAGMA_POP ITK_PRAGMA(GCC diagnostic pop)
109 # define ITK_GCC_SUPPRESS_Wfloat_equal ITK_PRAGMA(GCC diagnostic ignored "-Wfloat-equal")
110 # define ITK_GCC_SUPPRESS_Wformat_nonliteral ITK_PRAGMA(GCC diagnostic ignored "-Wformat-nonliteral")
111 # define ITK_GCC_SUPPRESS_Warray_bounds ITK_PRAGMA(GCC diagnostic ignored "-Warray-bounds")
113 # define ITK_GCC_PRAGMA_PUSH
114 # define ITK_GCC_PRAGMA_POP
115 # define ITK_GCC_SUPPRESS_Wfloat_equal
116 # define ITK_GCC_SUPPRESS_Wformat_nonliteral
117 # define ITK_GCC_SUPPRESS_Warray_bounds
121 #if defined(__clang__) && defined(__has_warning)
122 # define ITK_CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
123 # define ITK_CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
124 # define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant ITK_PRAGMA(clang diagnostic ignored "-Wzero-as-null-pointer-constant")
126 # define ITK_CLANG_PRAGMA_PUSH
127 # define ITK_CLANG_PRAGMA_POP
128 # define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant
133 #define CLANG_PRAGMA_PUSH ITK_CLANG_PRAGMA_PUSH
134 #define CLANG_PRAGMA_POP ITK_CLANG_PRAGMA_POP
135 #define CLANG_SUPPRESS_Wfloat_equal ITK_GCC_SUPPRESS_Wfloat_equal
137 #if !defined(ITK_LEGACY_REMOVE)
139 # define CLANG_SUPPRESS_Wcpp14_extensions \
140 [[deprecated("Remove deprecated CLANG_SUPPRESS_Wcpp14_extensions c++14 warning suppression")]] void * \
141 CLANG_SUPPRESS_Wcpp14_extensions = nullptr;
145 #if defined(__INTEL_COMPILER)
146 # define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
147 # define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
148 # define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
150 # define INTEL_PRAGMA_WARN_PUSH
151 # define INTEL_PRAGMA_WARN_POP
152 # define INTEL_SUPPRESS_warning_1292
163 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
164 # define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
165 # define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
166 # define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
168 # define ITK_GCC_PRAGMA_DIAG(x)
169 # define ITK_GCC_PRAGMA_DIAG_PUSH()
170 # define ITK_GCC_PRAGMA_DIAG_POP()
177 #if defined(_MSC_VER) && (_MSC_VER < 1920)
178 # error "MSVC versions before Visual Studio 2019 are not supported"
180 #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
181 # error "SUNPro C++ < 5.14.0 is not supported"
183 #if defined(__CYGWIN__)
184 # error "The Cygwin compiler is not supported"
186 #if defined(__BORLANDC__)
187 # error "The Borland C compiler is not supported"
189 #if defined(__MWERKS__)
190 # error "The MetroWerks compiler is not supported"
192 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7)
193 # error "GCC < 7 is not supported"
199 # error "The SGI compiler is not supported"
201 #if defined(__APPLE__)
202 # if defined(__clang__) && (__cplusplus < 201703L)
203 # error "Apple LLVM compiling with a standard less than C++17 is not supported"
205 #elif defined(__clang__) && (__clang_major__ < 5)
206 # error "Clang < 5 is not supported"
208 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910)
209 # error "Intel C++ < 19.1 is not supported4"
213 #if defined(_WIN32) || defined(WIN32)
214 # define ITK_ABI_IMPORT __declspec(dllimport)
215 # define ITK_ABI_EXPORT __declspec(dllexport)
216 # define ITK_ABI_HIDDEN
219 # define ITK_ABI_IMPORT __attribute__((visibility("default")))
220 # define ITK_ABI_EXPORT __attribute__((visibility("default")))
221 # define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
223 # define ITK_ABI_IMPORT
224 # define ITK_ABI_EXPORT
225 # define ITK_ABI_HIDDEN
230 #ifndef ITK_TEMPLATE_EXPORT
231 # ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
232 # define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
234 # define ITK_TEMPLATE_EXPORT
239 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
240 # define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
242 # define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
245 #ifndef ITK_FORWARD_EXPORT
247 # if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
248 defined(USE_COMPILER_HIDDEN_VISIBILITY)
249 # define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
251 # define ITK_FORWARD_EXPORT
276 #define itkNewMacro(x) \
277 itkSimpleNewMacro(x); \
278 itkCreateAnotherMacro(x); \
280 ITK_MACROEND_NOOP_STATEMENT
283 #define itkSimpleNewMacro(x) \
284 static Pointer New() \
286 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
287 if (smartPtr == nullptr) \
289 smartPtr = new x(); \
291 smartPtr->UnRegister(); \
294 ITK_MACROEND_NOOP_STATEMENT
296 #define itkCreateAnotherMacro(x) \
297 ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
298 ITK_MACROEND_NOOP_STATEMENT
300 #define itkCloneMacro(x) \
301 Pointer Clone() const \
303 Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
306 ITK_MACROEND_NOOP_STATEMENT
311 #define itkFactoryOnlyNewMacro(x) \
312 itkSimpleFactoryOnlyNewMacro(x); \
313 itkCreateAnotherMacro(x); \
315 ITK_MACROEND_NOOP_STATEMENT
318 #define itkSimpleFactoryOnlyNewMacro(x) \
319 static auto New()->Pointer \
321 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
322 if (smartPtr == nullptr) \
324 itkSpecializedMessageExceptionMacro(ExceptionObject, \
325 "Object factory failed to instantiate " << typeid(x).name()); \
327 smartPtr->UnRegister(); \
330 ITK_MACROEND_NOOP_STATEMENT
344 #define itkFactorylessNewMacro(x) \
345 static Pointer New() \
347 x * rawPtr = new x(); \
348 Pointer smartPtr = rawPtr; \
349 rawPtr->UnRegister(); \
352 itkCreateAnotherMacro(x); \
353 ITK_MACROEND_NOOP_STATEMENT
365 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
366 TypeName(const TypeName &) = delete; \
367 TypeName & operator=(const TypeName &) = delete; \
368 TypeName(TypeName &&) = delete; \
369 TypeName & operator=(TypeName &&) = delete
371 #if !defined(ITK_LEGACY_REMOVE)
372 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
374 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
375 static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
386 #define ITK_DEFAULT_COPY_AND_MOVE(TypeName) \
387 TypeName(const TypeName &) = default; \
388 TypeName & operator=(const TypeName &) = default; \
389 TypeName(TypeName &&) = default; \
390 TypeName & operator=(TypeName &&) = default
398 #if __cplusplus >= 202002L
399 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
405 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
408 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
412 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
413 bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
414 ITK_MACROEND_NOOP_STATEMENT
419 #define itkInternalGetNameOfClassImplementationMacro(thisClass) \
421 static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
422 "The macro argument `" #thisClass \
423 "` appears incorrect! It should correspond with the name of this class!"); \
426 ITK_MACROEND_NOOP_STATEMENT
432 #define itkVirtualGetNameOfClassMacro(thisClass) \
433 virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
435 #define itkOverrideGetNameOfClassMacro(thisClass) \
436 const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
438 #ifdef ITK_FUTURE_LEGACY_REMOVE
439 # define itkTypeMacro(thisClass, superclass) \
440 static_assert(false, \
441 "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
442 "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
443 # define itkTypeMacroNoParent(thisClass) \
444 static_assert(false, \
445 "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
446 "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
452 # define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
453 # define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
465 extern ITKCommon_EXPORT
void
466 OutputWindowDisplayText(
const char *);
469 extern ITKCommon_EXPORT
void
470 OutputWindowDisplayErrorText(
const char *);
472 extern ITKCommon_EXPORT
void
473 OutputWindowDisplayWarningText(
const char *);
475 extern ITKCommon_EXPORT
void
476 OutputWindowDisplayGenericOutputText(
const char *);
478 extern ITKCommon_EXPORT
void
479 OutputWindowDisplayDebugText(
const char *);
489 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
490 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
492 # define itkDebugMacro(x) \
494 using namespace ::itk::print_helper; \
495 if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
497 std::ostringstream itkmsg; \
498 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
499 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
500 ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
503 ITK_MACROEND_NOOP_STATEMENT
506 # define itkDebugStatement(x) x
513 #define itkWarningMacro(x) \
515 if (::itk::Object::GetGlobalWarningDisplay()) \
517 std::ostringstream itkmsg; \
518 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << '\n' \
519 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
520 ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
523 ITK_MACROEND_NOOP_STATEMENT
527 #define itkWarningStatement(x) x
529 #if defined(ITK_CPP_FUNCTION)
530 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
531 # define ITK_LOCATION __FUNCSIG__
532 # elif defined(__GNUC__)
533 # define ITK_LOCATION __PRETTY_FUNCTION__
535 # define ITK_LOCATION __FUNCTION__
538 # define ITK_LOCATION "unknown"
541 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
544 class newexcp : public parentexcp \
548 static constexpr const char * const default_exception_message = whatmessage; \
550 using parentexcp::parentexcp; \
551 itkOverrideGetNameOfClassMacro(newexcp); \
554 ITK_MACROEND_NOOP_STATEMENT
557 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
559 std::ostringstream exceptionDescriptionOutputStringStream; \
560 exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
561 throw ::itk::ExceptionType( \
562 std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
564 ITK_MACROEND_NOOP_STATEMENT
566 #define itkSpecializedExceptionMacro(ExceptionType) \
567 itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
572 #define itkExceptionMacro(x) \
573 itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
575 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
577 #define itkGenericOutputMacro(x) \
579 if (::itk::Object::GetGlobalWarningDisplay()) \
581 std::ostringstream itkmsg; \
582 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
583 ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
586 ITK_MACROEND_NOOP_STATEMENT
591 #define itkLogMacro(x, y) \
593 if (this->GetLogger()) \
595 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
598 ITK_MACROEND_NOOP_STATEMENT
600 #define itkLogMacroStatic(obj, x, y) \
602 if (obj->GetLogger()) \
604 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
607 ITK_MACROEND_NOOP_STATEMENT
638 #if defined(ITK_LEGACY_REMOVE)
639 # define itkLegacyMacro(method)
641 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
643 # define itkLegacyMacro(method) method
646 # define itkLegacyMacro(method) [[deprecated]] method
672 #if defined(ITK_LEGACY_SILENT)
673 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
674 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
675 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
676 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
678 # define itkLegacyBodyMacro(method, version) \
679 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
680 # define itkLegacyReplaceBodyMacro(method, version, replace) \
681 itkWarningMacro(#method " was deprecated for ITK " #version \
682 " and will be removed in a future version. Use " #replace " instead.")
683 # define itkGenericLegacyBodyMacro(method, version) \
684 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
685 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
686 itkGenericOutputMacro(#method " was deprecated for ITK " #version \
687 " and will be removed in a future version. Use " #replace " instead.")
694 #define ITK_CACHE_LINE_ALIGNMENT 64
702 #define itkPadStruct(mincachesize, oldtype, newtype) \
703 struct newtype : public oldtype \
705 char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
712 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
713 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
714 #elif defined(_MSC_VER)
715 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
717 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
720 #if defined(ITK_FUTURE_LEGACY_REMOVE)
743 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
744 #else // LEGACY_REMOVE
745 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
761 #define itkForLoopAssignmentMacro( \
762 DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
763 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
765 DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
767 ITK_MACROEND_NOOP_STATEMENT
778 #define itkForLoopRoundingAndAssignmentMacro( \
779 DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
780 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
782 DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
784 ITK_MACROEND_NOOP_STATEMENT
788 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
791 # define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
793 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
797 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
800 #define itkAssertOrThrowMacro(test, message) \
803 std::ostringstream msgstr; \
805 itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
807 ITK_MACROEND_NOOP_STATEMENT
809 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
810 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
812 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
822 #ifdef ITK_FUTURE_LEGACY_REMOVE
823 # define itkStaticConstMacro(name, type, value) \
824 "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
825 # define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
841 # define itkStaticConstMacro(name, type, value) static constexpr type name = value
843 # define itkGetStaticConstMacro(name) (Self::name)
847 #define itkSetInputMacro(name, type) \
848 virtual void Set##name(const type * _arg) \
850 itkDebugMacro("setting input " #name " to " << _arg); \
851 if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
853 this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
857 ITK_MACROEND_NOOP_STATEMENT
861 #define itkGetInputMacro(name, type) \
862 virtual const type * Get##name() const \
864 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
865 return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
867 ITK_MACROEND_NOOP_STATEMENT
872 #define itkSetDecoratedInputMacro(name, type) \
873 virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
875 itkDebugMacro("setting input " #name " to " << _arg); \
876 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
878 this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
882 virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
883 virtual void Set##name(const type & _arg) \
885 using DecoratorType = SimpleDataObjectDecorator<type>; \
886 itkDebugMacro("setting input " #name " to " << _arg); \
887 const DecoratorType * oldInput = \
888 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
889 ITK_GCC_PRAGMA_PUSH \
890 ITK_GCC_SUPPRESS_Wfloat_equal \
891 if (oldInput && oldInput->Get() == _arg) \
896 auto newInput = DecoratorType::New(); \
897 newInput->Set(_arg); \
898 this->Set##name##Input(newInput); \
900 ITK_MACROEND_NOOP_STATEMENT
905 #define itkGetDecoratedInputMacro(name, type) \
906 virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
908 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
909 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
911 virtual const type & Get##name() const \
913 itkDebugMacro("Getting input " #name); \
914 using DecoratorType = SimpleDataObjectDecorator<type>; \
915 const DecoratorType * input = \
916 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
917 if (input == nullptr) \
919 itkExceptionMacro("input" #name " is not set"); \
921 return input->Get(); \
923 ITK_MACROEND_NOOP_STATEMENT
928 #define itkSetGetDecoratedInputMacro(name, type) \
929 itkSetDecoratedInputMacro(name, type); \
930 itkGetDecoratedInputMacro(name, type)
936 #define itkSetDecoratedObjectInputMacro(name, type) \
937 virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
939 itkDebugMacro("setting input " #name " to " << _arg); \
940 if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
942 this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
946 virtual void Set##name(const type * _arg) \
948 using DecoratorType = DataObjectDecorator<type>; \
949 itkDebugMacro("setting input " #name " to " << _arg); \
950 const DecoratorType * oldInput = \
951 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
952 if (oldInput && oldInput->Get() == _arg) \
956 auto newInput = DecoratorType::New(); \
957 newInput->Set(_arg); \
958 this->Set##name##Input(newInput); \
960 ITK_MACROEND_NOOP_STATEMENT
967 #define itkGetDecoratedObjectInputMacro(name, type) \
968 virtual const DataObjectDecorator<type> * Get##name##Input() const \
970 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
971 return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
973 virtual const type * Get##name() const \
975 itkDebugMacro("Getting input " #name); \
976 using DecoratorType = DataObjectDecorator<type>; \
977 const DecoratorType * input = \
978 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
979 if (input == nullptr) \
983 return input->Get(); \
985 ITK_MACROEND_NOOP_STATEMENT
990 #define itkSetGetDecoratedObjectInputMacro(name, type) \
991 itkSetDecoratedObjectInputMacro(name, type); \
992 itkGetDecoratedObjectInputMacro(name, type)
996 #define itkSetMacro(name, type) \
997 virtual void Set##name(type _arg) \
999 itkDebugMacro("setting " #name " to " << _arg); \
1000 ITK_GCC_PRAGMA_PUSH \
1001 ITK_GCC_SUPPRESS_Wfloat_equal \
1002 if (this->m_##name != _arg) \
1004 this->m_##name = std::move(_arg); \
1007 ITK_GCC_PRAGMA_POP \
1009 ITK_MACROEND_NOOP_STATEMENT
1013 #define itkGetMacro(name, type) \
1014 virtual type Get##name() { return this->m_##name; } \
1015 ITK_MACROEND_NOOP_STATEMENT
1021 #define itkGetConstMacro(name, type) \
1022 virtual type Get##name() const { return this->m_##name; } \
1023 ITK_MACROEND_NOOP_STATEMENT
1030 #define itkGetConstReferenceMacro(name, type) \
1031 virtual const type & Get##name() const { return this->m_##name; } \
1032 ITK_MACROEND_NOOP_STATEMENT
1039 #define itkSetEnumMacro(name, type) \
1040 virtual void Set##name(const type _arg) \
1042 itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1043 if (this->m_##name != _arg) \
1045 this->m_##name = _arg; \
1049 ITK_MACROEND_NOOP_STATEMENT
1056 #define itkGetEnumMacro(name, type) \
1057 virtual type Get##name() const { return this->m_##name; } \
1058 ITK_MACROEND_NOOP_STATEMENT
1064 #define itkSetStringMacro(name) \
1065 virtual void Set##name(const char * _arg) \
1067 if (_arg && (_arg == this->m_##name)) \
1073 this->m_##name = _arg; \
1077 this->m_##name = ""; \
1081 virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1082 ITK_MACROEND_NOOP_STATEMENT
1089 #define itkGetStringMacro(name) \
1090 virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1091 ITK_MACROEND_NOOP_STATEMENT
1097 #define itkSetClampMacro(name, type, min, max) \
1098 virtual void Set##name(type _arg) \
1100 const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1101 itkDebugMacro("setting " << #name " to " << _arg); \
1102 ITK_GCC_PRAGMA_PUSH \
1103 ITK_GCC_SUPPRESS_Wfloat_equal \
1104 if (this->m_##name != temp_extrema) \
1106 this->m_##name = temp_extrema; \
1109 ITK_GCC_PRAGMA_POP \
1111 ITK_MACROEND_NOOP_STATEMENT
1119 #define itkSetObjectMacro(name, type) \
1120 virtual void Set##name(type * _arg) \
1122 itkDebugMacro("setting " << #name " to " << _arg); \
1123 if (this->m_##name != _arg) \
1125 this->m_##name = _arg; \
1129 ITK_MACROEND_NOOP_STATEMENT
1158 #define itkGetConstObjectMacro(name, type) \
1159 virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1160 ITK_MACROEND_NOOP_STATEMENT
1163 #if defined(ITK_FUTURE_LEGACY_REMOVE)
1169 # define itkGetObjectMacro(name, type) \
1170 virtual type * Get##name() \
1172 purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1174 ITK_MACROEND_NOOP_STATEMENT
1176 # define itkGetModifiableObjectMacro(name, type) \
1177 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1178 itkGetConstObjectMacro(name, type)
1180 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1183 # define itkGetObjectMacro(name, type) \
1184 virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1185 ITK_MACROEND_NOOP_STATEMENT
1186 # define itkGetModifiableObjectMacro(name, type) \
1187 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1188 itkGetConstObjectMacro(name, type); \
1189 itkGetObjectMacro(name, type)
1190 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1199 #define itkGetConstReferenceObjectMacro(name, type) \
1200 virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1201 ITK_MACROEND_NOOP_STATEMENT
1206 #define itkSetConstObjectMacro(name, type) \
1207 virtual void Set##name(const type * _arg) \
1209 itkDebugMacro("setting " << #name " to " << _arg); \
1210 if (this->m_##name != _arg) \
1212 this->m_##name = _arg; \
1216 ITK_MACROEND_NOOP_STATEMENT
1221 #define itkBooleanMacro(name) \
1222 virtual void name##On() { this->Set##name(true); } \
1223 virtual void name##Off() { this->Set##name(false); } \
1224 ITK_MACROEND_NOOP_STATEMENT
1231 #define itkSetVectorMacro(name, type, count) \
1232 virtual void Set##name(type data[]) \
1235 for (i = 0; i < count; ++i) \
1237 ITK_GCC_PRAGMA_PUSH \
1238 ITK_GCC_SUPPRESS_Wfloat_equal \
1239 if (data[i] != this->m_##name[i]) \
1243 ITK_GCC_PRAGMA_POP \
1248 for (i = 0; i < count; ++i) \
1250 this->m_##name[i] = data[i]; \
1254 ITK_MACROEND_NOOP_STATEMENT
1260 #define itkGetVectorMacro(name, type, count) \
1261 virtual type * Get##name() const { return this->m_##name; } \
1262 ITK_MACROEND_NOOP_STATEMENT
1268 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel) ITK_MACROEND_NOOP_STATEMENT
1275 #define itkGPUKernelMacro(kernel) \
1279 ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1280 kernel() = delete; \
1281 ~kernel() = delete; \
1282 static const char * GetOpenCLSource(); \
1284 ITK_MACROEND_NOOP_STATEMENT
1287 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1288 static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); } \
1289 ITK_MACROEND_NOOP_STATEMENT
1293 #define itkPrintSelfObjectMacro(name) \
1294 if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1296 os << indent << #name << ": (null)" << std::endl; \
1300 os << indent << #name << ": " << std::endl; \
1301 this->m_##name->Print(os, indent.GetNextIndent()); \
1303 ITK_MACROEND_NOOP_STATEMENT
1307 #define itkSetDecoratedOutputMacro(name, type) \
1308 virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1310 itkDebugMacro("setting output " #name " to " << _arg); \
1311 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1313 this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1317 virtual void Set##name(const type & _arg) \
1319 using DecoratorType = SimpleDataObjectDecorator<type>; \
1320 itkDebugMacro("setting output " #name " to " << _arg); \
1321 DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1324 if (output->Get() == _arg) \
1330 output->Set(_arg); \
1335 auto newOutput = DecoratorType::New(); \
1336 newOutput->Set(_arg); \
1337 this->Set##name##Output(newOutput); \
1340 ITK_MACROEND_NOOP_STATEMENT
1344 #define itkGetDecoratedOutputMacro(name, type) \
1345 virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1347 itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1348 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1350 virtual const type & Get##name() const \
1352 itkDebugMacro("Getting output " #name); \
1353 using DecoratorType = SimpleDataObjectDecorator<type>; \
1354 const DecoratorType * output = \
1355 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1356 if (output == nullptr) \
1358 itkExceptionMacro("output" #name " is not set"); \
1360 return output->Get(); \
1362 ITK_MACROEND_NOOP_STATEMENT
1366 #define itkExceptionObject_h
1368 #undef itkExceptionObject_h
1377 template <
typename TTarget,
typename TSource>
1379 itkDynamicCastInDebugMode(TSource x)
1386 TTarget rval = dynamic_cast<TTarget>(x);
1387 if (rval ==
nullptr)
1389 itkGenericExceptionMacro(
"Failed dynamic cast to " <<
typeid(TTarget).name()
1390 <<
" object type = " << x->GetNameOfClass());
1394 return static_cast<TTarget>(x);
1399 #if __cplusplus >= 202002L
1400 # define ITK_NODISCARD(message) [[nodiscard(message)]]
1402 # define ITK_NODISCARD(message) [[nodiscard]]
1407 #if defined(ITK_LEGACY_REMOVE)
1408 # define itkExposeEnumValue(name) \
1409 static_assert(false, "ERROR: Replace static_cast<int>(name) with with proper enumeration instead of integer")
1411 # define ITK_NOEXCEPT_OR_THROW static_assert(false, "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT")
1413 # define ITK_DELETE_FUNCTION static_assert(false, "ERROR: ITK_DELETE_FUNCTION must be replaced with `= delete`"
1414 # define ITK_CONSTEXPR_FUNC static_assert(false, "ERROR: ITK_CONSTEXPR_FUNC must be replaced with 'constexpr'")
1415 # define ITK_CONSTEXPR_VAR static_assert(false, "ERROR: ITK_CONSTEXPR_VAR must be replaced with 'constexpr'")
1417 # define ITK_FALLTHROUGH static_assert(false, "ERROR: ITK_FALLTHROUGH must be replaced with '[[fallthrough]]'")
1420 # define ITK_ALIGNAS static_assert(false, "ERROR: ITK_ALIGNAS must be replaced with 'alignas'")
1421 # define ITK_ALIGNOF static_assert(false, "ERROR: ITK_ALIGNOF must be replaced with 'alignof'")
1422 # define ITK_DEPRECATED static_assert(false, "ERROR: ITK_DEPRECATED must be replaced with '[[deprecated]]'")
1423 # define ITK_DEPRECATED_MSG \
1424 static_assert(false, "ERROR: ITK_DEPRECATED_MSG must be replaced with '[[deprecated(MSG)]]'")
1425 # define ITK_CONSTEXPR static_assert(false, "ERROR: ITK_CONSTEXPR must be replaced with 'constexpr'")
1426 # define ITK_DELETED_FUNCTION static_assert(false, "ERROR: ITK_DELETED_FUNCTION must be replaced with '= delete'")
1427 # define ITK_EXTERN_TEMPLATE static_assert(false, "ERROR: ITK_EXTERN_TEMPLATE must be replaced with 'extern'")
1428 # define ITK_FINAL static_assert(false, "ERROR: ITK_FINAL must be replaced with 'final'")
1429 # define ITK_NOEXCEPT static_assert(false, "ERROR: ITK_NOEXCEPT must be replaced with 'noexcept'")
1430 # define ITK_NOEXCEPT_EXPR static_assert(false, "ERROR: ITK_NOEXCEPT_EXPR must be replaced with 'noexcept'")
1431 # define ITK_NULLPTR static_assert(false, "ERROR: ITK_NULLPTR must be replaced with 'nullptr'")
1432 # define ITK_OVERRIDE static_assert(false, "ERROR: ITK_OVERRIDE must be replaced with 'override'")
1433 # define ITK_STATIC_ASSERT static_assert(false, "ERROR: ITK_STATIC_ASSERT must be replaced with 'static_assert'")
1434 # define ITK_STATIC_ASSERT_MSG \
1435 static_assert(false, "ERROR: ITK_STATIC_ASSERT_MSG must be replaced with 'static_assert'")
1436 # define ITK_THREAD_LOCAL static_assert(false, "ERROR: ITK_THREAD_LOCAL must be replaced with 'thread_local'")
1439 # define ITKv5_CONST static_assert(false, "ERROR: ITKv5_CONST must be replaced with 'const'")
1441 # define ITK_ITERATOR_VIRTUAL static_assert(false, "ERROR: ITK_ITERATOR_VIRTUAL must be removed'")
1442 # define ITK_ITERATOR_OVERRIDE static_assert(false, "ERROR: ITK_ITERATOR_OVERRIDE must be removed")
1443 # define ITK_ITERATOR_FINAL static_assert(false, "ERROR: ITK_ITERATOR_FINAL must be removed")
1452 # define itkExposeEnumValue(name) static_cast<int>(name)
1455 # define ITK_NOEXCEPT_OR_THROW ITK_NOEXCEPT
1457 # define ITK_FALLTHROUGH [[fallthrough]]
1459 # define ITK_DELETE_FUNCTION = delete
1461 # define ITK_CONSTEXPR_FUNC constexpr
1462 # define ITK_CONSTEXPR_VAR constexpr
1465 # define ITK_ALIGNAS(X) alignas(X)
1466 # define ITK_ALIGNOF(X) alignof(X)
1467 # define ITK_DEPRECATED [[deprecated]]
1468 # define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1469 # define ITK_CONSTEXPR constexpr
1470 # define ITK_DELETED_FUNCTION = delete
1471 # define ITK_EXTERN_TEMPLATE extern
1472 # define ITK_FINAL final
1473 # define ITK_NOEXCEPT noexcept
1474 # define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1475 # define ITK_NULLPTR nullptr
1476 # define ITK_OVERRIDE override
1477 # define ITK_STATIC_ASSERT(X) static_assert(X, # X)
1478 # define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1479 # define ITK_THREAD_LOCAL thread_local
1482 # define ITKv5_CONST const
1484 # define ITK_ITERATOR_VIRTUAL
1485 # define ITK_ITERATOR_OVERRIDE
1486 # define ITK_ITERATOR_FINAL
1489 #endif // itkMacro_h