ITK  5.4.0
Insight Toolkit
itkMacro.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18/*=========================================================================
19 *
20 * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21 *
22 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23 *
24 * For complete copyright, license and disclaimer of warranty information
25 * please refer to the NOTICE file at the top of the ITK source tree.
26 *
27 *=========================================================================*/
38#ifndef itkMacro_h
39#define itkMacro_h
40
41#include "itkWin32Header.h"
42#include "itkConfigure.h"
43#include "ITKCommonExport.h"
44
45#include <typeinfo>
46
47#include <string>
48#include <cstdlib>
49#ifndef NDEBUG
50# include <cassert>
51# include "itkPrintHelper.h" // for ostream operator<<std::vector<T>
52#endif
53
54#include <sstream>
55#include <type_traits> // For is_same, remove_const, and remove_reference.
56
61namespace itk
62{
63// end namespace itk - this is here for documentation purposes
64}
65
68#define itkNotUsed(x)
69
70// clang-format off
71
81#define ITK_NOOP_STATEMENT static_assert(true, "")
82
83
84#if defined(ITK_FUTURE_LEGACY_REMOVE)
85
86# define ITK_MACROEND_NOOP_STATEMENT ITK_NOOP_STATEMENT
87#else
88/* NOTE: The ITK_MACROEND_NOOP_STATEMENT must be defined to nothing
89 * in order to maintain backwards compatibility with earlier macro
90 * uses that may or may not have ';' after the macro is used. */
91/* Purposefully empty */
92# define ITK_MACROEND_NOOP_STATEMENT
93#endif
94// clang-format on
95
96// Define ITK_PRAGMA macro.
97//
98// It sets "#pragma" preprocessor directives without expecting the arguments
99// to be quoted.
100#define ITK_PRAGMA(x) _Pragma(#x)
101
102// The GCC/Clang compilers have many useful non-default compiler warnings
103// that tend to have a high false positive rate or are otherwise not always appropriate.
104// The following set of defines allows us to suppress instances of said warnings.
105
106// For GCC and Clang (Clang also identifies itself as GCC, and supports these pragmas):
107#if defined(__GNUC__)
108# define ITK_GCC_PRAGMA_PUSH ITK_PRAGMA(GCC diagnostic push)
109# define ITK_GCC_PRAGMA_POP ITK_PRAGMA(GCC diagnostic pop)
110# define ITK_GCC_SUPPRESS_Wfloat_equal ITK_PRAGMA(GCC diagnostic ignored "-Wfloat-equal")
111# define ITK_GCC_SUPPRESS_Wformat_nonliteral ITK_PRAGMA(GCC diagnostic ignored "-Wformat-nonliteral")
112#else
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#endif
118
119// For Clang only (and not GCC):
120#if defined(__clang__) && defined(__has_warning)
121# define ITK_CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
122# define ITK_CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
123#else
124# define ITK_CLANG_PRAGMA_PUSH
125# define ITK_CLANG_PRAGMA_POP
126#endif
127
128// These were not intended as public API, but some code was nevertheless using them.
129// Support the pre ITK 5.4 spelling for compatibility.
130#define CLANG_PRAGMA_PUSH ITK_CLANG_PRAGMA_PUSH
131#define CLANG_PRAGMA_POP ITK_CLANG_PRAGMA_POP
132#define CLANG_SUPPRESS_Wfloat_equal ITK_GCC_SUPPRESS_Wfloat_equal
133
134#if !defined(ITK_LEGACY_REMOVE)
135// Issue warning if deprecated preprocessor flag is used.
136# define CLANG_SUPPRESS_Wcpp14_extensions \
137 [[deprecated("Remove deprecated CLANG_SUPPRESS_Wcpp14_extensions c++14 warning suppression")]] void * \
138 CLANG_SUPPRESS_Wcpp14_extensions = nullptr;
139#endif
140
141// Intel compiler convenience macros
142#if defined(__INTEL_COMPILER)
143# define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
144# define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
145# define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
146#else
147# define INTEL_PRAGMA_WARN_PUSH
148# define INTEL_PRAGMA_WARN_POP
149# define INTEL_SUPPRESS_warning_1292
150#endif
151
152// Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
153//
154// This macro sets a pragma diagnostic
155//
156// Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
157//
158// These macros respectively push and pop the diagnostic context
159//
160#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
161# define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
162# define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
163# define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
164#else
165# define ITK_GCC_PRAGMA_DIAG(x)
166# define ITK_GCC_PRAGMA_DIAG_PUSH()
167# define ITK_GCC_PRAGMA_DIAG_POP()
168#endif
169
170/*
171 * ITK only supports MSVC++ 14.2 and greater
172 * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
173 */
174#if defined(_MSC_VER) && (_MSC_VER < 1920)
175# error "MSVC versions before Visual Studio 2019 are not supported under ITKv5.4"
176#endif
177#if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
178# error "SUNPro C++ < 5.14.0 is not supported under ITKv5 and above"
179#endif
180#if defined(__CYGWIN__)
181# error "The Cygwin compiler is not supported in ITKv4 and above"
182#endif
183#if defined(__BORLANDC__)
184# error "The Borland C compiler is not supported in ITKv4 and above"
185#endif
186#if defined(__MWERKS__)
187# error "The MetroWerks compiler is not supported in ITKv4 and above"
188#endif
189#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7)
190# error "GCC < 7 is not supported under ITKv5.4"
191#endif
192#if defined(__sgi)
193// This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
194// TODO: At some future point, it may be necessary to
195// define a minimum __sgi version that will work.
196# error "The SGI compiler is not supported under ITKv4 and above"
197#endif
198#if defined(__APPLE__)
199# if defined(__clang__) && (__cplusplus < 201703L)
200# error "Apple LLVM compiling with a standard less than C++17 is not supported under ITKv5.4"
201# endif
202#elif defined(__clang__) && (__clang_major__ < 5)
203# error "Clang < 5 is not supported under ITKv5.4"
204#endif
205#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910)
206# error "Intel C++ < 19.1 is not supported under ITKv5.4"
207#endif
208
209// Setup symbol exports
210#if defined(_WIN32) || defined(WIN32)
211# define ITK_ABI_IMPORT __declspec(dllimport)
212# define ITK_ABI_EXPORT __declspec(dllexport)
213# define ITK_ABI_HIDDEN
214#else
215# ifdef __GNUC__
216# define ITK_ABI_IMPORT __attribute__((visibility("default")))
217# define ITK_ABI_EXPORT __attribute__((visibility("default")))
218# define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
219# else
220# define ITK_ABI_IMPORT
221# define ITK_ABI_EXPORT
222# define ITK_ABI_HIDDEN
223# endif
224#endif
225
226// Setup symbol exports
227#ifndef ITK_TEMPLATE_EXPORT
228# ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
229# define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
230# else
231# define ITK_TEMPLATE_EXPORT
232# endif
233#endif
234
235// Setup symbol exports
236#ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
237# define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
238#else
239# define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
240#endif
241
242#ifndef ITK_FORWARD_EXPORT
243// If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
244# if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
245 defined(USE_COMPILER_HIDDEN_VISIBILITY)
246# define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
247# else
248# define ITK_FORWARD_EXPORT
249# endif
250#endif
251
252
253//-*-*-*
254// The following deprecations should be removed in ITKV6 and later
255// NOTE DEPRECATED should be ITK_NOEXCEPT
256#define ITK_NOEXCEPT_OR_THROW error "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT"
257// NOTE DEPRECATED! should be ITK_COMPILER_CXX_STATIC_ASSERT
258#if !defined(ITK_LEGACY_REMOVE)
259# define ITK_DELETE_FUNCTION = delete
260#else
261# define ITK_DELETE_FUNCTION error "Replace ITK_DELETE_FUNCTION with = delete"
262#endif
263//-*-*-*
264
265// DEPRECATED: These macros are left here for compatibility with remote modules.
266// Once they have been removed from all known remote modules, this code should
267// be removed.
268#if defined(ITK_FUTURE_LEGACY_REMOVE)
269# define ITK_CONSTEXPR_FUNC "Replace ITK_CONSTEXPR_FUNC with constexpr"
270# define ITK_CONSTEXPR_VAR "Replace ITK_CONSTEXPR_VAR with constexpr"
272# define itkExposeEnumValue(name) static_cast<int>(name)
273// Future remove# define itkExposeEnumValue(name) "Replace type of " # name " with proper enumeration instead of
274// integer."
275#else
276# define ITK_CONSTEXPR_FUNC constexpr
277# define ITK_CONSTEXPR_VAR constexpr
278
280# define itkExposeEnumValue(name) static_cast<int>(name)
281#endif
282
283#if !defined(ITK_FUTURE_LEGACY_REMOVE)
284# define ITK_FALLTHROUGH [[fallthrough]]
285#else
286# define ITK_FALLTHROUGH static_assert(false, "ERROR: ITK_FALLTHROUGH must be replaced with [[fallthrough]]")
287#endif
288
309#define itkNewMacro(x) \
310 itkSimpleNewMacro(x); \
311 itkCreateAnotherMacro(x); \
312 itkCloneMacro(x); \
313 ITK_MACROEND_NOOP_STATEMENT
316#define itkSimpleNewMacro(x) \
317 static Pointer New() \
318 { \
319 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
320 if (smartPtr == nullptr) \
321 { \
322 smartPtr = new x(); \
323 } \
324 smartPtr->UnRegister(); \
325 return smartPtr; \
326 } \
327 ITK_MACROEND_NOOP_STATEMENT
328
329#define itkCreateAnotherMacro(x) \
330 ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
331 ITK_MACROEND_NOOP_STATEMENT
332
333#define itkCloneMacro(x) \
334 Pointer Clone() const \
335 { \
336 Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
337 return rval; \
338 } \
339 ITK_MACROEND_NOOP_STATEMENT
340
344#define itkFactoryOnlyNewMacro(x) \
345 itkSimpleFactoryOnlyNewMacro(x); \
346 itkCreateAnotherMacro(x); \
347 itkCloneMacro(x); \
348 ITK_MACROEND_NOOP_STATEMENT
351#define itkSimpleFactoryOnlyNewMacro(x) \
352 static auto New()->Pointer \
353 { \
354 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
355 if (smartPtr == nullptr) \
356 { \
357 itkSpecializedMessageExceptionMacro(ExceptionObject, \
358 "Object factory failed to instantiate " << typeid(x).name()); \
359 } \
360 smartPtr->UnRegister(); \
361 return smartPtr; \
362 } \
363 ITK_MACROEND_NOOP_STATEMENT
364
377#define itkFactorylessNewMacro(x) \
378 static Pointer New() \
379 { \
380 x * rawPtr = new x(); \
381 Pointer smartPtr = rawPtr; \
382 rawPtr->UnRegister(); \
383 return smartPtr; \
384 } \
385 itkCreateAnotherMacro(x); \
386 ITK_MACROEND_NOOP_STATEMENT
389//
390// A macro to disallow the copy constructor, copy assignment,
391// move constructor, and move assignment functions.
392// This should be used in the public: declarations for a class
393//
394// ITK's paradigm for smart pointer and pipeline consistency
395// prohibits the use of copy/move construction and copy/move assignment
396// functions.
397//
398#define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
399 TypeName(const TypeName &) = delete; \
400 TypeName & operator=(const TypeName &) = delete; \
401 TypeName(TypeName &&) = delete; \
402 TypeName & operator=(TypeName &&) = delete
403
404#if !defined(ITK_FUTURE_LEGACY_REMOVE)
405# define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
406#else
407# define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
408 static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
409#endif
410
411
419#define ITK_DEFAULT_COPY_AND_MOVE(TypeName) \
420 TypeName(const TypeName &) = default; \
421 TypeName & operator=(const TypeName &) = default; \
422 TypeName(TypeName &&) = default; \
423 TypeName & operator=(TypeName &&) = default
427// When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
428// the ability for operator!= to be rewritten automatically in terms of
429// operator==, as introduced with C++20. This macro is experimental. It may be
430// modified, renamed, or removed without backward compatibility support.
431#if __cplusplus >= 202002L
432# define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
433#endif
434
435// Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
436// is only for internal use within the implementation of ITK. It may be
437// modified, renamed, or removed without backward compatibility support.
438#ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
439// With C++20, operator!= is automatically rewritten in terms of the
440// corresponding operator==.
441# define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
442#else
443// For C++14 and C++17, this macro defines an operator!= member function that
444// just calls the corresponding operator== member function.
445# define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
446 bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
447 ITK_MACROEND_NOOP_STATEMENT
448#endif
449
450
451// Internal macro (not part of the public ITK API), used to implement `GetNameOfClass()` member functions.
452#define itkInternalGetNameOfClassImplementationMacro(thisClass) \
453 { \
454 static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
455 "The macro argument `" #thisClass \
456 "` appears incorrect! It should correspond with the name of this class!"); \
457 return #thisClass; \
458 } \
459 ITK_MACROEND_NOOP_STATEMENT
460
461
465#define itkVirtualGetNameOfClassMacro(thisClass) \
466 virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
467
468#define itkOverrideGetNameOfClassMacro(thisClass) \
469 const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
470
471#ifdef ITK_FUTURE_LEGACY_REMOVE
472# define itkTypeMacro(thisClass, superclass) \
473 static_assert(false, \
474 "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
475 "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
476# define itkTypeMacroNoParent(thisClass) \
477 static_assert(false, \
478 "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
479 "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
480#else
485# define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
486# define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
487#endif
488
489
490namespace itk
491{
498extern ITKCommon_EXPORT void
499OutputWindowDisplayText(const char *);
502extern ITKCommon_EXPORT void
503OutputWindowDisplayErrorText(const char *);
504
505extern ITKCommon_EXPORT void
506OutputWindowDisplayWarningText(const char *);
507
508extern ITKCommon_EXPORT void
509OutputWindowDisplayGenericOutputText(const char *);
510
511extern ITKCommon_EXPORT void
512OutputWindowDisplayDebugText(const char *);
513
514} // end namespace itk
515
516// The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
521#if defined(NDEBUG)
522# define itkDebugMacro(x) ITK_NOOP_STATEMENT
523# define itkDebugStatement(x) ITK_NOOP_STATEMENT
524#else
525# define itkDebugMacro(x) \
526 do \
527 { \
528 using namespace ::itk::print_helper; /* for ostream << std::vector<T> */ \
529 if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
530 { \
531 std::ostringstream itkmsg; \
532 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
533 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
534 ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
535 } \
536 } while (0)
539// The itkDebugStatement is to be used to protect code that is only
540// used in the itkDebugMacro
541# define itkDebugStatement(x) x
542#endif
543
547#define itkWarningMacro(x) \
548 do \
549 { \
550 if (::itk::Object::GetGlobalWarningDisplay()) \
551 { \
552 std::ostringstream itkmsg; \
553 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << '\n' \
554 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
555 ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
556 } \
557 } while (0)
560#define itkWarningStatement(x) x
561
562#if defined(ITK_CPP_FUNCTION)
563# if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
564# define ITK_LOCATION __FUNCSIG__
565# elif defined(__GNUC__)
566# define ITK_LOCATION __PRETTY_FUNCTION__
567# else
568# define ITK_LOCATION __FUNCTION__
569# endif
570#else
571# define ITK_LOCATION "unknown"
572#endif
573
574#define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
575 namespace itk \
576 { \
577 class newexcp : public parentexcp \
578 { \
579 public: \
580 /* default message provides backward compatibility for a given exception type */ \
581 static constexpr const char * const default_exception_message = whatmessage; \
582 /* Inherit the constructors from its base class. */ \
583 using parentexcp::parentexcp; \
584 itkOverrideGetNameOfClassMacro(newexcp); \
585 }; \
586 } \
587 ITK_MACROEND_NOOP_STATEMENT
588
589
590#define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
591 { \
592 std::ostringstream exceptionDescriptionOutputStringStream; \
593 exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
594 throw ::itk::ExceptionType( \
595 std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
596 } \
597 ITK_MACROEND_NOOP_STATEMENT
598
599#define itkSpecializedExceptionMacro(ExceptionType) \
600 itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
601
605#define itkExceptionMacro(x) \
606 itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
607
608#define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
609
610#define itkGenericOutputMacro(x) \
611 { \
612 if (::itk::Object::GetGlobalWarningDisplay()) \
613 { \
614 std::ostringstream itkmsg; \
615 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
616 ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
617 } \
618 } \
619 ITK_MACROEND_NOOP_STATEMENT
620
621//----------------------------------------------------------------------------
622// Macros for simplifying the use of logging
623//
624#define itkLogMacro(x, y) \
625 { \
626 if (this->GetLogger()) \
627 { \
628 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
629 } \
630 } \
631 ITK_MACROEND_NOOP_STATEMENT
632
633#define itkLogMacroStatic(obj, x, y) \
634 { \
635 if (obj->GetLogger()) \
636 { \
637 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
638 } \
639 } \
640 ITK_MACROEND_NOOP_STATEMENT
641
642//----------------------------------------------------------------------------
643// Setup legacy code policy.
644//
645// CMake options:
646// - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
647// - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
648// of legacy code will not produce compiler warnings.
649// - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
650// of legacy code will produce compiler warnings
651//
652// ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
653//
654// Source files that test the legacy code may define ITK_LEGACY_TEST
655// like this:
656//
657// #define ITK_LEGACY_TEST
658// #include "itkClassWithDeprecatedMethod.h"
659//
660// in order to silence the warnings for calling deprecated methods.
661// No other source files in ITK should call the methods since they are
662// provided only for compatibility with older user code.
663
664// Define itkLegacyMacro to mark legacy methods where they are
665// declared in their class. Example usage:
666//
667// // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
668// itkLegacyMacro(void MyMethod());
669//
670// See below for what to do for the method definition.
671#if defined(ITK_LEGACY_REMOVE)
672# define itkLegacyMacro(method) /* no ';' */
673#else
674# if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
675// Provide legacy methods with no warnings.
676# define itkLegacyMacro(method) method
677# else
678// Request compile-time warnings for uses of deprecated methods.
679# define itkLegacyMacro(method) [[deprecated]] method
680# endif
681#endif
682
683// Macros to create runtime deprecation warning messages in function
684// bodies. Example usage:
685//
686// #if !defined( ITK_LEGACY_REMOVE )
687// void itkMyClass::MyOldMethod()
688// {
689// itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
690// }
691//
692// void itkMyClass::MyMethod()
693// {
694// itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
695// itkMyClass::MyOtherMethod);
696// }
697// #endif
698//
699// NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
700// itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
701// are purposefully not defined when ITK_LEGACY_REMOVE is on,
702// because these macros are only relevant inside code segments
703// that are conditionally compiled only when ITK_LEGACY_REMOVE
704// is off.
705#if defined(ITK_LEGACY_SILENT)
706# define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
707# define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
708# define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
709# define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
710#else
711# define itkLegacyBodyMacro(method, version) \
712 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
713# define itkLegacyReplaceBodyMacro(method, version, replace) \
714 itkWarningMacro(#method " was deprecated for ITK " #version \
715 " and will be removed in a future version. Use " #replace " instead.")
716# define itkGenericLegacyBodyMacro(method, version) \
717 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
718# define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
719 itkGenericOutputMacro(#method " was deprecated for ITK " #version \
720 " and will be removed in a future version. Use " #replace " instead.")
721#endif
722
723// Most modern x86 CPUs have 64 byte aligned blocks which are used for
724// the cache lines. By aligning multi-threaded structures with the
725// cache lines, false shared can be reduced, and performance
726// increased.
727#define ITK_CACHE_LINE_ALIGNMENT 64
728
729//
730// itkPadStruct will add padding to a structure to ensure a minimum size
731// for ensuring that adjacent structures do not share CACHE lines.
732// Each struct will take up some multiple of cacheline sizes.
733// This is particularly useful for arrays of thread private variables.
734//
735#define itkPadStruct(mincachesize, oldtype, newtype) \
736 struct newtype : public oldtype \
737 { \
738 char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
739 };
740
741//
742// itkAlignedTypedef is a macro which creates a new type to make a
743// data structure aligned.
744//
745#if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
746# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
747#elif defined(_MSC_VER)
748# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
749#else
750# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
751#endif
752
753#if defined(ITK_FUTURE_LEGACY_REMOVE)
754//=============================================================================
755/*
756NOTE: DEPRECATED - This macro is not longer needed to support modern
757compilers.
758
759 Define a common way of declaring a templated function as a friend inside a class.
760 - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
761
762 The following templated function
763
764 template <T>
765 T add(const T & a, const T & b);
766
767 is declared as friend with
768
769 class A
770 {
771 public:
772 friend Self add<>( const Self & a, const Self & b );
773 }
774
775*/
776# define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
777#else // LEGACY_REMOVE
778# define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
779#endif
780
781//--------------------------------------------------------------------------------
782// Helper macros for Template Meta-Programming techniques of for-loops
783// unrolling
784//--------------------------------------------------------------------------------
785
786//--------------------------------------------------------------------------------
787// Macro that generates an unrolled for loop for assigning elements of one array
788// to elements of another array The array are assumed to be of same length
789// (dimension), and this is also assumed to be the value of NumberOfIterations.
790// No verification of size is performed. Casting is performed as part of the
791// assignment, by using the DestinationElementType as the casting type.
792// Source and destination array types must have defined operator[] in their
793// API.
794#define itkForLoopAssignmentMacro( \
795 DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
796 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
797 { \
798 DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
799 }
800
801//--------------------------------------------------------------------------------
802// Macro that generates an unrolled for loop for rounding and assigning
803// elements of one array to elements of another array The array are assumed to
804// be of same length (dimension), and this is also assumed to be the value of
805// NumberOfIterations. No verification of size is performed. Casting is
806// performed as part of the assignment, by using the DestinationElementType as
807// the casting type.
808// Source and destination array types must have defined operator[] in their
809// API.
810#define itkForLoopRoundingAndAssignmentMacro( \
811 DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
812 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
813 { \
814 DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
815 }
816
817// end of Template Meta Programming helper macros
818
819#if !defined(NDEBUG) && !defined(ITK_WRAPPING)
820
821# ifdef __GLIBC__
822# define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
823# else
824# define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
825# endif
826
827#else
828# define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
829#endif
830
831#define itkAssertOrThrowMacro(test, message) \
832 if (!(test)) \
833 { \
834 std::ostringstream msgstr; \
835 msgstr << message; \
836 itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
837 } \
838 ITK_MACROEND_NOOP_STATEMENT
839
840#if !defined(NDEBUG) && !defined(ITK_WRAPPING)
841# define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
842#else
843# define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
844#endif
845
846
847// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
848// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
849// !! The ITK Get/Set Macros for various types !!
850// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
851// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
852
853#ifdef ITK_FUTURE_LEGACY_REMOVE
854# define itkStaticConstMacro(name, type, value) \
855 "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
856# define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
857#else
872# define itkStaticConstMacro(name, type, value) static constexpr type name = value
873
874# define itkGetStaticConstMacro(name) (Self::name)
875#endif
876
878#define itkSetInputMacro(name, type) \
879 virtual void Set##name(const type * _arg) \
880 { \
881 itkDebugMacro("setting input " #name " to " << _arg); \
882 if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
883 { \
884 this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
885 this->Modified(); \
886 } \
887 } \
888 ITK_MACROEND_NOOP_STATEMENT
892#define itkGetInputMacro(name, type) \
893 virtual const type * Get##name() const \
894 { \
895 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
896 return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
897 } \
898 ITK_MACROEND_NOOP_STATEMENT
901// clang-format off
903#define itkSetDecoratedInputMacro(name, type) \
904 virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
905 { \
906 itkDebugMacro("setting input " #name " to " << _arg); \
907 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
908 { \
909 this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
910 this->Modified(); \
911 } \
912 } \
913 virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
914 virtual void Set##name(const type & _arg) \
915 { \
916 using DecoratorType = SimpleDataObjectDecorator<type>; \
917 itkDebugMacro("setting input " #name " to " << _arg); \
918 const DecoratorType * oldInput = \
919 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
920 ITK_GCC_PRAGMA_PUSH \
921 ITK_GCC_SUPPRESS_Wfloat_equal \
922 if (oldInput && oldInput->Get() == _arg) \
923 { \
924 return; \
925 } \
926 ITK_GCC_PRAGMA_POP \
927 auto newInput = DecoratorType::New(); \
928 newInput->Set(_arg); \
929 this->Set##name##Input(newInput); \
930 } \
931 ITK_MACROEND_NOOP_STATEMENT
932// clang-format on
936#define itkGetDecoratedInputMacro(name, type) \
937 virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
938 { \
939 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
940 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
941 } \
942 virtual const type & Get##name() const \
943 { \
944 itkDebugMacro("Getting input " #name); \
945 using DecoratorType = SimpleDataObjectDecorator<type>; \
946 const DecoratorType * input = \
947 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
948 if (input == nullptr) \
949 { \
950 itkExceptionMacro("input" #name " is not set"); \
951 } \
952 return input->Get(); \
953 } \
954 ITK_MACROEND_NOOP_STATEMENT
959#define itkSetGetDecoratedInputMacro(name, type) \
960 itkSetDecoratedInputMacro(name, type); \
961 itkGetDecoratedInputMacro(name, type)
962
967#define itkSetDecoratedObjectInputMacro(name, type) \
968 virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
969 { \
970 itkDebugMacro("setting input " #name " to " << _arg); \
971 if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
972 { \
973 this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
974 this->Modified(); \
975 } \
976 } \
977 virtual void Set##name(const type * _arg) \
978 { \
979 using DecoratorType = DataObjectDecorator<type>; \
980 itkDebugMacro("setting input " #name " to " << _arg); \
981 const DecoratorType * oldInput = \
982 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
983 if (oldInput && oldInput->Get() == _arg) \
984 { \
985 return; \
986 } \
987 auto newInput = DecoratorType::New(); \
988 newInput->Set(_arg); \
989 this->Set##name##Input(newInput); \
990 } \
991 ITK_MACROEND_NOOP_STATEMENT
998#define itkGetDecoratedObjectInputMacro(name, type) \
999 virtual const DataObjectDecorator<type> * Get##name##Input() const \
1000 { \
1001 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
1002 return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
1003 } \
1004 virtual const type * Get##name() const \
1005 { \
1006 itkDebugMacro("Getting input " #name); \
1007 using DecoratorType = DataObjectDecorator<type>; \
1008 const DecoratorType * input = \
1009 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
1010 if (input == nullptr) \
1011 { \
1012 return nullptr; \
1013 } \
1014 return input->Get(); \
1015 } \
1016 ITK_MACROEND_NOOP_STATEMENT
1021#define itkSetGetDecoratedObjectInputMacro(name, type) \
1022 itkSetDecoratedObjectInputMacro(name, type); \
1023 itkGetDecoratedObjectInputMacro(name, type)
1024
1026// clang-format off
1027#define itkSetMacro(name, type) \
1028 virtual void Set##name(type _arg) \
1029 { \
1030 itkDebugMacro("setting " #name " to " << _arg); \
1031 ITK_GCC_PRAGMA_PUSH \
1032 ITK_GCC_SUPPRESS_Wfloat_equal \
1033 if (this->m_##name != _arg) \
1034 { \
1035 this->m_##name = std::move(_arg); \
1036 this->Modified(); \
1037 } \
1038 ITK_GCC_PRAGMA_POP \
1039 } \
1040 ITK_MACROEND_NOOP_STATEMENT
1041// clang-format on
1042
1044#define itkGetMacro(name, type) \
1045 virtual type Get##name() { return this->m_##name; } \
1046 ITK_MACROEND_NOOP_STATEMENT
1052#define itkGetConstMacro(name, type) \
1053 virtual type Get##name() const { return this->m_##name; } \
1054 ITK_MACROEND_NOOP_STATEMENT
1061#define itkGetConstReferenceMacro(name, type) \
1062 virtual const type & Get##name() const { return this->m_##name; } \
1063 ITK_MACROEND_NOOP_STATEMENT
1070#define itkSetEnumMacro(name, type) \
1071 virtual void Set##name(const type _arg) \
1072 { \
1073 itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1074 if (this->m_##name != _arg) \
1075 { \
1076 this->m_##name = _arg; \
1077 this->Modified(); \
1078 } \
1079 } \
1080 ITK_MACROEND_NOOP_STATEMENT
1087#define itkGetEnumMacro(name, type) \
1088 virtual type Get##name() const { return this->m_##name; } \
1089 ITK_MACROEND_NOOP_STATEMENT
1095#define itkSetStringMacro(name) \
1096 virtual void Set##name(const char * _arg) \
1097 { \
1098 if (_arg && (_arg == this->m_##name)) \
1099 { \
1100 return; \
1101 } \
1102 if (_arg) \
1103 { \
1104 this->m_##name = _arg; \
1105 } \
1106 else \
1107 { \
1108 this->m_##name = ""; \
1109 } \
1110 this->Modified(); \
1111 } \
1112 virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1113 ITK_MACROEND_NOOP_STATEMENT
1120#define itkGetStringMacro(name) \
1121 virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1122 ITK_MACROEND_NOOP_STATEMENT
1123
1124// clang-format off
1128#define itkSetClampMacro(name, type, min, max) \
1129 virtual void Set##name(type _arg) \
1130 { \
1131 const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1132 itkDebugMacro("setting " << #name " to " << _arg); \
1133 ITK_GCC_PRAGMA_PUSH \
1134 ITK_GCC_SUPPRESS_Wfloat_equal \
1135 if (this->m_##name != temp_extrema) \
1136 { \
1137 this->m_##name = temp_extrema; \
1138 this->Modified(); \
1139 } \
1140 ITK_GCC_PRAGMA_POP \
1141 } \
1142 ITK_MACROEND_NOOP_STATEMENT
1143// clang-format on
1146// clang-format off
1150#define itkSetObjectMacro(name, type) \
1151 virtual void Set##name(type * _arg) \
1152 { \
1153 itkDebugMacro("setting " << #name " to " << _arg); \
1154 if (this->m_##name != _arg) \
1155 { \
1156 this->m_##name = _arg; \
1157 this->Modified(); \
1158 } \
1159 } \
1160 ITK_MACROEND_NOOP_STATEMENT
1161// clang-format on
1172// NOTE: A class can use either itkGetModifiableObjectMacro
1173// or itkGetObjectMacro, but not both.
1174// A class can use either itkGetModifiableObjectMacro
1175// or itkGetConstObjectMacro, but not both.
1176// If the desired behavior is to only provide const
1177// access to the itkObject ivar, then use itkGetConstObjectMacro,
1178// else use itkGetModifiableObjectMacro for read/write access to
1179// the ivar.
1180// It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1181// for backwards compatibility.
1182// If the ITK_LEGACY_REMOVE=FALSE, then it is
1183// permissible to use itkGetObjectMacro which
1184// defines both signatures itk::GetXXX() and
1185// itk::GetModifiableXXX()
1186
1189#define itkGetConstObjectMacro(name, type) \
1190 virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1191 ITK_MACROEND_NOOP_STATEMENT
1192
1193
1194#if defined(ITK_FUTURE_LEGACY_REMOVE)
1195// In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1196// flag. For now, this very advanced feature is only available
1197// through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1198// ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1199// to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1200# define itkGetObjectMacro(name, type) \
1201 virtual type * Get##name() \
1202 { \
1203 purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1204 }
1205
1206# define itkGetModifiableObjectMacro(name, type) \
1207 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1208 itkGetConstObjectMacro(name, type)
1209
1210#else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1213# define itkGetObjectMacro(name, type) \
1214 virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1215 ITK_MACROEND_NOOP_STATEMENT
1216# define itkGetModifiableObjectMacro(name, type) \
1217 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1218 itkGetConstObjectMacro(name, type); \
1219 itkGetObjectMacro(name, type)
1220#endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1223// For backwards compatibility define ITK_EXPORT to nothing
1224#define ITK_EXPORT
1225
1226
1229#define itkGetConstReferenceObjectMacro(name, type) \
1230 virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1231 ITK_MACROEND_NOOP_STATEMENT
1232
1236#define itkSetConstObjectMacro(name, type) \
1237 virtual void Set##name(const type * _arg) \
1238 { \
1239 itkDebugMacro("setting " << #name " to " << _arg); \
1240 if (this->m_##name != _arg) \
1241 { \
1242 this->m_##name = _arg; \
1243 this->Modified(); \
1244 } \
1245 } \
1246 ITK_MACROEND_NOOP_STATEMENT
1251#define itkBooleanMacro(name) \
1252 virtual void name##On() { this->Set##name(true); } \
1253 virtual void name##Off() { this->Set##name(false); }
1256// clang-format off
1260#define itkSetVectorMacro(name, type, count) \
1261 virtual void Set##name(type data[]) \
1262 { \
1263 unsigned int i; \
1264 for (i = 0; i < count; ++i) \
1265 { \
1266 ITK_GCC_PRAGMA_PUSH \
1267 ITK_GCC_SUPPRESS_Wfloat_equal \
1268 if (data[i] != this->m_##name[i]) \
1269 { \
1270 break; \
1271 } \
1272 ITK_GCC_PRAGMA_POP \
1273 } \
1274 if (i < count) \
1275 { \
1276 this->Modified(); \
1277 for (i = 0; i < count; ++i) \
1278 { \
1279 this->m_##name[i] = data[i]; \
1280 } \
1281 } \
1282 } \
1283 ITK_MACROEND_NOOP_STATEMENT
1284// clang-format on
1289#define itkGetVectorMacro(name, type, count) \
1290 virtual type * Get##name() const { return this->m_##name; } \
1291 ITK_MACROEND_NOOP_STATEMENT
1292
1297#define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1298
1304#define itkGPUKernelMacro(kernel) \
1305 kernel \
1306 { \
1307 public: \
1308 ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1309 kernel() = delete; \
1310 ~kernel() = delete; \
1311 static const char * GetOpenCLSource(); \
1312 }
1315#define itkGetOpenCLSourceFromKernelMacro(kernel) \
1316 static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); }
1317
1318// A useful macro in the PrintSelf method for printing member variables
1319// which are pointers to object based on the LightObject class.
1320#define itkPrintSelfObjectMacro(name) \
1321 if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1322 { \
1323 os << indent << #name << ": (null)" << std::endl; \
1324 } \
1325 else \
1326 { \
1327 os << indent << #name << ": " << std::endl; \
1328 this->m_##name->Print(os, indent.GetNextIndent()); \
1329 } \
1330 ITK_MACROEND_NOOP_STATEMENT
1331
1332
1334#define itkSetDecoratedOutputMacro(name, type) \
1335 virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1336 { \
1337 itkDebugMacro("setting output " #name " to " << _arg); \
1338 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1339 { \
1340 this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1341 this->Modified(); \
1342 } \
1343 } \
1344 virtual void Set##name(const type & _arg) \
1345 { \
1346 using DecoratorType = SimpleDataObjectDecorator<type>; \
1347 itkDebugMacro("setting output " #name " to " << _arg); \
1348 DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1349 if (output) \
1350 { \
1351 if (output->Get() == _arg) \
1352 { \
1353 return; \
1354 } \
1355 else \
1356 { \
1357 output->Set(_arg); \
1358 } \
1359 } \
1360 else \
1361 { \
1362 auto newOutput = DecoratorType::New(); \
1363 newOutput->Set(_arg); \
1364 this->Set##name##Output(newOutput); \
1365 } \
1366 } \
1367 ITK_MACROEND_NOOP_STATEMENT
1371#define itkGetDecoratedOutputMacro(name, type) \
1372 virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1373 { \
1374 itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1375 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1376 } \
1377 virtual const type & Get##name() const \
1378 { \
1379 itkDebugMacro("Getting output " #name); \
1380 using DecoratorType = SimpleDataObjectDecorator<type>; \
1381 const DecoratorType * output = \
1382 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1383 if (output == nullptr) \
1384 { \
1385 itkExceptionMacro("output" #name " is not set"); \
1386 } \
1387 return output->Get(); \
1388 } \
1389 ITK_MACROEND_NOOP_STATEMENT
1402#if defined(ITKV4_COMPATIBILITY)
1403# define ITK_ITERATOR_VIRTUAL virtual
1404# define ITK_ITERATOR_OVERRIDE override
1405# define ITK_ITERATOR_FINAL
1406#elif !defined(ITK_LEGACY_REMOVE)
1407# define ITK_ITERATOR_VIRTUAL virtual
1408# define ITK_ITERATOR_OVERRIDE override
1409# define ITK_ITERATOR_FINAL final
1410#else
1411# define ITK_ITERATOR_VIRTUAL
1412# define ITK_ITERATOR_OVERRIDE
1413# define ITK_ITERATOR_FINAL
1414#endif
1415
1416#if defined(ITKV4_COMPATIBILITY)
1417// A macro for methods which are const in ITKv5, but not in ITKv4
1418# define ITKv5_CONST
1419#else
1420// A macro for methods which are const in ITKv5, but not in ITKv4
1421# define ITKv5_CONST const
1422#endif
1423
1424#define itkExceptionObject_h
1425#include "itkExceptionObject.h"
1426#undef itkExceptionObject_h
1427
1435template <typename TTarget, typename TSource>
1436TTarget
1437itkDynamicCastInDebugMode(TSource x)
1438{
1439#ifndef NDEBUG
1440 if (x == nullptr)
1441 {
1442 return nullptr;
1443 }
1444 TTarget rval = dynamic_cast<TTarget>(x);
1445 if (rval == nullptr)
1446 {
1447 itkGenericExceptionMacro("Failed dynamic cast to " << typeid(TTarget).name()
1448 << " object type = " << x->GetNameOfClass());
1449 }
1450 return rval;
1451#else
1452 return static_cast<TTarget>(x);
1453#endif
1454}
1457#ifdef ITK_LEGACY_REMOVE
1458# if __cplusplus >= 202002L
1459# define ITK_NODISCARD(message) [[nodiscard(message)]]
1460# else
1461# define ITK_NODISCARD(message) [[nodiscard]]
1462# endif
1463#else
1464# define ITK_NODISCARD(message)
1465#endif
1466
1467// Defines which used to be in itk_compiler_detection.h
1468#define ITK_ALIGNAS(X) alignas(X)
1469#define ITK_ALIGNOF(X) alignof(X)
1470#define ITK_DEPRECATED [[deprecated]]
1471#define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1472#define ITK_CONSTEXPR constexpr
1473#define ITK_DELETED_FUNCTION = delete
1474#define ITK_EXTERN_TEMPLATE extern
1475#define ITK_FINAL final
1476#define ITK_NOEXCEPT noexcept
1477#define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1478#define ITK_NULLPTR nullptr
1479#define ITK_OVERRIDE override
1480#define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1481#define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1482#define ITK_THREAD_LOCAL thread_local
1483
1484#endif // end of itkMacro.h
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....