ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 *=========================================================================*/
37
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#endif
52
53#include <sstream>
54#include <type_traits> // For is_same, remove_const, and remove_reference.
55
60namespace itk
61{
62// end namespace itk - this is here for documentation purposes
63}
64
67#define itkNotUsed(x)
68
69// clang-format off
80#define ITK_NOOP_STATEMENT static_assert(true, "")
81
82/* NOTE: The ITK_MACROEND_NOOP_STATEMENT is used at the end
83 * of ITK supported macros to ensure that when the macro
84 * is used in the code base that the line must have ';' after
85 * the macro is used. This makes formatting visually similar
86 * to functions, and greatly improves the clang-format
87 * behaviors for indentation. This also assists
88 * modern IDE's and removes 1000's of warnings about
89 * unused statements or unnecessary ';' when macros are
90 * used. */
91#define ITK_MACROEND_NOOP_STATEMENT ITK_NOOP_STATEMENT
92// clang-format on
93
94// Define ITK_PRAGMA macro.
95//
96// It sets "#pragma" preprocessor directives without expecting the arguments
97// to be quoted.
98#define ITK_PRAGMA(x) _Pragma(#x)
99
100// The GCC/Clang compilers have many useful non-default compiler warnings
101// that tend to have a high false positive rate or are otherwise not always appropriate.
102// The following set of defines allows us to suppress instances of said warnings.
103
104// For GCC and Clang (Clang also identifies itself as GCC, and supports these pragmas):
105#if defined(__GNUC__)
106# define ITK_GCC_PRAGMA_PUSH ITK_PRAGMA(GCC diagnostic push)
107# define ITK_GCC_PRAGMA_POP ITK_PRAGMA(GCC diagnostic pop)
108# define ITK_GCC_SUPPRESS_Wfloat_equal ITK_PRAGMA(GCC diagnostic ignored "-Wfloat-equal")
109# define ITK_GCC_SUPPRESS_Wformat_nonliteral ITK_PRAGMA(GCC diagnostic ignored "-Wformat-nonliteral")
110# define ITK_GCC_SUPPRESS_Warray_bounds ITK_PRAGMA(GCC diagnostic ignored "-Warray-bounds")
111#else
112# define ITK_GCC_PRAGMA_PUSH
113# define ITK_GCC_PRAGMA_POP
114# define ITK_GCC_SUPPRESS_Wfloat_equal
115# define ITK_GCC_SUPPRESS_Wformat_nonliteral
116# define ITK_GCC_SUPPRESS_Warray_bounds
117#endif
118
119// -Wmaybe-uninitialized is a real-GCC-only warning name; Apple Clang emits
120// -Wunknown-warning-option for it (which ITK's dashboard treats as fatal).
121#if defined(__GNUC__) && !defined(__clang__)
122# define ITK_GCC_SUPPRESS_Wmaybe_uninitialized ITK_PRAGMA(GCC diagnostic ignored "-Wmaybe-uninitialized")
123#else
124# define ITK_GCC_SUPPRESS_Wmaybe_uninitialized
125#endif
126
127// For Clang only (and not GCC):
128#if defined(__clang__) && defined(__has_warning)
129# define ITK_CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
130# define ITK_CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
131# if __has_warning("-Wzero-as-null-pointer-constant")
132# define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant \
133 ITK_PRAGMA(clang diagnostic ignored "-Wzero-as-null-pointer-constant")
134# else
135# define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant
136# endif
137# if __has_warning("-Wduplicate-enum")
138# define ITK_CLANG_SUPPRESS_Wduplicate_enum ITK_PRAGMA(clang diagnostic ignored "-Wduplicate-enum")
139# else
140# define ITK_CLANG_SUPPRESS_Wduplicate_enum
141# endif
142#else
143# define ITK_CLANG_PRAGMA_PUSH
144# define ITK_CLANG_PRAGMA_POP
145# define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant
146# define ITK_CLANG_SUPPRESS_Wduplicate_enum
147#endif
148
149// These were not intended as public API, but some code was nevertheless using them.
150// Support the pre ITK 5.4 spelling for compatibility.
151#define CLANG_PRAGMA_PUSH ITK_CLANG_PRAGMA_PUSH
152#define CLANG_PRAGMA_POP ITK_CLANG_PRAGMA_POP
153#define CLANG_SUPPRESS_Wfloat_equal ITK_GCC_SUPPRESS_Wfloat_equal
154
155// For GCC/Clang, to decorate printf-like functions allowing for compiler checks of format strings.
156#if defined(__GNUC__)
157# define ITK_FORMAT_PRINTF(a, b) __attribute__((format(printf, a, b)))
158#else
159# define ITK_FORMAT_PRINTF(a, b)
160#endif
161
162#if !defined(ITK_LEGACY_REMOVE)
163// Issue warning if deprecated preprocessor flag is used.
164# define CLANG_SUPPRESS_Wcpp14_extensions \
165 [[deprecated("Remove deprecated CLANG_SUPPRESS_Wcpp14_extensions c++14 warning suppression")]] void * \
166 CLANG_SUPPRESS_Wcpp14_extensions = nullptr;
167#endif
168
169// Intel compiler convenience macros
170#if defined(__INTEL_COMPILER)
171# define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
172# define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
173# define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
174#else
175# define INTEL_PRAGMA_WARN_PUSH
176# define INTEL_PRAGMA_WARN_POP
177# define INTEL_SUPPRESS_warning_1292
178#endif
179
180// Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
181//
182// This macro sets a pragma diagnostic
183//
184// Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
185//
186// These macros respectively push and pop the diagnostic context
187//
188#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
189# define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
190# define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
191# define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
192#else
193# define ITK_GCC_PRAGMA_DIAG(x)
194# define ITK_GCC_PRAGMA_DIAG_PUSH()
195# define ITK_GCC_PRAGMA_DIAG_POP()
196#endif
197
198/*
199 * ITK only supports MSVC++ 14.2 and greater
200 * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
201 */
202#if defined(_MSC_VER) && (_MSC_VER < 1920)
203# error "MSVC versions before Visual Studio 2019 are not supported"
204#endif
205#if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
206# error "SUNPro C++ < 5.14.0 is not supported"
207#endif
208#if defined(__CYGWIN__)
209# error "The Cygwin compiler is not supported"
210#endif
211#if defined(__BORLANDC__)
212# error "The Borland C compiler is not supported"
213#endif
214#if defined(__MWERKS__)
215# error "The MetroWerks compiler is not supported"
216#endif
217#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7)
218# error "GCC < 7 is not supported"
219#endif
220#if defined(__sgi)
221// This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
222// TODO: At some future point, it may be necessary to
223// define a minimum __sgi version that will work.
224# error "The SGI compiler is not supported"
225#endif
226#if defined(__apple_build_version__) && (__apple_build_version__ < 12000032)
227# error "AppleClang < Xcode 12.4 is not supported"
228#elif defined(__clang__) && (__clang_major__ < 5)
229# error "Clang < 5 is not supported"
230#endif
231#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910)
232# error "Intel C++ < 19.1 is not supported4"
233#endif
234
235// Setup symbol exports
236#if defined(_WIN32) || defined(WIN32)
237# define ITK_ABI_IMPORT __declspec(dllimport)
238# define ITK_ABI_EXPORT __declspec(dllexport)
239# define ITK_ABI_HIDDEN
240#else
241# ifdef __GNUC__
242# define ITK_ABI_IMPORT __attribute__((visibility("default")))
243# define ITK_ABI_EXPORT __attribute__((visibility("default")))
244# define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
245# else
246# define ITK_ABI_IMPORT
247# define ITK_ABI_EXPORT
248# define ITK_ABI_HIDDEN
249# endif
250#endif
251
252// Setup symbol exports
253#ifndef ITK_TEMPLATE_EXPORT
254# ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
255# define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
256# else
257# define ITK_TEMPLATE_EXPORT
258# endif
259#endif
260
261// Setup symbol exports
262#ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
263# define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
264#else
265# define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
266#endif
267
268#ifndef ITK_FORWARD_EXPORT
269// If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
270# if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
271 defined(USE_COMPILER_HIDDEN_VISIBILITY)
272# define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
273# else
274# define ITK_FORWARD_EXPORT
275# endif
276#endif
277
278
300#define itkNewMacro(x) \
301 itkSimpleNewMacro(x); \
302 itkCreateAnotherMacro(x); \
303 itkCloneMacro(x); \
304 ITK_MACROEND_NOOP_STATEMENT
306#define itkSimpleNewMacro(x) \
307 static Pointer New() \
308 { \
309 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
310 if (smartPtr == nullptr) \
311 { \
312 smartPtr = new x(); \
313 } \
314 smartPtr->UnRegister(); \
315 return smartPtr; \
316 } \
317 ITK_MACROEND_NOOP_STATEMENT
318
319#define itkCreateAnotherMacro(x) \
320 ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
321 ITK_MACROEND_NOOP_STATEMENT
322
323#define itkCloneMacro(x) \
324 Pointer Clone() const \
325 { \
326 Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
327 return rval; \
328 } \
329 ITK_MACROEND_NOOP_STATEMENT
330
335#define itkFactoryOnlyNewMacro(x) \
336 itkSimpleFactoryOnlyNewMacro(x); \
337 itkCreateAnotherMacro(x); \
338 itkCloneMacro(x); \
339 ITK_MACROEND_NOOP_STATEMENT
341#define itkSimpleFactoryOnlyNewMacro(x) \
342 static auto New() -> Pointer \
343 { \
344 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
345 if (smartPtr == nullptr) \
346 { \
347 itkSpecializedMessageExceptionMacro(ExceptionObject, \
348 "Object factory failed to instantiate " << typeid(x).name()); \
349 } \
350 smartPtr->UnRegister(); \
351 return smartPtr; \
352 } \
353 ITK_MACROEND_NOOP_STATEMENT
354
368#define itkFactorylessNewMacro(x) \
369 static Pointer New() \
370 { \
371 auto * rawPtr = new x(); \
372 Pointer smartPtr = rawPtr; \
373 rawPtr->UnRegister(); \
374 return smartPtr; \
375 } \
376 itkCreateAnotherMacro(x); \
377 ITK_MACROEND_NOOP_STATEMENT
379//
380// A macro to disallow the copy constructor, copy assignment,
381// move constructor, and move assignment functions.
382// This should be used in the public: declarations for a class
383//
384// ITK's paradigm for smart pointer and pipeline consistency
385// prohibits the use of copy/move construction and copy/move assignment
386// functions.
387//
388#define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
389 TypeName(const TypeName &) = delete; \
390 TypeName & operator=(const TypeName &) = delete; \
391 TypeName(TypeName &&) = delete; \
392 TypeName & operator=(TypeName &&) = delete
393
394#if !defined(ITK_LEGACY_REMOVE)
395# define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
396#else
397# define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
398 static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
399#endif
400
401
410#define ITK_DEFAULT_COPY_AND_MOVE(TypeName) \
411 TypeName(const TypeName &) = default; \
412 TypeName & operator=(const TypeName &) = default; \
413 TypeName(TypeName &&) = default; \
414 TypeName & operator=(TypeName &&) = default
416
417// When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
418// the ability for operator!= to be rewritten automatically in terms of
419// operator==, as introduced with C++20. This macro is experimental. It may be
420// modified, renamed, or removed without backward compatibility support.
421#if __cplusplus >= 202002L
422# define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
423#endif
424
425// Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
426// is only for internal use within the implementation of ITK. It may be
427// modified, renamed, or removed without backward compatibility support.
428#ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
429// With C++20, operator!= is automatically rewritten in terms of the
430// corresponding operator==.
431# define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
432#else
433// For C++14 and C++17, this macro defines an operator!= member function that
434// just calls the corresponding operator== member function.
435# define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
436 bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
437 ITK_MACROEND_NOOP_STATEMENT
438#endif
439
440
441// Internal macro (not part of the public ITK API), used to implement `GetNameOfClass()` member functions.
442#define itkInternalGetNameOfClassImplementationMacro(thisClass) \
443 { \
444 static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
445 "The macro argument `" #thisClass \
446 "` appears incorrect! It should correspond with the name of this class!"); \
447 return #thisClass; \
448 } \
449 ITK_MACROEND_NOOP_STATEMENT
450
451
455#define itkVirtualGetNameOfClassMacro(thisClass) \
456 virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
457
458#define itkOverrideGetNameOfClassMacro(thisClass) \
459 const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
460
461#ifdef ITK_FUTURE_LEGACY_REMOVE
462# define itkTypeMacro(thisClass, superclass) \
463 static_assert(false, \
464 "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
465 "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
466# define itkTypeMacroNoParent(thisClass) \
467 static_assert(false, \
468 "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
469 "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
470#else
475# define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
476# define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
477#endif
478
479
480namespace itk
481{
489#ifndef ITK_FUTURE_LEGACY_REMOVE
490extern ITKCommon_EXPORT void
491OutputWindowDisplayText(const char *);
492
493extern ITKCommon_EXPORT void
494OutputWindowDisplayErrorText(const char *);
495
496extern ITKCommon_EXPORT void
497OutputWindowDisplayWarningText(const char *);
498
499extern ITKCommon_EXPORT void
500OutputWindowDisplayGenericOutputText(const char *);
501
502extern ITKCommon_EXPORT void
503OutputWindowDisplayDebugText(const char *);
504#endif
505
506// New context-aware versions of output display functions
507extern ITKCommon_EXPORT void
508OutputWindowDisplayDebugText(const char * file,
509 unsigned int line,
510 const char * className,
511 const void * objectAddress,
512 const char * message);
513
514extern ITKCommon_EXPORT void
515OutputWindowDisplayWarningText(const char * file,
516 unsigned int line,
517 const char * className,
518 const void * objectAddress,
519 const char * message);
520
521extern ITKCommon_EXPORT void
522OutputWindowDisplayErrorText(const char * file,
523 unsigned int line,
524 const char * className,
525 const void * objectAddress,
526 const char * message);
527
528extern ITKCommon_EXPORT void
529OutputWindowDisplayGenericOutputText(const char * file, unsigned int line, const char * message);
531
532} // end namespace itk
533
534// The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
540#if defined(NDEBUG)
541# define itkDebugMacro(x) ITK_NOOP_STATEMENT
542# define itkDebugStatement(x) ITK_NOOP_STATEMENT
543#else
544# define itkDebugMacro(x) \
545 { \
546 using namespace ::itk::print_helper; /* for ostream << std::vector<T> */ \
547 if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
548 { \
549 std::ostringstream itkmsg; \
550 itkmsg << "" x; \
551 ::itk::OutputWindowDisplayDebugText(__FILE__, __LINE__, this->GetNameOfClass(), this, itkmsg.str().c_str()); \
552 } \
553 } \
554 ITK_MACROEND_NOOP_STATEMENT
555// The itkDebugStatement is to be used to protect code that is only
556// used in the itkDebugMacro
557# define itkDebugStatement(x) x
558#endif
563#define itkWarningMacro(x) \
564 { \
565 if (::itk::Object::GetGlobalWarningDisplay()) \
566 { \
567 std::ostringstream itkmsg; \
568 itkmsg << "" x; \
569 ::itk::OutputWindowDisplayWarningText(__FILE__, __LINE__, this->GetNameOfClass(), this, itkmsg.str().c_str()); \
570 } \
571 } \
572 ITK_MACROEND_NOOP_STATEMENT
573
574
575#define itkWarningStatement(x) x
576
577#if defined(ITK_CPP_FUNCTION)
578# if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
579# define ITK_LOCATION __FUNCSIG__
580# elif defined(__GNUC__)
581# define ITK_LOCATION __PRETTY_FUNCTION__
582# else
583# define ITK_LOCATION __FUNCTION__
584# endif
585#else
586# define ITK_LOCATION "unknown"
587#endif
588
589#define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
590 namespace itk \
591 { \
592 class newexcp : public parentexcp \
593 { \
594 public: \
595 /* default message provides backward compatibility for a given exception type */ \
596 static constexpr const char * const default_exception_message = whatmessage; \
597 /* Inherit the constructors from its base class. */ \
598 using parentexcp::parentexcp; \
599 itkOverrideGetNameOfClassMacro(newexcp); \
600 }; \
601 } \
602 ITK_MACROEND_NOOP_STATEMENT
603
604
605#define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
606 { \
607 std::ostringstream exceptionDescriptionOutputStringStream; \
608 exceptionDescriptionOutputStringStream << "" x; \
609 throw ::itk::ExceptionType( \
610 std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
611 } \
612 ITK_MACROEND_NOOP_STATEMENT
613
614#define itkSpecializedExceptionMacro(ExceptionType) \
615 throw ::itk::ExceptionType( \
616 std::string{ __FILE__ }, __LINE__, ::itk::ExceptionType::default_exception_message, std::string{ ITK_LOCATION });
617
618
622#define itkExceptionMacro(x) \
623 { \
624 std::ostringstream exceptionDescriptionOutputStringStream; \
625 exceptionDescriptionOutputStringStream << "" x; \
626 throw ::itk::ExceptionObject(std::string{ __FILE__ }, \
627 __LINE__, \
628 exceptionDescriptionOutputStringStream.str(), \
629 std::string{ ITK_LOCATION }, \
630 this); \
631 } \
632 ITK_MACROEND_NOOP_STATEMENT
633
634#define itkExceptionStringMacro(x) \
635 { \
636 throw ::itk::ExceptionObject( \
637 std::string{ __FILE__ }, __LINE__, std::string{ x }, std::string{ ITK_LOCATION }, this); \
638 } \
639 ITK_MACROEND_NOOP_STATEMENT
640
641#define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
642
643#define itkGenericOutputMacro(x) \
644 { \
645 if (::itk::Object::GetGlobalWarningDisplay()) \
646 { \
647 std::ostringstream itkmsg; \
648 itkmsg << "" x; \
649 ::itk::OutputWindowDisplayGenericOutputText(__FILE__, __LINE__, itkmsg.str().c_str()); \
650 } \
651 } \
652 ITK_MACROEND_NOOP_STATEMENT
653
654//----------------------------------------------------------------------------
655// Macros for simplifying the use of logging
656//
657#define itkLogMacro(x, y) \
658 { \
659 if (this->GetLogger()) \
660 { \
661 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
662 } \
663 } \
664 ITK_MACROEND_NOOP_STATEMENT
665
666#define itkLogMacroStatic(obj, x, y) \
667 { \
668 if (obj->GetLogger()) \
669 { \
670 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
671 } \
672 } \
673 ITK_MACROEND_NOOP_STATEMENT
674
675//----------------------------------------------------------------------------
676// Setup legacy code policy.
677//
678// CMake options:
679// - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
680// - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
681// of legacy code will not produce compiler warnings.
682// - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
683// of legacy code will produce compiler warnings
684//
685// ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
686//
687// Source files that test the legacy code may define ITK_LEGACY_TEST
688// like this:
689//
690// #define ITK_LEGACY_TEST
691// #include "itkClassWithDeprecatedMethod.h"
692//
693// in order to silence the warnings for calling deprecated methods.
694// No other source files in ITK should call the methods since they are
695// provided only for compatibility with older user code.
696
697// Define itkLegacyMacro to mark legacy methods where they are
698// declared in their class. Example usage:
699//
700// // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
701// itkLegacyMacro(void MyMethod();)
702//
703// See below for what to do for the method definition.
704#if defined(ITK_LEGACY_REMOVE)
705# define itkLegacyMacro(method) /* no ';' */
706#else
707# if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
708// Provide legacy methods with no warnings.
709# define itkLegacyMacro(method) method /* no ';' */
710# else
711// Request compile-time warnings for uses of deprecated methods.
712# define itkLegacyMacro(method) [[deprecated]] method /* no ';' */
713# endif
714#endif
715
716// Macros to create runtime deprecation warning messages in function
717// bodies. Example usage:
718//
719// #if !defined( ITK_LEGACY_REMOVE )
720// void itkMyClass::MyOldMethod()
721// {
722// itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
723// }
724//
725// void itkMyClass::MyMethod()
726// {
727// itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
728// itkMyClass::MyOtherMethod);
729// }
730// #endif
731//
732// NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
733// itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
734// are purposefully not defined when ITK_LEGACY_REMOVE is on,
735// because these macros are only relevant inside code segments
736// that are conditionally compiled only when ITK_LEGACY_REMOVE
737// is off.
738#if defined(ITK_LEGACY_SILENT)
739# define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
740# define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
741# define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
742# define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
743#else
744# define itkLegacyBodyMacro(method, version) \
745 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
746# define itkLegacyReplaceBodyMacro(method, version, replace) \
747 itkWarningMacro(#method " was deprecated for ITK " #version \
748 " and will be removed in a future version. Use " #replace " instead.")
749# define itkGenericLegacyBodyMacro(method, version) \
750 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
751# define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
752 itkGenericOutputMacro(#method " was deprecated for ITK " #version \
753 " and will be removed in a future version. Use " #replace " instead.")
754#endif
755
756// Most modern x86 CPUs have 64 byte aligned blocks which are used for
757// the cache lines. By aligning multi-threaded structures with the
758// cache lines, false shared can be reduced, and performance
759// increased.
760constexpr size_t ITK_CACHE_LINE_ALIGNMENT{ 64 };
761
762//
763// itkPadStruct will add padding to a structure to ensure a minimum size
764// for ensuring that adjacent structures do not share CACHE lines.
765// Each struct will take up some multiple of cacheline sizes.
766// This is particularly useful for arrays of thread private variables.
767//
768#define itkPadStruct(mincachesize, oldtype, newtype) \
769 struct newtype : public oldtype \
770 { \
771 char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
772 }
773
774//
775// itkAlignedTypedef is a macro which creates a new type to make a
776// data structure aligned.
777//
778#if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
779# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
780#elif defined(_MSC_VER)
781# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
782#else
783# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
784#endif
785
786#if defined(ITK_FUTURE_LEGACY_REMOVE)
787//=============================================================================
788/*
789NOTE: DEPRECATED - This macro is not longer needed to support modern
790compilers.
791
792 Define a common way of declaring a templated function as a friend inside a class.
793 - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
794
795 The following templated function
796
797 template <T>
798 T add(const T & a, const T & b);
799
800 is declared as friend with
801
802 class A
803 {
804 public:
805 friend Self add<>( const Self & a, const Self & b );
806 }
807
808*/
809# define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
810#else // LEGACY_REMOVE
811# define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
812#endif
813
814//--------------------------------------------------------------------------------
815// Helper macros for Template Meta-Programming techniques of for-loops
816// unrolling
817//--------------------------------------------------------------------------------
818
819//--------------------------------------------------------------------------------
820// Macro that generates an unrolled for loop for assigning elements of one array
821// to elements of another array The array are assumed to be of same length
822// (dimension), and this is also assumed to be the value of NumberOfIterations.
823// No verification of size is performed. Casting is performed as part of the
824// assignment, by using the DestinationElementType as the casting type.
825// Source and destination array types must have defined operator[] in their
826// API.
827#define itkForLoopAssignmentMacro( \
828 DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
829 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
830 { \
831 DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
832 } \
833 ITK_MACROEND_NOOP_STATEMENT
834
835//--------------------------------------------------------------------------------
836// Macro that generates an unrolled for loop for rounding and assigning
837// elements of one array to elements of another array The array are assumed to
838// be of same length (dimension), and this is also assumed to be the value of
839// NumberOfIterations. No verification of size is performed. Casting is
840// performed as part of the assignment, by using the DestinationElementType as
841// the casting type.
842// Source and destination array types must have defined operator[] in their
843// API.
844#define itkForLoopRoundingAndAssignmentMacro( \
845 DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
846 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
847 { \
848 DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
849 } \
850 ITK_MACROEND_NOOP_STATEMENT
851
852// end of Template Meta Programming helper macros
853
854#if !defined(NDEBUG) && !defined(ITK_WRAPPING)
855
856# ifdef __GLIBC__
857# define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
858# else
859# define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
860# endif
861
862#else
863# define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
864#endif
865
866#define itkAssertOrThrowMacro(test, message) \
867 if (!(test)) \
868 { \
869 std::ostringstream msgstr; \
870 msgstr << message; \
871 itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
872 } \
873 ITK_MACROEND_NOOP_STATEMENT
874
875#if !defined(NDEBUG) && !defined(ITK_WRAPPING)
876# define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
877#else
878# define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
879#endif
880
881
882// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
883// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
884// !! The ITK Get/Set Macros for various types !!
885// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
886// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
887
888#ifdef ITK_FUTURE_LEGACY_REMOVE
889# define itkStaticConstMacro(name, type, value) \
890 "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
891# define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
892#else
907# define itkStaticConstMacro(name, type, value) static constexpr type name = value
908
909# define itkGetStaticConstMacro(name) (Self::name)
910#endif
911
912// Set an input. This defines the Set"name"() method. Implementation detail; use the public wrappers below.
913#define ITK_DETAIL_SetInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
914 virtualKeyword void Set##name(const type * _arg) finalKeyword \
915 { \
916 itkDebugMacro("setting input " #name " to " << _arg); \
917 if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
918 { \
919 this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
920 this->Modified(); \
921 } \
922 } \
923 ITK_MACROEND_NOOP_STATEMENT
924
927#define itkVirtualSetInputMacro(name, type) ITK_DETAIL_SetInputMacroImpl(virtual, , name, type)
928#define itkFinalSetInputMacro(name, type) ITK_DETAIL_SetInputMacroImpl(, final, name, type)
929#define itkNonVirtualSetInputMacro(name, type) ITK_DETAIL_SetInputMacroImpl(, , name, type)
930#define itkSetInputMacro(name, type) ITK_DETAIL_SetInputMacroImpl(virtual, , name, type)
932
933// Get an input. This defines the Get"name"() method. Implementation detail; use the public wrappers below.
934#define ITK_DETAIL_GetInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
935 virtualKeyword const type * Get##name() const finalKeyword \
936 { \
937 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
938 return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
939 } \
940 ITK_MACROEND_NOOP_STATEMENT
941
944#define itkVirtualGetInputMacro(name, type) ITK_DETAIL_GetInputMacroImpl(virtual, , name, type)
945#define itkFinalGetInputMacro(name, type) ITK_DETAIL_GetInputMacroImpl(, final, name, type)
946#define itkNonVirtualGetInputMacro(name, type) ITK_DETAIL_GetInputMacroImpl(, , name, type)
947#define itkGetInputMacro(name, type) ITK_DETAIL_GetInputMacroImpl(virtual, , name, type)
949
950// clang-format off
951// Set a decorated input. Defines Set"name"Input(), Set"name"(decorator*) and Set"name"(value). Implementation detail; use the public wrappers below.
952#define ITK_DETAIL_SetDecoratedInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
953 virtualKeyword void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) finalKeyword \
954 { \
955 itkDebugMacro("setting input " #name " to " << _arg); \
956 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
957 { \
958 this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
959 this->Modified(); \
960 } \
961 } \
962 virtualKeyword void Set##name(const SimpleDataObjectDecorator<type> * _arg) finalKeyword \
963 { \
964 this->Set##name##Input(_arg); \
965 } \
966 virtualKeyword void Set##name(const type & _arg) finalKeyword \
967 { \
968 using DecoratorType = SimpleDataObjectDecorator<type>; \
969 itkDebugMacro("setting input " #name " to " << _arg); \
970 const DecoratorType * oldInput = \
971 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
972 ITK_GCC_PRAGMA_PUSH \
973 ITK_GCC_SUPPRESS_Wfloat_equal \
974 if (oldInput && oldInput->Get() == _arg) \
975 { \
976 return; \
977 } \
978 ITK_GCC_PRAGMA_POP \
979 auto newInput = DecoratorType::New(); \
980 newInput->Set(_arg); \
981 this->Set##name##Input(newInput); \
982 } \
983 ITK_MACROEND_NOOP_STATEMENT
984// clang-format on
985
988#define itkVirtualSetDecoratedInputMacro(name, type) ITK_DETAIL_SetDecoratedInputMacroImpl(virtual, , name, type)
989#define itkFinalSetDecoratedInputMacro(name, type) ITK_DETAIL_SetDecoratedInputMacroImpl(, final, name, type)
990#define itkNonVirtualSetDecoratedInputMacro(name, type) ITK_DETAIL_SetDecoratedInputMacroImpl(, , name, type)
991#define itkSetDecoratedInputMacro(name, type) ITK_DETAIL_SetDecoratedInputMacroImpl(virtual, , name, type)
993
994// Get a decorated input. Defines Get"name"Input() and Get"name"(). Implementation detail; use the public wrappers
995// below.
996#define ITK_DETAIL_GetDecoratedInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
997 virtualKeyword const SimpleDataObjectDecorator<type> * Get##name##Input() const finalKeyword \
998 { \
999 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
1000 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
1001 } \
1002 virtualKeyword const type & Get##name() const finalKeyword \
1003 { \
1004 itkDebugMacro("Getting input " #name); \
1005 using DecoratorType = SimpleDataObjectDecorator<type>; \
1006 const DecoratorType * input = \
1007 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
1008 if (input == nullptr) \
1009 { \
1010 itkExceptionStringMacro("input" #name " is not set"); \
1011 } \
1012 return input->Get(); \
1013 } \
1014 ITK_MACROEND_NOOP_STATEMENT
1015
1018#define itkVirtualGetDecoratedInputMacro(name, type) ITK_DETAIL_GetDecoratedInputMacroImpl(virtual, , name, type)
1019#define itkFinalGetDecoratedInputMacro(name, type) ITK_DETAIL_GetDecoratedInputMacroImpl(, final, name, type)
1020#define itkNonVirtualGetDecoratedInputMacro(name, type) ITK_DETAIL_GetDecoratedInputMacroImpl(, , name, type)
1021#define itkGetDecoratedInputMacro(name, type) ITK_DETAIL_GetDecoratedInputMacroImpl(virtual, , name, type)
1023
1026#define itkVirtualSetGetDecoratedInputMacro(name, type) \
1027 itkVirtualSetDecoratedInputMacro(name, type); \
1028 itkVirtualGetDecoratedInputMacro(name, type)
1029#define itkFinalSetGetDecoratedInputMacro(name, type) \
1030 itkFinalSetDecoratedInputMacro(name, type); \
1031 itkFinalGetDecoratedInputMacro(name, type)
1032#define itkNonVirtualSetGetDecoratedInputMacro(name, type) \
1033 itkNonVirtualSetDecoratedInputMacro(name, type); \
1034 itkNonVirtualGetDecoratedInputMacro(name, type)
1035#define itkSetGetDecoratedInputMacro(name, type) \
1036 itkSetDecoratedInputMacro(name, type); \
1037 itkGetDecoratedInputMacro(name, type)
1039
1040// Set a decorated itk::Object-derived (non-DataObject) input. Defines Set"name"() and Set"name"Input().
1041// Implementation detail; use the public wrappers below.
1042#define ITK_DETAIL_SetDecoratedObjectInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
1043 virtualKeyword void Set##name##Input(const DataObjectDecorator<type> * _arg) finalKeyword \
1044 { \
1045 itkDebugMacro("setting input " #name " to " << _arg); \
1046 if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
1047 { \
1048 this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
1049 this->Modified(); \
1050 } \
1051 } \
1052 virtualKeyword void Set##name(const type * _arg) finalKeyword \
1053 { \
1054 using DecoratorType = DataObjectDecorator<type>; \
1055 itkDebugMacro("setting input " #name " to " << _arg); \
1056 const DecoratorType * oldInput = \
1057 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
1058 if (oldInput && oldInput->Get() == _arg) \
1059 { \
1060 return; \
1061 } \
1062 auto newInput = DecoratorType::New(); \
1063 newInput->Set(_arg); \
1064 this->Set##name##Input(newInput); \
1065 } \
1066 ITK_MACROEND_NOOP_STATEMENT
1067
1071#define itkVirtualSetDecoratedObjectInputMacro(name, type) \
1072 ITK_DETAIL_SetDecoratedObjectInputMacroImpl(virtual, , name, type)
1073#define itkFinalSetDecoratedObjectInputMacro(name, type) \
1074 ITK_DETAIL_SetDecoratedObjectInputMacroImpl(, final, name, type)
1075#define itkNonVirtualSetDecoratedObjectInputMacro(name, type) \
1076 ITK_DETAIL_SetDecoratedObjectInputMacroImpl(, , name, type)
1077#define itkSetDecoratedObjectInputMacro(name, type) ITK_DETAIL_SetDecoratedObjectInputMacroImpl(virtual, , name, type)
1079
1080// Get a decorated itk::Object-derived (non-DataObject) input. Defines Get"name"() and Get"name"Input().
1081// Implementation detail; use the public wrappers below.
1082#define ITK_DETAIL_GetDecoratedObjectInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
1083 virtualKeyword const DataObjectDecorator<type> * Get##name##Input() const finalKeyword \
1084 { \
1085 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
1086 return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
1087 } \
1088 virtualKeyword const type * Get##name() const finalKeyword \
1089 { \
1090 itkDebugMacro("Getting input " #name); \
1091 using DecoratorType = DataObjectDecorator<type>; \
1092 const DecoratorType * input = \
1093 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
1094 if (input == nullptr) \
1095 { \
1096 return nullptr; \
1097 } \
1098 return input->Get(); \
1099 } \
1100 ITK_MACROEND_NOOP_STATEMENT
1101
1105#define itkVirtualGetDecoratedObjectInputMacro(name, type) \
1106 ITK_DETAIL_GetDecoratedObjectInputMacroImpl(virtual, , name, type)
1107#define itkFinalGetDecoratedObjectInputMacro(name, type) \
1108 ITK_DETAIL_GetDecoratedObjectInputMacroImpl(, final, name, type)
1109#define itkNonVirtualGetDecoratedObjectInputMacro(name, type) \
1110 ITK_DETAIL_GetDecoratedObjectInputMacroImpl(, , name, type)
1111#define itkGetDecoratedObjectInputMacro(name, type) ITK_DETAIL_GetDecoratedObjectInputMacroImpl(virtual, , name, type)
1113
1116#define itkVirtualSetGetDecoratedObjectInputMacro(name, type) \
1117 itkVirtualSetDecoratedObjectInputMacro(name, type); \
1118 itkVirtualGetDecoratedObjectInputMacro(name, type)
1119#define itkFinalSetGetDecoratedObjectInputMacro(name, type) \
1120 itkFinalSetDecoratedObjectInputMacro(name, type); \
1121 itkFinalGetDecoratedObjectInputMacro(name, type)
1122#define itkNonVirtualSetGetDecoratedObjectInputMacro(name, type) \
1123 itkNonVirtualSetDecoratedObjectInputMacro(name, type); \
1124 itkNonVirtualGetDecoratedObjectInputMacro(name, type)
1125#define itkSetGetDecoratedObjectInputMacro(name, type) \
1126 itkSetDecoratedObjectInputMacro(name, type); \
1127 itkGetDecoratedObjectInputMacro(name, type)
1129
1130// Internal Set/Get macro bodies parametrized by the C++ virtual-specifier
1131// (`virtual`) and the trailing virt-specifier (`final`); at most one of
1132// `virtualKeyword`/`finalKeyword` is non-empty. Public variants below:
1133// itkVirtual*, itkFinal*, itkNonVirtual*; legacy itk*Macro forms remain
1134// `virtual` for ABI-stability through ITK v7. No `itkOverride*` variants:
1135// inherit the base member, or write the function by hand when an override
1136// genuinely needs different behavior. Implementation detail; use the public
1137// wrappers below.
1138// clang-format off
1139// Do not invoke ITK_DETAIL_SetMacroImpl directly from user code; use the public wrappers below.
1140#define ITK_DETAIL_SetMacroImpl(virtualKeyword, finalKeyword, name, type) \
1141 virtualKeyword void Set##name(type _arg) finalKeyword \
1142 { \
1143 itkDebugMacro("setting " #name " to " << _arg); \
1144 ITK_GCC_PRAGMA_PUSH \
1145 ITK_GCC_SUPPRESS_Wfloat_equal \
1146 if (this->m_##name != _arg) \
1147 { \
1148 this->m_##name = std::move(_arg); \
1149 this->Modified(); \
1150 } \
1151 ITK_GCC_PRAGMA_POP \
1152 } \
1153 ITK_MACROEND_NOOP_STATEMENT
1154// clang-format on
1155
1156// Do not invoke ITK_DETAIL_GetMacroImpl directly from user code; use the public wrappers below.
1157#define ITK_DETAIL_GetMacroImpl(virtualKeyword, finalKeyword, name, type) \
1158 virtualKeyword type Get##name() finalKeyword { return this->m_##name; } \
1159 ITK_MACROEND_NOOP_STATEMENT
1160
1161// Do not invoke ITK_DETAIL_GetConstMacroImpl directly from user code; use the public wrappers below.
1162#define ITK_DETAIL_GetConstMacroImpl(virtualKeyword, finalKeyword, name, type) \
1163 virtualKeyword type Get##name() const finalKeyword { return this->m_##name; } \
1164 ITK_MACROEND_NOOP_STATEMENT
1165
1166// Do not invoke ITK_DETAIL_GetConstReferenceMacroImpl directly from user code; use the public wrappers below.
1167#define ITK_DETAIL_GetConstReferenceMacroImpl(virtualKeyword, finalKeyword, name, type) \
1168 virtualKeyword const type & Get##name() const finalKeyword { return this->m_##name; } \
1169 ITK_MACROEND_NOOP_STATEMENT
1170
1173#define itkVirtualSetMacro(name, type) ITK_DETAIL_SetMacroImpl(virtual, , name, type)
1174#define itkFinalSetMacro(name, type) ITK_DETAIL_SetMacroImpl(, final, name, type)
1175#define itkNonVirtualSetMacro(name, type) ITK_DETAIL_SetMacroImpl(, , name, type)
1176#define itkSetMacro(name, type) ITK_DETAIL_SetMacroImpl(virtual, , name, type)
1178
1181#define itkVirtualGetMacro(name, type) ITK_DETAIL_GetMacroImpl(virtual, , name, type)
1182#define itkFinalGetMacro(name, type) ITK_DETAIL_GetMacroImpl(, final, name, type)
1183#define itkNonVirtualGetMacro(name, type) ITK_DETAIL_GetMacroImpl(, , name, type)
1184#define itkGetMacro(name, type) ITK_DETAIL_GetMacroImpl(virtual, , name, type)
1186
1191#define itkVirtualGetConstMacro(name, type) ITK_DETAIL_GetConstMacroImpl(virtual, , name, type)
1192#define itkFinalGetConstMacro(name, type) ITK_DETAIL_GetConstMacroImpl(, final, name, type)
1193#define itkNonVirtualGetConstMacro(name, type) ITK_DETAIL_GetConstMacroImpl(, , name, type)
1194#define itkGetConstMacro(name, type) ITK_DETAIL_GetConstMacroImpl(virtual, , name, type)
1196
1202#define itkVirtualGetConstReferenceMacro(name, type) ITK_DETAIL_GetConstReferenceMacroImpl(virtual, , name, type)
1203#define itkFinalGetConstReferenceMacro(name, type) ITK_DETAIL_GetConstReferenceMacroImpl(, final, name, type)
1204#define itkNonVirtualGetConstReferenceMacro(name, type) ITK_DETAIL_GetConstReferenceMacroImpl(, , name, type)
1205#define itkGetConstReferenceMacro(name, type) ITK_DETAIL_GetConstReferenceMacroImpl(virtual, , name, type)
1207// Set an enum-typed member. Creates Set"name"(); avoids itkDebugMacro warnings
1208// on some compilers with non-specified enum types. Implementation detail; use the public wrappers below.
1209#define ITK_DETAIL_SetEnumMacroImpl(virtualKeyword, finalKeyword, name, type) \
1210 virtualKeyword void Set##name(const type _arg) finalKeyword \
1211 { \
1212 itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1213 if (this->m_##name != _arg) \
1214 { \
1215 this->m_##name = _arg; \
1216 this->Modified(); \
1217 } \
1218 } \
1219 ITK_MACROEND_NOOP_STATEMENT
1220
1225#define itkVirtualSetEnumMacro(name, type) ITK_DETAIL_SetEnumMacroImpl(virtual, , name, type)
1226#define itkFinalSetEnumMacro(name, type) ITK_DETAIL_SetEnumMacroImpl(, final, name, type)
1227#define itkNonVirtualSetEnumMacro(name, type) ITK_DETAIL_SetEnumMacroImpl(, , name, type)
1228#define itkSetEnumMacro(name, type) ITK_DETAIL_SetEnumMacroImpl(virtual, , name, type)
1230
1231// Get an enum-typed member. Creates Get"name"(). Implementation detail; use the public wrappers below.
1232#define ITK_DETAIL_GetEnumMacroImpl(virtualKeyword, finalKeyword, name, type) \
1233 virtualKeyword type Get##name() const finalKeyword { return this->m_##name; } \
1234 ITK_MACROEND_NOOP_STATEMENT
1235
1239#define itkVirtualGetEnumMacro(name, type) ITK_DETAIL_GetEnumMacroImpl(virtual, , name, type)
1240#define itkFinalGetEnumMacro(name, type) ITK_DETAIL_GetEnumMacroImpl(, final, name, type)
1241#define itkNonVirtualGetEnumMacro(name, type) ITK_DETAIL_GetEnumMacroImpl(, , name, type)
1242#define itkGetEnumMacro(name, type) ITK_DETAIL_GetEnumMacroImpl(virtual, , name, type)
1244
1245// Set a std::string member from char*/std::string. Creates Set"name"(). Implementation detail; use the public wrappers
1246// below.
1247#define ITK_DETAIL_SetStringMacroImpl(virtualKeyword, finalKeyword, name) \
1248 virtualKeyword void Set##name(const char * _arg) finalKeyword \
1249 { \
1250 if (_arg && (_arg == this->m_##name)) \
1251 { \
1252 return; \
1253 } \
1254 if (_arg) \
1255 { \
1256 this->m_##name = _arg; \
1257 } \
1258 else \
1259 { \
1260 this->m_##name = ""; \
1261 } \
1262 this->Modified(); \
1263 } \
1264 virtualKeyword void Set##name(const std::string & _arg) finalKeyword { this->Set##name(_arg.c_str()); } \
1265 ITK_MACROEND_NOOP_STATEMENT
1266
1270#define itkVirtualSetStringMacro(name) ITK_DETAIL_SetStringMacroImpl(virtual, , name)
1271#define itkFinalSetStringMacro(name) ITK_DETAIL_SetStringMacroImpl(, final, name)
1272#define itkNonVirtualSetStringMacro(name) ITK_DETAIL_SetStringMacroImpl(, , name)
1273#define itkSetStringMacro(name) ITK_DETAIL_SetStringMacroImpl(virtual, , name)
1275
1276// Get a std::string member as const char*. Creates Get"name"(). Implementation detail; use the public wrappers below.
1277#define ITK_DETAIL_GetStringMacroImpl(virtualKeyword, finalKeyword, name) \
1278 virtualKeyword const char * Get##name() const finalKeyword { return this->m_##name.c_str(); } \
1279 ITK_MACROEND_NOOP_STATEMENT
1280
1284#define itkVirtualGetStringMacro(name) ITK_DETAIL_GetStringMacroImpl(virtual, , name)
1285#define itkFinalGetStringMacro(name) ITK_DETAIL_GetStringMacroImpl(, final, name)
1286#define itkNonVirtualGetStringMacro(name) ITK_DETAIL_GetStringMacroImpl(, , name)
1287#define itkGetStringMacro(name) ITK_DETAIL_GetStringMacroImpl(virtual, , name)
1289
1290// clang-format off
1291// Set a value constrained between min/max limits. Creates Set"name"(). Implementation detail; use the public wrappers below.
1292#define ITK_DETAIL_SetClampMacroImpl(virtualKeyword, finalKeyword, name, type, min, max) \
1293 virtualKeyword void Set##name(type _arg) finalKeyword \
1294 { \
1295 const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1296 itkDebugMacro("setting " << #name " to " << _arg); \
1297 ITK_GCC_PRAGMA_PUSH \
1298 ITK_GCC_SUPPRESS_Wfloat_equal \
1299 if (this->m_##name != temp_extrema) \
1300 { \
1301 this->m_##name = temp_extrema; \
1302 this->Modified(); \
1303 } \
1304 ITK_GCC_PRAGMA_POP \
1305 } \
1306 ITK_MACROEND_NOOP_STATEMENT
1307// clang-format on
1308
1312#define itkVirtualSetClampMacro(name, type, min, max) ITK_DETAIL_SetClampMacroImpl(virtual, , name, type, min, max)
1313#define itkFinalSetClampMacro(name, type, min, max) ITK_DETAIL_SetClampMacroImpl(, final, name, type, min, max)
1314#define itkNonVirtualSetClampMacro(name, type, min, max) ITK_DETAIL_SetClampMacroImpl(, , name, type, min, max)
1315#define itkSetClampMacro(name, type, min, max) ITK_DETAIL_SetClampMacroImpl(virtual, , name, type, min, max)
1317
1318// Set object pointer (Object reference-counted). Creates Set"name"(). Implementation detail; use the public wrappers
1319// below.
1320#define ITK_DETAIL_SetObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1321 virtualKeyword void Set##name(type * _arg) finalKeyword \
1322 { \
1323 itkDebugMacro("setting " << #name " to " << _arg); \
1324 if (this->m_##name != _arg) \
1325 { \
1326 this->m_##name = _arg; \
1327 this->Modified(); \
1328 } \
1329 } \
1330 ITK_MACROEND_NOOP_STATEMENT
1331
1335#define itkVirtualSetObjectMacro(name, type) ITK_DETAIL_SetObjectMacroImpl(virtual, , name, type)
1336#define itkFinalSetObjectMacro(name, type) ITK_DETAIL_SetObjectMacroImpl(, final, name, type)
1337#define itkNonVirtualSetObjectMacro(name, type) ITK_DETAIL_SetObjectMacroImpl(, , name, type)
1338#define itkSetObjectMacro(name, type) ITK_DETAIL_SetObjectMacroImpl(virtual, , name, type)
1340// NOTE: A class can use either itkGetModifiableObjectMacro
1341// or itkGetObjectMacro, but not both.
1342// A class can use either itkGetModifiableObjectMacro
1343// or itkGetConstObjectMacro, but not both.
1344// If the desired behavior is to only provide const
1345// access to the itkObject ivar, then use itkGetConstObjectMacro,
1346// else use itkGetModifiableObjectMacro for read/write access to
1347// the ivar.
1348// It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1349// for backwards compatibility.
1350// If the ITK_LEGACY_REMOVE=FALSE, then it is
1351// permissible to use itkGetObjectMacro which
1352// defines both signatures itk::GetXXX() and
1353// itk::GetModifiableXXX()
1354
1355// Get a raw const pointer to an object. Creates Get"name"(). Implementation detail; use the public wrappers below.
1356#define ITK_DETAIL_GetConstObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1357 virtualKeyword const type * Get##name() const finalKeyword { return this->m_##name.GetPointer(); } \
1358 ITK_MACROEND_NOOP_STATEMENT
1359
1363#define itkVirtualGetConstObjectMacro(name, type) ITK_DETAIL_GetConstObjectMacroImpl(virtual, , name, type)
1364#define itkFinalGetConstObjectMacro(name, type) ITK_DETAIL_GetConstObjectMacroImpl(, final, name, type)
1365#define itkNonVirtualGetConstObjectMacro(name, type) ITK_DETAIL_GetConstObjectMacroImpl(, , name, type)
1366#define itkGetConstObjectMacro(name, type) ITK_DETAIL_GetConstObjectMacroImpl(virtual, , name, type)
1368
1369// ITK_DETAIL_GetObjectMacroImpl / ITK_DETAIL_GetModifiableObjectMacroImpl are
1370// implementation details; use the public wrappers below.
1371#if defined(ITK_FUTURE_LEGACY_REMOVE)
1372// In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1373// flag. For now, this very advanced feature is only available
1374// through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1375// ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1376// to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1377// Do not invoke ITK_DETAIL_GetObjectMacroImpl directly from user code; use the public wrappers below.
1378# define ITK_DETAIL_GetObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1379 virtualKeyword type * Get##name() finalKeyword \
1380 { \
1381 purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1382 } \
1383 ITK_MACROEND_NOOP_STATEMENT
1384
1385// Do not invoke ITK_DETAIL_GetModifiableObjectMacroImpl directly from user code; use the public wrappers below.
1386# define ITK_DETAIL_GetModifiableObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1387 virtualKeyword type * GetModifiable##name() finalKeyword { return this->m_##name.GetPointer(); } \
1388 ITK_DETAIL_GetConstObjectMacroImpl(virtualKeyword, finalKeyword, name, type)
1389
1390#else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1391// Get a raw pointer to an object. Creates Get"name"(). Implementation detail; use the public wrappers below.
1392# define ITK_DETAIL_GetObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1393 virtualKeyword type * Get##name() finalKeyword { return this->m_##name.GetPointer(); } \
1394 ITK_MACROEND_NOOP_STATEMENT
1395
1396// Do not invoke ITK_DETAIL_GetModifiableObjectMacroImpl directly from user code; use the public wrappers below.
1397# define ITK_DETAIL_GetModifiableObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1398 virtualKeyword type * GetModifiable##name() finalKeyword { return this->m_##name.GetPointer(); } \
1399 ITK_DETAIL_GetConstObjectMacroImpl(virtualKeyword, finalKeyword, name, type); \
1400 ITK_DETAIL_GetObjectMacroImpl(virtualKeyword, finalKeyword, name, type)
1401#endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1402
1408#define itkVirtualGetObjectMacro(name, type) ITK_DETAIL_GetObjectMacroImpl(virtual, , name, type)
1409#define itkFinalGetObjectMacro(name, type) ITK_DETAIL_GetObjectMacroImpl(, final, name, type)
1410#define itkNonVirtualGetObjectMacro(name, type) ITK_DETAIL_GetObjectMacroImpl(, , name, type)
1411#define itkGetObjectMacro(name, type) ITK_DETAIL_GetObjectMacroImpl(virtual, , name, type)
1412
1413#define itkVirtualGetModifiableObjectMacro(name, type) ITK_DETAIL_GetModifiableObjectMacroImpl(virtual, , name, type)
1414#define itkFinalGetModifiableObjectMacro(name, type) ITK_DETAIL_GetModifiableObjectMacroImpl(, final, name, type)
1415#define itkNonVirtualGetModifiableObjectMacro(name, type) ITK_DETAIL_GetModifiableObjectMacroImpl(, , name, type)
1416#define itkGetModifiableObjectMacro(name, type) ITK_DETAIL_GetModifiableObjectMacroImpl(virtual, , name, type)
1418
1419// For backwards compatibility define ITK_EXPORT to nothing
1420#define ITK_EXPORT
1421
1422
1423// Get a const reference to a smart pointer to an object. Creates Get"name"(). Implementation detail; use the public
1424// wrappers below.
1425#define ITK_DETAIL_GetConstReferenceObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1426 virtualKeyword const typename type::Pointer & Get##name() const finalKeyword { return this->m_##name; } \
1427 ITK_MACROEND_NOOP_STATEMENT
1428
1432#define itkVirtualGetConstReferenceObjectMacro(name, type) \
1433 ITK_DETAIL_GetConstReferenceObjectMacroImpl(virtual, , name, type)
1434#define itkFinalGetConstReferenceObjectMacro(name, type) \
1435 ITK_DETAIL_GetConstReferenceObjectMacroImpl(, final, name, type)
1436#define itkNonVirtualGetConstReferenceObjectMacro(name, type) \
1437 ITK_DETAIL_GetConstReferenceObjectMacroImpl(, , name, type)
1438#define itkGetConstReferenceObjectMacro(name, type) ITK_DETAIL_GetConstReferenceObjectMacroImpl(virtual, , name, type)
1440
1441// Set a const object pointer (Object reference-counted). Creates Set"name"(). Implementation detail; use the public
1442// wrappers below.
1443#define ITK_DETAIL_SetConstObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1444 virtualKeyword void Set##name(const type * _arg) finalKeyword \
1445 { \
1446 itkDebugMacro("setting " << #name " to " << _arg); \
1447 if (this->m_##name != _arg) \
1448 { \
1449 this->m_##name = _arg; \
1450 this->Modified(); \
1451 } \
1452 } \
1453 ITK_MACROEND_NOOP_STATEMENT
1454
1458#define itkVirtualSetConstObjectMacro(name, type) ITK_DETAIL_SetConstObjectMacroImpl(virtual, , name, type)
1459#define itkFinalSetConstObjectMacro(name, type) ITK_DETAIL_SetConstObjectMacroImpl(, final, name, type)
1460#define itkNonVirtualSetConstObjectMacro(name, type) ITK_DETAIL_SetConstObjectMacroImpl(, , name, type)
1461#define itkSetConstObjectMacro(name, type) ITK_DETAIL_SetConstObjectMacroImpl(virtual, , name, type)
1463// Create "name"On()/"name"Off(). Requires a Set method. Implementation detail; use the public wrappers below.
1464#define ITK_DETAIL_BooleanMacroImpl(virtualKeyword, finalKeyword, name) \
1465 virtualKeyword void name##On() finalKeyword { this->Set##name(true); } \
1466 virtualKeyword void name##Off() finalKeyword { this->Set##name(false); } \
1467 ITK_MACROEND_NOOP_STATEMENT
1468
1472#define itkVirtualBooleanMacro(name) ITK_DETAIL_BooleanMacroImpl(virtual, , name)
1473#define itkFinalBooleanMacro(name) ITK_DETAIL_BooleanMacroImpl(, final, name)
1474#define itkNonVirtualBooleanMacro(name) ITK_DETAIL_BooleanMacroImpl(, , name)
1475#define itkBooleanMacro(name) ITK_DETAIL_BooleanMacroImpl(virtual, , name)
1477
1486template <typename MemberContainerType, typename CopyFromValueType, typename LoopEndType>
1487bool
1488ContainerFillWithCheck(MemberContainerType & m, const CopyFromValueType & c, const LoopEndType N)
1489{
1490 bool value_updated = false;
1491 for (unsigned int i = 0; i < N; ++i)
1492 {
1493 ITK_GCC_PRAGMA_PUSH
1494 ITK_GCC_SUPPRESS_Wfloat_equal
1495 if (m[i] != c)
1496 {
1497 m[i] = c;
1498 value_updated = true;
1499 }
1500 ITK_GCC_PRAGMA_POP
1501 }
1502 return value_updated;
1503}
1504
1513template <typename MemberContainerType, typename CopyFromContainerType, typename LoopEndType>
1514bool
1515ContainerCopyWithCheck(MemberContainerType & m, const CopyFromContainerType & c, const LoopEndType N)
1516{
1517 bool value_updated = false;
1518 for (LoopEndType i = 0; i < N; ++i)
1519 {
1520 ITK_GCC_PRAGMA_PUSH
1521 ITK_GCC_SUPPRESS_Wfloat_equal
1522 if (m[i] != c[i])
1523 {
1524 m[i] = c[i];
1525 value_updated = true;
1526 }
1527 ITK_GCC_PRAGMA_POP
1528 }
1529 return value_updated;
1530}
1531
1532// clang-format off
1533// Copy `count` values into the object. Creates Set"name"(). Implementation detail; use the public wrappers below.
1534#define ITK_DETAIL_SetVectorMacroImpl(virtualKeyword, finalKeyword, name, type, count) \
1535 virtualKeyword void Set##name(type data[]) finalKeyword \
1536 { \
1537 if (ContainerCopyWithCheck(this->m_##name, data, count)) \
1538 { \
1539 this->Modified(); \
1540 } \
1541 } \
1542 ITK_MACROEND_NOOP_STATEMENT
1543// clang-format on
1544
1549#define itkVirtualSetVectorMacro(name, type, count) ITK_DETAIL_SetVectorMacroImpl(virtual, , name, type, count)
1550#define itkFinalSetVectorMacro(name, type, count) ITK_DETAIL_SetVectorMacroImpl(, final, name, type, count)
1551#define itkNonVirtualSetVectorMacro(name, type, count) ITK_DETAIL_SetVectorMacroImpl(, , name, type, count)
1552#define itkSetVectorMacro(name, type, count) ITK_DETAIL_SetVectorMacroImpl(virtual, , name, type, count)
1554
1555// Return pointer to type (array of type), for efficiency. Creates Get"name"(). Implementation detail; use the public
1556// wrappers below.
1557#define ITK_DETAIL_GetVectorMacroImpl(virtualKeyword, finalKeyword, name, type, count) \
1558 virtualKeyword type * Get##name() const finalKeyword { return this->m_##name; } \
1559 ITK_MACROEND_NOOP_STATEMENT
1560
1563#define itkVirtualGetVectorMacro(name, type, count) ITK_DETAIL_GetVectorMacroImpl(virtual, , name, type, count)
1564#define itkFinalGetVectorMacro(name, type, count) ITK_DETAIL_GetVectorMacroImpl(, final, name, type, count)
1565#define itkNonVirtualGetVectorMacro(name, type, count) ITK_DETAIL_GetVectorMacroImpl(, , name, type, count)
1566#define itkGetVectorMacro(name, type, count) ITK_DETAIL_GetVectorMacroImpl(virtual, , name, type, count)
1568
1573#define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1574
1581#define itkGPUKernelMacro(kernel) \
1582 kernel \
1583 { \
1584 public: \
1585 ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1586 kernel() = delete; \
1587 ~kernel() = delete; \
1588 static const char * GetOpenCLSource(); \
1589 }
1591#define itkGetOpenCLSourceFromKernelMacro(kernel) \
1592 static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); } \
1593 ITK_MACROEND_NOOP_STATEMENT
1594
1595// A useful macro in the PrintSelf method for printing member variables
1596// which are pointers to object based on the LightObject class.
1597#define itkPrintSelfObjectMacro(name) \
1598 if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1599 { \
1600 os << indent << #name << ": (null)" << std::endl; \
1601 } \
1602 else \
1603 { \
1604 os << indent << #name << ": " << std::endl; \
1605 this->m_##name->Print(os, indent.GetNextIndent()); \
1606 } \
1607 ITK_MACROEND_NOOP_STATEMENT
1608
1609
1610// A useful macro in the PrintSelf method for printing boolean member
1611// variables.
1612#define itkPrintSelfBooleanMacro(name) \
1613 os << indent << #name << ": " << (this->m_##name ? "On" : "Off") << std::endl; \
1614 ITK_MACROEND_NOOP_STATEMENT
1615
1616
1617// Set a decorated output. Defines Set"name"Output() and Set"name"(value). Implementation detail; use the public
1618// wrappers below.
1619#define ITK_DETAIL_SetDecoratedOutputMacroImpl(virtualKeyword, finalKeyword, name, type) \
1620 virtualKeyword void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) finalKeyword \
1621 { \
1622 itkDebugMacro("setting output " #name " to " << _arg); \
1623 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1624 { \
1625 this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1626 this->Modified(); \
1627 } \
1628 } \
1629 virtualKeyword void Set##name(const type & _arg) finalKeyword \
1630 { \
1631 using DecoratorType = SimpleDataObjectDecorator<type>; \
1632 itkDebugMacro("setting output " #name " to " << _arg); \
1633 DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1634 if (output) \
1635 { \
1636 if (output->Get() == _arg) \
1637 { \
1638 return; \
1639 } \
1640 else \
1641 { \
1642 output->Set(_arg); \
1643 } \
1644 } \
1645 else \
1646 { \
1647 auto newOutput = DecoratorType::New(); \
1648 newOutput->Set(_arg); \
1649 this->Set##name##Output(newOutput); \
1650 } \
1651 } \
1652 ITK_MACROEND_NOOP_STATEMENT
1653
1656#define itkVirtualSetDecoratedOutputMacro(name, type) ITK_DETAIL_SetDecoratedOutputMacroImpl(virtual, , name, type)
1657#define itkFinalSetDecoratedOutputMacro(name, type) ITK_DETAIL_SetDecoratedOutputMacroImpl(, final, name, type)
1658#define itkNonVirtualSetDecoratedOutputMacro(name, type) ITK_DETAIL_SetDecoratedOutputMacroImpl(, , name, type)
1659#define itkSetDecoratedOutputMacro(name, type) ITK_DETAIL_SetDecoratedOutputMacroImpl(virtual, , name, type)
1661
1662// Get a decorated output. Defines Get"name"Output() and Get"name"(). Implementation detail; use the public wrappers
1663// below.
1664#define ITK_DETAIL_GetDecoratedOutputMacroImpl(virtualKeyword, finalKeyword, name, type) \
1665 virtualKeyword const SimpleDataObjectDecorator<type> * Get##name##Output() const finalKeyword \
1666 { \
1667 itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1668 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1669 } \
1670 virtualKeyword const type & Get##name() const finalKeyword \
1671 { \
1672 itkDebugMacro("Getting output " #name); \
1673 using DecoratorType = SimpleDataObjectDecorator<type>; \
1674 const DecoratorType * output = \
1675 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1676 if (output == nullptr) \
1677 { \
1678 itkExceptionStringMacro("output" #name " is not set"); \
1679 } \
1680 return output->Get(); \
1681 } \
1682 ITK_MACROEND_NOOP_STATEMENT
1683
1686#define itkVirtualGetDecoratedOutputMacro(name, type) ITK_DETAIL_GetDecoratedOutputMacroImpl(virtual, , name, type)
1687#define itkFinalGetDecoratedOutputMacro(name, type) ITK_DETAIL_GetDecoratedOutputMacroImpl(, final, name, type)
1688#define itkNonVirtualGetDecoratedOutputMacro(name, type) ITK_DETAIL_GetDecoratedOutputMacroImpl(, , name, type)
1689#define itkGetDecoratedOutputMacro(name, type) ITK_DETAIL_GetDecoratedOutputMacroImpl(virtual, , name, type)
1691// ITK_FUTURE_DEPRECATED is only for internal use, within the implementation of ITK. It allows triggering "deprecated"
1692// warnings when legacy support is removed, which warn that a specific feature may be removed in the future.
1693#if defined(ITK_LEGACY_REMOVE) && !defined(ITK_LEGACY_SILENT)
1694# define ITK_FUTURE_DEPRECATED(message) [[deprecated(message)]]
1695#else
1696# define ITK_FUTURE_DEPRECATED(message)
1697#endif
1698
1699#if __cplusplus >= 202002L
1700# define ITK_NODISCARD(message) [[nodiscard(message)]]
1701#else
1702# define ITK_NODISCARD(message) [[nodiscard]]
1703#endif
1704
1705//-*-*-*
1706
1707#if defined(ITK_LEGACY_REMOVE)
1708# define itkExposeEnumValue(name) \
1709 static_assert(false, "ERROR: Replace static_cast<int>(name) with with proper enumeration instead of integer")
1710
1711# define ITK_NOEXCEPT_OR_THROW static_assert(false, "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT")
1712
1713# define ITK_DELETE_FUNCTION static_assert(false, "ERROR: ITK_DELETE_FUNCTION must be replaced with `= delete`"
1714# define ITK_CONSTEXPR_FUNC static_assert(false, "ERROR: ITK_CONSTEXPR_FUNC must be replaced with 'constexpr'")
1715# define ITK_CONSTEXPR_VAR static_assert(false, "ERROR: ITK_CONSTEXPR_VAR must be replaced with 'constexpr'")
1716
1717# define ITK_FALLTHROUGH static_assert(false, "ERROR: ITK_FALLTHROUGH must be replaced with '[[fallthrough]]'")
1718
1719// Defines which used to be in itk_compiler_detection.h
1720# define ITK_ALIGNAS static_assert(false, "ERROR: ITK_ALIGNAS must be replaced with 'alignas'")
1721# define ITK_ALIGNOF static_assert(false, "ERROR: ITK_ALIGNOF must be replaced with 'alignof'")
1722# define ITK_DEPRECATED static_assert(false, "ERROR: ITK_DEPRECATED must be replaced with '[[deprecated]]'")
1723# define ITK_DEPRECATED_MSG \
1724 static_assert(false, "ERROR: ITK_DEPRECATED_MSG must be replaced with '[[deprecated(MSG)]]'")
1725# define ITK_CONSTEXPR static_assert(false, "ERROR: ITK_CONSTEXPR must be replaced with 'constexpr'")
1726# define ITK_DELETED_FUNCTION static_assert(false, "ERROR: ITK_DELETED_FUNCTION must be replaced with '= delete'")
1727# define ITK_EXTERN_TEMPLATE static_assert(false, "ERROR: ITK_EXTERN_TEMPLATE must be replaced with 'extern'")
1728# define ITK_FINAL static_assert(false, "ERROR: ITK_FINAL must be replaced with 'final'")
1729# define ITK_NOEXCEPT static_assert(false, "ERROR: ITK_NOEXCEPT must be replaced with 'noexcept'")
1730# define ITK_NOEXCEPT_EXPR static_assert(false, "ERROR: ITK_NOEXCEPT_EXPR must be replaced with 'noexcept'")
1731# define ITK_NULLPTR static_assert(false, "ERROR: ITK_NULLPTR must be replaced with 'nullptr'")
1732# define ITK_OVERRIDE static_assert(false, "ERROR: ITK_OVERRIDE must be replaced with 'override'")
1733# define ITK_STATIC_ASSERT static_assert(false, "ERROR: ITK_STATIC_ASSERT must be replaced with 'static_assert'")
1734# define ITK_STATIC_ASSERT_MSG \
1735 static_assert(false, "ERROR: ITK_STATIC_ASSERT_MSG must be replaced with 'static_assert'")
1736# define ITK_THREAD_LOCAL static_assert(false, "ERROR: ITK_THREAD_LOCAL must be replaced with 'thread_local'")
1737
1738// A macro for methods which are const in ITKv5 and ITKv6 require const for functions
1739# define ITKv5_CONST static_assert(false, "ERROR: ITKv5_CONST must be replaced with 'const'")
1740
1741# define ITK_ITERATOR_VIRTUAL static_assert(false, "ERROR: ITK_ITERATOR_VIRTUAL must be removed'")
1742# define ITK_ITERATOR_OVERRIDE static_assert(false, "ERROR: ITK_ITERATOR_OVERRIDE must be removed")
1743# define ITK_ITERATOR_FINAL static_assert(false, "ERROR: ITK_ITERATOR_FINAL must be removed")
1744
1745#else
1746// DEPRECATED: These macros are left here for compatibility with remote modules.
1747// Once they have been removed from all known remote modules, this code should
1748// be removed.
1749
1750// Future remove `#define itkExposeEnumValue(name)`
1751// "Replace type of `name` with proper enumeration instead of integer.
1752# define itkExposeEnumValue(name) static_cast<int>(name)
1753
1754
1755# define ITK_NOEXCEPT_OR_THROW ITK_NOEXCEPT
1756
1757# define ITK_FALLTHROUGH [[fallthrough]]
1758
1759# define ITK_DELETE_FUNCTION = delete
1760
1761# define ITK_CONSTEXPR_FUNC constexpr
1762# define ITK_CONSTEXPR_VAR constexpr
1763
1764// Defines which used to be in itk_compiler_detection.h
1765# define ITK_ALIGNAS(X) alignas(X)
1766# define ITK_ALIGNOF(X) alignof(X)
1767# define ITK_DEPRECATED [[deprecated]]
1768# define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1769# define ITK_CONSTEXPR constexpr
1770# define ITK_DELETED_FUNCTION = delete
1771# define ITK_EXTERN_TEMPLATE extern
1772# define ITK_FINAL final
1773# define ITK_NOEXCEPT noexcept
1774# define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1775# define ITK_NULLPTR nullptr
1776# define ITK_OVERRIDE override
1777# define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1778# define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1779# define ITK_THREAD_LOCAL thread_local
1780
1781// A macro for methods which are const in after ITKv4
1782# define ITKv5_CONST const
1783
1784# define ITK_ITERATOR_VIRTUAL /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1785# define ITK_ITERATOR_OVERRIDE /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1786# define ITK_ITERATOR_FINAL /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1787#endif
1788
1789#define allow_inclusion_of_itkExceptionObject_h
1790// Must include itkExceptionObject.h at the end of the file
1791// because it depends on the macros defined above
1792#include "itkExceptionObject.h"
1793
1794
1795#undef allow_inclusion_of_itkExceptionObject_h
1796
1797
1798#include "itkPrintHelper.h"
1799#endif // itkMacro_h
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....