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// Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
170//
171// This macro sets a pragma diagnostic
172//
173// Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
174//
175// These macros respectively push and pop the diagnostic context
176//
177#if defined(__GNUC__)
178# define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
179# define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
180# define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
181#else
182# define ITK_GCC_PRAGMA_DIAG(x)
183# define ITK_GCC_PRAGMA_DIAG_PUSH()
184# define ITK_GCC_PRAGMA_DIAG_POP()
185#endif
186
187/*
188 * ITK only supports MSVC++ 14.2 and greater
189 * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
190 */
191#if defined(_MSC_VER) && (_MSC_VER < 1920)
192# error "MSVC versions before Visual Studio 2019 are not supported"
193#endif
194#if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
195# error "SUNPro C++ < 5.14.0 is not supported"
196#endif
197#if defined(__CYGWIN__)
198# error "The Cygwin compiler is not supported"
199#endif
200#if defined(__BORLANDC__)
201# error "The Borland C compiler is not supported"
202#endif
203#if defined(__MWERKS__)
204# error "The MetroWerks compiler is not supported"
205#endif
206#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 7)
207# error "GCC < 7 is not supported"
208#endif
209#if defined(__sgi)
210// This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
211// TODO: At some future point, it may be necessary to
212// define a minimum __sgi version that will work.
213# error "The SGI compiler is not supported"
214#endif
215#if defined(__apple_build_version__) && (__apple_build_version__ < 12000032)
216# error "AppleClang < Xcode 12.4 is not supported"
217#elif defined(__clang__) && (__clang_major__ < 5)
218# error "Clang < 5 is not supported"
219#endif
220
221// Setup symbol exports
222#if defined(_WIN32) || defined(WIN32)
223# define ITK_ABI_IMPORT __declspec(dllimport)
224# define ITK_ABI_EXPORT __declspec(dllexport)
225# define ITK_ABI_HIDDEN
226#else
227# ifdef __GNUC__
228# define ITK_ABI_IMPORT __attribute__((visibility("default")))
229# define ITK_ABI_EXPORT __attribute__((visibility("default")))
230# define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
231# else
232# define ITK_ABI_IMPORT
233# define ITK_ABI_EXPORT
234# define ITK_ABI_HIDDEN
235# endif
236#endif
237
238// Setup symbol exports
239#ifndef ITK_TEMPLATE_EXPORT
240# ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
241# define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
242# else
243# define ITK_TEMPLATE_EXPORT
244# endif
245#endif
246
247// Setup symbol exports
248#ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
249# define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
250#else
251# define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
252#endif
253
254#ifndef ITK_FORWARD_EXPORT
255// If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
256# if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
257 defined(USE_COMPILER_HIDDEN_VISIBILITY)
258# define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
259# else
260# define ITK_FORWARD_EXPORT
261# endif
262#endif
263
264
286#define itkNewMacro(x) \
287 itkSimpleNewMacro(x); \
288 itkCreateAnotherMacro(x); \
289 itkCloneMacro(x); \
290 ITK_MACROEND_NOOP_STATEMENT
292#define itkSimpleNewMacro(x) \
293 static Pointer New() \
294 { \
295 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
296 if (smartPtr == nullptr) \
297 { \
298 smartPtr = new x(); \
299 } \
300 smartPtr->UnRegister(); \
301 return smartPtr; \
302 } \
303 ITK_MACROEND_NOOP_STATEMENT
304
305#define itkCreateAnotherMacro(x) \
306 ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
307 ITK_MACROEND_NOOP_STATEMENT
308
309#define itkCloneMacro(x) \
310 Pointer Clone() const \
311 { \
312 Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
313 return rval; \
314 } \
315 ITK_MACROEND_NOOP_STATEMENT
316
321#define itkFactoryOnlyNewMacro(x) \
322 itkSimpleFactoryOnlyNewMacro(x); \
323 itkCreateAnotherMacro(x); \
324 itkCloneMacro(x); \
325 ITK_MACROEND_NOOP_STATEMENT
327#define itkSimpleFactoryOnlyNewMacro(x) \
328 static auto New() -> Pointer \
329 { \
330 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
331 if (smartPtr == nullptr) \
332 { \
333 itkSpecializedMessageExceptionMacro(ExceptionObject, \
334 "Object factory failed to instantiate " << typeid(x).name()); \
335 } \
336 smartPtr->UnRegister(); \
337 return smartPtr; \
338 } \
339 ITK_MACROEND_NOOP_STATEMENT
340
354#define itkFactorylessNewMacro(x) \
355 static Pointer New() \
356 { \
357 auto * rawPtr = new x(); \
358 Pointer smartPtr = rawPtr; \
359 rawPtr->UnRegister(); \
360 return smartPtr; \
361 } \
362 itkCreateAnotherMacro(x); \
363 ITK_MACROEND_NOOP_STATEMENT
365//
366// A macro to disallow the copy constructor, copy assignment,
367// move constructor, and move assignment functions.
368// This should be used in the public: declarations for a class
369//
370// ITK's paradigm for smart pointer and pipeline consistency
371// prohibits the use of copy/move construction and copy/move assignment
372// functions.
373//
374#define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
375 TypeName(const TypeName &) = delete; \
376 TypeName & operator=(const TypeName &) = delete; \
377 TypeName(TypeName &&) = delete; \
378 TypeName & operator=(TypeName &&) = delete
379
380#if !defined(ITK_LEGACY_REMOVE)
381# define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
382#else
383# define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
384 static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
385#endif
386
387
396#define ITK_DEFAULT_COPY_AND_MOVE(TypeName) \
397 TypeName(const TypeName &) = default; \
398 TypeName & operator=(const TypeName &) = default; \
399 TypeName(TypeName &&) = default; \
400 TypeName & operator=(TypeName &&) = default
402
403// When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
404// the ability for operator!= to be rewritten automatically in terms of
405// operator==, as introduced with C++20. This macro is experimental. It may be
406// modified, renamed, or removed without backward compatibility support.
407#if __cplusplus >= 202002L
408# define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
409#endif
410
411// Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
412// is only for internal use within the implementation of ITK. It may be
413// modified, renamed, or removed without backward compatibility support.
414#ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
415// With C++20, operator!= is automatically rewritten in terms of the
416// corresponding operator==.
417# define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
418#else
419// For C++14 and C++17, this macro defines an operator!= member function that
420// just calls the corresponding operator== member function.
421# define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
422 bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
423 ITK_MACROEND_NOOP_STATEMENT
424#endif
425
426
427// Internal macro (not part of the public ITK API), used to implement `GetNameOfClass()` member functions.
428#define itkInternalGetNameOfClassImplementationMacro(thisClass) \
429 { \
430 static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
431 "The macro argument `" #thisClass \
432 "` appears incorrect! It should correspond with the name of this class!"); \
433 return #thisClass; \
434 } \
435 ITK_MACROEND_NOOP_STATEMENT
436
437
441#define itkVirtualGetNameOfClassMacro(thisClass) \
442 virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
443
444#define itkOverrideGetNameOfClassMacro(thisClass) \
445 const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
446
447#ifdef ITK_FUTURE_LEGACY_REMOVE
448# define itkTypeMacro(thisClass, superclass) \
449 static_assert(false, \
450 "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
451 "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
452# define itkTypeMacroNoParent(thisClass) \
453 static_assert(false, \
454 "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
455 "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
456#else
461# define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
462# define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
463#endif
464
465
466namespace itk
467{
475#ifndef ITK_FUTURE_LEGACY_REMOVE
476extern ITKCommon_EXPORT void
477OutputWindowDisplayText(const char *);
478
479extern ITKCommon_EXPORT void
480OutputWindowDisplayErrorText(const char *);
481
482extern ITKCommon_EXPORT void
483OutputWindowDisplayWarningText(const char *);
484
485extern ITKCommon_EXPORT void
486OutputWindowDisplayGenericOutputText(const char *);
487
488extern ITKCommon_EXPORT void
489OutputWindowDisplayDebugText(const char *);
490#endif
491
492// New context-aware versions of output display functions
493extern ITKCommon_EXPORT void
494OutputWindowDisplayDebugText(const char * file,
495 unsigned int line,
496 const char * className,
497 const void * objectAddress,
498 const char * message);
499
500extern ITKCommon_EXPORT void
501OutputWindowDisplayWarningText(const char * file,
502 unsigned int line,
503 const char * className,
504 const void * objectAddress,
505 const char * message);
506
507extern ITKCommon_EXPORT void
508OutputWindowDisplayErrorText(const char * file,
509 unsigned int line,
510 const char * className,
511 const void * objectAddress,
512 const char * message);
513
514extern ITKCommon_EXPORT void
515OutputWindowDisplayGenericOutputText(const char * file, unsigned int line, const char * message);
517
518} // end namespace itk
519
520// The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
526#if defined(NDEBUG)
527# define itkDebugMacro(x) ITK_NOOP_STATEMENT
528# define itkDebugStatement(x) ITK_NOOP_STATEMENT
529#else
530# define itkDebugMacro(x) \
531 { \
532 using namespace ::itk::print_helper; /* for ostream << std::vector<T> */ \
533 if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
534 { \
535 std::ostringstream itkmsg; \
536 itkmsg << "" x; \
537 ::itk::OutputWindowDisplayDebugText(__FILE__, __LINE__, this->GetNameOfClass(), this, itkmsg.str().c_str()); \
538 } \
539 } \
540 ITK_MACROEND_NOOP_STATEMENT
541// The itkDebugStatement is to be used to protect code that is only
542// used in the itkDebugMacro
543# define itkDebugStatement(x) x
544#endif
549#define itkWarningMacro(x) \
550 { \
551 if (::itk::Object::GetGlobalWarningDisplay()) \
552 { \
553 std::ostringstream itkmsg; \
554 itkmsg << "" x; \
555 ::itk::OutputWindowDisplayWarningText(__FILE__, __LINE__, this->GetNameOfClass(), this, itkmsg.str().c_str()); \
556 } \
557 } \
558 ITK_MACROEND_NOOP_STATEMENT
559
560
561#define itkWarningStatement(x) x
562
563#if defined(ITK_CPP_FUNCTION)
564# if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
565# define ITK_LOCATION __FUNCSIG__
566# elif defined(__GNUC__)
567# define ITK_LOCATION __PRETTY_FUNCTION__
568# else
569# define ITK_LOCATION __FUNCTION__
570# endif
571#else
572# define ITK_LOCATION "unknown"
573#endif
574
575#define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
576 namespace itk \
577 { \
578 class newexcp : public parentexcp \
579 { \
580 public: \
581 /* default message provides backward compatibility for a given exception type */ \
582 static constexpr const char * const default_exception_message = whatmessage; \
583 /* Inherit the constructors from its base class. */ \
584 using parentexcp::parentexcp; \
585 itkOverrideGetNameOfClassMacro(newexcp); \
586 }; \
587 } \
588 ITK_MACROEND_NOOP_STATEMENT
589
590
591#define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
592 { \
593 std::ostringstream exceptionDescriptionOutputStringStream; \
594 exceptionDescriptionOutputStringStream << "" x; \
595 throw ::itk::ExceptionType( \
596 std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
597 } \
598 ITK_MACROEND_NOOP_STATEMENT
599
600#define itkSpecializedExceptionMacro(ExceptionType) \
601 throw ::itk::ExceptionType( \
602 std::string{ __FILE__ }, __LINE__, ::itk::ExceptionType::default_exception_message, std::string{ ITK_LOCATION });
603
604
608#define itkExceptionMacro(x) \
609 { \
610 std::ostringstream exceptionDescriptionOutputStringStream; \
611 exceptionDescriptionOutputStringStream << "" x; \
612 throw ::itk::ExceptionObject(std::string{ __FILE__ }, \
613 __LINE__, \
614 exceptionDescriptionOutputStringStream.str(), \
615 std::string{ ITK_LOCATION }, \
616 this); \
617 } \
618 ITK_MACROEND_NOOP_STATEMENT
619
620#define itkExceptionStringMacro(x) \
621 { \
622 throw ::itk::ExceptionObject( \
623 std::string{ __FILE__ }, __LINE__, std::string{ x }, std::string{ ITK_LOCATION }, this); \
624 } \
625 ITK_MACROEND_NOOP_STATEMENT
626
627#define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
628
629#define itkGenericOutputMacro(x) \
630 { \
631 if (::itk::Object::GetGlobalWarningDisplay()) \
632 { \
633 std::ostringstream itkmsg; \
634 itkmsg << "" x; \
635 ::itk::OutputWindowDisplayGenericOutputText(__FILE__, __LINE__, itkmsg.str().c_str()); \
636 } \
637 } \
638 ITK_MACROEND_NOOP_STATEMENT
639
640//----------------------------------------------------------------------------
641// Macros for simplifying the use of logging
642//
643#define itkLogMacro(x, y) \
644 { \
645 if (this->GetLogger()) \
646 { \
647 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
648 } \
649 } \
650 ITK_MACROEND_NOOP_STATEMENT
651
652#define itkLogMacroStatic(obj, x, y) \
653 { \
654 if (obj->GetLogger()) \
655 { \
656 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
657 } \
658 } \
659 ITK_MACROEND_NOOP_STATEMENT
660
661//----------------------------------------------------------------------------
662// Setup legacy code policy.
663//
664// CMake options:
665// - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
666// - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
667// of legacy code will not produce compiler warnings.
668// - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
669// of legacy code will produce compiler warnings
670//
671// ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
672//
673// Source files that test the legacy code may define ITK_LEGACY_TEST
674// like this:
675//
676// #define ITK_LEGACY_TEST
677// #include "itkClassWithDeprecatedMethod.h"
678//
679// in order to silence the warnings for calling deprecated methods.
680// No other source files in ITK should call the methods since they are
681// provided only for compatibility with older user code.
682
683// Define itkLegacyMacro to mark legacy methods where they are
684// declared in their class. Example usage:
685//
686// // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
687// itkLegacyMacro(void MyMethod();)
688//
689// See below for what to do for the method definition.
690#if defined(ITK_LEGACY_REMOVE)
691# define itkLegacyMacro(method) /* no ';' */
692#else
693# if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
694// Provide legacy methods with no warnings.
695# define itkLegacyMacro(method) method /* no ';' */
696# else
697// Request compile-time warnings for uses of deprecated methods.
698# define itkLegacyMacro(method) [[deprecated]] method /* no ';' */
699# endif
700#endif
701
702// Macros to create runtime deprecation warning messages in function
703// bodies. Example usage:
704//
705// #if !defined( ITK_LEGACY_REMOVE )
706// void itkMyClass::MyOldMethod()
707// {
708// itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
709// }
710//
711// void itkMyClass::MyMethod()
712// {
713// itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
714// itkMyClass::MyOtherMethod);
715// }
716// #endif
717//
718// NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
719// itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
720// are purposefully not defined when ITK_LEGACY_REMOVE is on,
721// because these macros are only relevant inside code segments
722// that are conditionally compiled only when ITK_LEGACY_REMOVE
723// is off.
724#if defined(ITK_LEGACY_SILENT)
725# define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
726# define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
727# define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
728# define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
729#else
730# define itkLegacyBodyMacro(method, version) \
731 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
732# define itkLegacyReplaceBodyMacro(method, version, replace) \
733 itkWarningMacro(#method " was deprecated for ITK " #version \
734 " and will be removed in a future version. Use " #replace " instead.")
735# define itkGenericLegacyBodyMacro(method, version) \
736 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
737# define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
738 itkGenericOutputMacro(#method " was deprecated for ITK " #version \
739 " and will be removed in a future version. Use " #replace " instead.")
740#endif
741
742// Most modern x86 CPUs have 64 byte aligned blocks which are used for
743// the cache lines. By aligning multi-threaded structures with the
744// cache lines, false shared can be reduced, and performance
745// increased.
746constexpr size_t ITK_CACHE_LINE_ALIGNMENT{ 64 };
747
748//
749// itkPadStruct will add padding to a structure to ensure a minimum size
750// for ensuring that adjacent structures do not share CACHE lines.
751// Each struct will take up some multiple of cacheline sizes.
752// This is particularly useful for arrays of thread private variables.
753//
754#define itkPadStruct(mincachesize, oldtype, newtype) \
755 struct newtype : public oldtype \
756 { \
757 char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
758 }
759
760//
761// itkAlignedTypedef is a macro which creates a new type to make a
762// data structure aligned.
763//
764#if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
765# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
766#elif defined(_MSC_VER)
767# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
768#else
769# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
770#endif
771
772#if defined(ITK_FUTURE_LEGACY_REMOVE)
773//=============================================================================
774/*
775NOTE: DEPRECATED - This macro is not longer needed to support modern
776compilers.
777
778 Define a common way of declaring a templated function as a friend inside a class.
779 - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
780
781 The following templated function
782
783 template <T>
784 T add(const T & a, const T & b);
785
786 is declared as friend with
787
788 class A
789 {
790 public:
791 friend Self add<>( const Self & a, const Self & b );
792 }
793
794*/
795# define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
796#else // LEGACY_REMOVE
797# define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
798#endif
799
800//--------------------------------------------------------------------------------
801// Helper macros for Template Meta-Programming techniques of for-loops
802// unrolling
803//--------------------------------------------------------------------------------
804
805//--------------------------------------------------------------------------------
806// Macro that generates an unrolled for loop for assigning elements of one array
807// to elements of another array The array are assumed to be of same length
808// (dimension), and this is also assumed to be the value of NumberOfIterations.
809// No verification of size is performed. Casting is performed as part of the
810// assignment, by using the DestinationElementType as the casting type.
811// Source and destination array types must have defined operator[] in their
812// API.
813#define itkForLoopAssignmentMacro( \
814 DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
815 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
816 { \
817 DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
818 } \
819 ITK_MACROEND_NOOP_STATEMENT
820
821//--------------------------------------------------------------------------------
822// Macro that generates an unrolled for loop for rounding and assigning
823// elements of one array to elements of another array The array are assumed to
824// be of same length (dimension), and this is also assumed to be the value of
825// NumberOfIterations. No verification of size is performed. Casting is
826// performed as part of the assignment, by using the DestinationElementType as
827// the casting type.
828// Source and destination array types must have defined operator[] in their
829// API.
830#define itkForLoopRoundingAndAssignmentMacro( \
831 DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
832 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
833 { \
834 DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
835 } \
836 ITK_MACROEND_NOOP_STATEMENT
837
838// end of Template Meta Programming helper macros
839
840#if !defined(NDEBUG) && !defined(ITK_WRAPPING)
841
842# ifdef __GLIBC__
843# define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
844# else
845# define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
846# endif
847
848#else
849# define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
850#endif
851
852#define itkAssertOrThrowMacro(test, message) \
853 if (!(test)) \
854 { \
855 std::ostringstream msgstr; \
856 msgstr << message; \
857 itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
858 } \
859 ITK_MACROEND_NOOP_STATEMENT
860
861#if !defined(NDEBUG) && !defined(ITK_WRAPPING)
862# define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
863#else
864# define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
865#endif
866
867
868// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
869// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
870// !! The ITK Get/Set Macros for various types !!
871// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
872// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
873
874#ifdef ITK_FUTURE_LEGACY_REMOVE
875# define itkStaticConstMacro(name, type, value) \
876 "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
877# define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
878#else
893# define itkStaticConstMacro(name, type, value) static constexpr type name = value
894
895# define itkGetStaticConstMacro(name) (Self::name)
896#endif
897
898// Set an input. This defines the Set"name"() method. Implementation detail; use the public wrappers below.
899#define ITK_DETAIL_SetInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
900 virtualKeyword void Set##name(const type * _arg) finalKeyword \
901 { \
902 itkDebugMacro("setting input " #name " to " << _arg); \
903 if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
904 { \
905 this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
906 this->Modified(); \
907 } \
908 } \
909 ITK_MACROEND_NOOP_STATEMENT
910
913#define itkVirtualSetInputMacro(name, type) ITK_DETAIL_SetInputMacroImpl(virtual, , name, type)
914#define itkFinalSetInputMacro(name, type) ITK_DETAIL_SetInputMacroImpl(, final, name, type)
915#define itkNonVirtualSetInputMacro(name, type) ITK_DETAIL_SetInputMacroImpl(, , name, type)
916#define itkSetInputMacro(name, type) ITK_DETAIL_SetInputMacroImpl(virtual, , name, type)
918
919// Get an input. This defines the Get"name"() method. Implementation detail; use the public wrappers below.
920#define ITK_DETAIL_GetInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
921 virtualKeyword const type * Get##name() const finalKeyword \
922 { \
923 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
924 return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
925 } \
926 ITK_MACROEND_NOOP_STATEMENT
927
930#define itkVirtualGetInputMacro(name, type) ITK_DETAIL_GetInputMacroImpl(virtual, , name, type)
931#define itkFinalGetInputMacro(name, type) ITK_DETAIL_GetInputMacroImpl(, final, name, type)
932#define itkNonVirtualGetInputMacro(name, type) ITK_DETAIL_GetInputMacroImpl(, , name, type)
933#define itkGetInputMacro(name, type) ITK_DETAIL_GetInputMacroImpl(virtual, , name, type)
935
936// clang-format off
937// Set a decorated input. Defines Set"name"Input(), Set"name"(decorator*) and Set"name"(value). Implementation detail; use the public wrappers below.
938#define ITK_DETAIL_SetDecoratedInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
939 virtualKeyword void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) finalKeyword \
940 { \
941 itkDebugMacro("setting input " #name " to " << _arg); \
942 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
943 { \
944 this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
945 this->Modified(); \
946 } \
947 } \
948 virtualKeyword void Set##name(const SimpleDataObjectDecorator<type> * _arg) finalKeyword \
949 { \
950 this->Set##name##Input(_arg); \
951 } \
952 virtualKeyword void Set##name(const type & _arg) finalKeyword \
953 { \
954 using DecoratorType = SimpleDataObjectDecorator<type>; \
955 itkDebugMacro("setting input " #name " to " << _arg); \
956 const DecoratorType * oldInput = \
957 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
958 ITK_GCC_PRAGMA_PUSH \
959 ITK_GCC_SUPPRESS_Wfloat_equal \
960 if (oldInput && oldInput->Get() == _arg) \
961 { \
962 return; \
963 } \
964 ITK_GCC_PRAGMA_POP \
965 auto newInput = DecoratorType::New(); \
966 newInput->Set(_arg); \
967 this->Set##name##Input(newInput); \
968 } \
969 ITK_MACROEND_NOOP_STATEMENT
970// clang-format on
971
974#define itkVirtualSetDecoratedInputMacro(name, type) ITK_DETAIL_SetDecoratedInputMacroImpl(virtual, , name, type)
975#define itkFinalSetDecoratedInputMacro(name, type) ITK_DETAIL_SetDecoratedInputMacroImpl(, final, name, type)
976#define itkNonVirtualSetDecoratedInputMacro(name, type) ITK_DETAIL_SetDecoratedInputMacroImpl(, , name, type)
977#define itkSetDecoratedInputMacro(name, type) ITK_DETAIL_SetDecoratedInputMacroImpl(virtual, , name, type)
979
980// Get a decorated input. Defines Get"name"Input() and Get"name"(). Implementation detail; use the public wrappers
981// below.
982#define ITK_DETAIL_GetDecoratedInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
983 virtualKeyword const SimpleDataObjectDecorator<type> * Get##name##Input() const finalKeyword \
984 { \
985 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
986 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
987 } \
988 virtualKeyword const type & Get##name() const finalKeyword \
989 { \
990 itkDebugMacro("Getting input " #name); \
991 using DecoratorType = SimpleDataObjectDecorator<type>; \
992 const DecoratorType * input = \
993 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
994 if (input == nullptr) \
995 { \
996 itkExceptionStringMacro("input" #name " is not set"); \
997 } \
998 return input->Get(); \
999 } \
1000 ITK_MACROEND_NOOP_STATEMENT
1001
1004#define itkVirtualGetDecoratedInputMacro(name, type) ITK_DETAIL_GetDecoratedInputMacroImpl(virtual, , name, type)
1005#define itkFinalGetDecoratedInputMacro(name, type) ITK_DETAIL_GetDecoratedInputMacroImpl(, final, name, type)
1006#define itkNonVirtualGetDecoratedInputMacro(name, type) ITK_DETAIL_GetDecoratedInputMacroImpl(, , name, type)
1007#define itkGetDecoratedInputMacro(name, type) ITK_DETAIL_GetDecoratedInputMacroImpl(virtual, , name, type)
1009
1012#define itkVirtualSetGetDecoratedInputMacro(name, type) \
1013 itkVirtualSetDecoratedInputMacro(name, type); \
1014 itkVirtualGetDecoratedInputMacro(name, type)
1015#define itkFinalSetGetDecoratedInputMacro(name, type) \
1016 itkFinalSetDecoratedInputMacro(name, type); \
1017 itkFinalGetDecoratedInputMacro(name, type)
1018#define itkNonVirtualSetGetDecoratedInputMacro(name, type) \
1019 itkNonVirtualSetDecoratedInputMacro(name, type); \
1020 itkNonVirtualGetDecoratedInputMacro(name, type)
1021#define itkSetGetDecoratedInputMacro(name, type) \
1022 itkSetDecoratedInputMacro(name, type); \
1023 itkGetDecoratedInputMacro(name, type)
1025
1026// Set a decorated itk::Object-derived (non-DataObject) input. Defines Set"name"() and Set"name"Input().
1027// Implementation detail; use the public wrappers below.
1028#define ITK_DETAIL_SetDecoratedObjectInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
1029 virtualKeyword void Set##name##Input(const DataObjectDecorator<type> * _arg) finalKeyword \
1030 { \
1031 itkDebugMacro("setting input " #name " to " << _arg); \
1032 if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
1033 { \
1034 this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
1035 this->Modified(); \
1036 } \
1037 } \
1038 virtualKeyword void Set##name(const type * _arg) finalKeyword \
1039 { \
1040 using DecoratorType = DataObjectDecorator<type>; \
1041 itkDebugMacro("setting input " #name " to " << _arg); \
1042 const DecoratorType * oldInput = \
1043 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
1044 if (oldInput && oldInput->Get() == _arg) \
1045 { \
1046 return; \
1047 } \
1048 auto newInput = DecoratorType::New(); \
1049 newInput->Set(_arg); \
1050 this->Set##name##Input(newInput); \
1051 } \
1052 ITK_MACROEND_NOOP_STATEMENT
1053
1057#define itkVirtualSetDecoratedObjectInputMacro(name, type) \
1058 ITK_DETAIL_SetDecoratedObjectInputMacroImpl(virtual, , name, type)
1059#define itkFinalSetDecoratedObjectInputMacro(name, type) \
1060 ITK_DETAIL_SetDecoratedObjectInputMacroImpl(, final, name, type)
1061#define itkNonVirtualSetDecoratedObjectInputMacro(name, type) \
1062 ITK_DETAIL_SetDecoratedObjectInputMacroImpl(, , name, type)
1063#define itkSetDecoratedObjectInputMacro(name, type) ITK_DETAIL_SetDecoratedObjectInputMacroImpl(virtual, , name, type)
1065
1066// Get a decorated itk::Object-derived (non-DataObject) input. Defines Get"name"() and Get"name"Input().
1067// Implementation detail; use the public wrappers below.
1068#define ITK_DETAIL_GetDecoratedObjectInputMacroImpl(virtualKeyword, finalKeyword, name, type) \
1069 virtualKeyword const DataObjectDecorator<type> * Get##name##Input() const finalKeyword \
1070 { \
1071 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
1072 return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
1073 } \
1074 virtualKeyword const type * Get##name() const finalKeyword \
1075 { \
1076 itkDebugMacro("Getting input " #name); \
1077 using DecoratorType = DataObjectDecorator<type>; \
1078 const DecoratorType * input = \
1079 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
1080 if (input == nullptr) \
1081 { \
1082 return nullptr; \
1083 } \
1084 return input->Get(); \
1085 } \
1086 ITK_MACROEND_NOOP_STATEMENT
1087
1091#define itkVirtualGetDecoratedObjectInputMacro(name, type) \
1092 ITK_DETAIL_GetDecoratedObjectInputMacroImpl(virtual, , name, type)
1093#define itkFinalGetDecoratedObjectInputMacro(name, type) \
1094 ITK_DETAIL_GetDecoratedObjectInputMacroImpl(, final, name, type)
1095#define itkNonVirtualGetDecoratedObjectInputMacro(name, type) \
1096 ITK_DETAIL_GetDecoratedObjectInputMacroImpl(, , name, type)
1097#define itkGetDecoratedObjectInputMacro(name, type) ITK_DETAIL_GetDecoratedObjectInputMacroImpl(virtual, , name, type)
1099
1102#define itkVirtualSetGetDecoratedObjectInputMacro(name, type) \
1103 itkVirtualSetDecoratedObjectInputMacro(name, type); \
1104 itkVirtualGetDecoratedObjectInputMacro(name, type)
1105#define itkFinalSetGetDecoratedObjectInputMacro(name, type) \
1106 itkFinalSetDecoratedObjectInputMacro(name, type); \
1107 itkFinalGetDecoratedObjectInputMacro(name, type)
1108#define itkNonVirtualSetGetDecoratedObjectInputMacro(name, type) \
1109 itkNonVirtualSetDecoratedObjectInputMacro(name, type); \
1110 itkNonVirtualGetDecoratedObjectInputMacro(name, type)
1111#define itkSetGetDecoratedObjectInputMacro(name, type) \
1112 itkSetDecoratedObjectInputMacro(name, type); \
1113 itkGetDecoratedObjectInputMacro(name, type)
1115
1116// Internal Set/Get macro bodies parametrized by the C++ virtual-specifier
1117// (`virtual`) and the trailing virt-specifier (`final`); at most one of
1118// `virtualKeyword`/`finalKeyword` is non-empty. Public variants below:
1119// itkVirtual*, itkFinal*, itkNonVirtual*; legacy itk*Macro forms remain
1120// `virtual` for ABI-stability through ITK v7. No `itkOverride*` variants:
1121// inherit the base member, or write the function by hand when an override
1122// genuinely needs different behavior. Implementation detail; use the public
1123// wrappers below.
1124// clang-format off
1125// Do not invoke ITK_DETAIL_SetMacroImpl directly from user code; use the public wrappers below.
1126#define ITK_DETAIL_SetMacroImpl(virtualKeyword, finalKeyword, name, type) \
1127 virtualKeyword void Set##name(type _arg) finalKeyword \
1128 { \
1129 itkDebugMacro("setting " #name " to " << _arg); \
1130 ITK_GCC_PRAGMA_PUSH \
1131 ITK_GCC_SUPPRESS_Wfloat_equal \
1132 if (this->m_##name != _arg) \
1133 { \
1134 this->m_##name = std::move(_arg); \
1135 this->Modified(); \
1136 } \
1137 ITK_GCC_PRAGMA_POP \
1138 } \
1139 ITK_MACROEND_NOOP_STATEMENT
1140// clang-format on
1141
1142// Do not invoke ITK_DETAIL_GetMacroImpl directly from user code; use the public wrappers below.
1143#define ITK_DETAIL_GetMacroImpl(virtualKeyword, finalKeyword, name, type) \
1144 virtualKeyword type Get##name() finalKeyword { return this->m_##name; } \
1145 ITK_MACROEND_NOOP_STATEMENT
1146
1147// Do not invoke ITK_DETAIL_GetConstMacroImpl directly from user code; use the public wrappers below.
1148#define ITK_DETAIL_GetConstMacroImpl(virtualKeyword, finalKeyword, name, type) \
1149 virtualKeyword type Get##name() const finalKeyword { return this->m_##name; } \
1150 ITK_MACROEND_NOOP_STATEMENT
1151
1152// Do not invoke ITK_DETAIL_GetConstReferenceMacroImpl directly from user code; use the public wrappers below.
1153#define ITK_DETAIL_GetConstReferenceMacroImpl(virtualKeyword, finalKeyword, name, type) \
1154 virtualKeyword const type & Get##name() const finalKeyword { return this->m_##name; } \
1155 ITK_MACROEND_NOOP_STATEMENT
1156
1159#define itkVirtualSetMacro(name, type) ITK_DETAIL_SetMacroImpl(virtual, , name, type)
1160#define itkFinalSetMacro(name, type) ITK_DETAIL_SetMacroImpl(, final, name, type)
1161#define itkNonVirtualSetMacro(name, type) ITK_DETAIL_SetMacroImpl(, , name, type)
1162#define itkSetMacro(name, type) ITK_DETAIL_SetMacroImpl(virtual, , name, type)
1164
1167#define itkVirtualGetMacro(name, type) ITK_DETAIL_GetMacroImpl(virtual, , name, type)
1168#define itkFinalGetMacro(name, type) ITK_DETAIL_GetMacroImpl(, final, name, type)
1169#define itkNonVirtualGetMacro(name, type) ITK_DETAIL_GetMacroImpl(, , name, type)
1170#define itkGetMacro(name, type) ITK_DETAIL_GetMacroImpl(virtual, , name, type)
1172
1177#define itkVirtualGetConstMacro(name, type) ITK_DETAIL_GetConstMacroImpl(virtual, , name, type)
1178#define itkFinalGetConstMacro(name, type) ITK_DETAIL_GetConstMacroImpl(, final, name, type)
1179#define itkNonVirtualGetConstMacro(name, type) ITK_DETAIL_GetConstMacroImpl(, , name, type)
1180#define itkGetConstMacro(name, type) ITK_DETAIL_GetConstMacroImpl(virtual, , name, type)
1182
1188#define itkVirtualGetConstReferenceMacro(name, type) ITK_DETAIL_GetConstReferenceMacroImpl(virtual, , name, type)
1189#define itkFinalGetConstReferenceMacro(name, type) ITK_DETAIL_GetConstReferenceMacroImpl(, final, name, type)
1190#define itkNonVirtualGetConstReferenceMacro(name, type) ITK_DETAIL_GetConstReferenceMacroImpl(, , name, type)
1191#define itkGetConstReferenceMacro(name, type) ITK_DETAIL_GetConstReferenceMacroImpl(virtual, , name, type)
1193// Set an enum-typed member. Creates Set"name"(); avoids itkDebugMacro warnings
1194// on some compilers with non-specified enum types. Implementation detail; use the public wrappers below.
1195#define ITK_DETAIL_SetEnumMacroImpl(virtualKeyword, finalKeyword, name, type) \
1196 virtualKeyword void Set##name(const type _arg) finalKeyword \
1197 { \
1198 itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1199 if (this->m_##name != _arg) \
1200 { \
1201 this->m_##name = _arg; \
1202 this->Modified(); \
1203 } \
1204 } \
1205 ITK_MACROEND_NOOP_STATEMENT
1206
1211#define itkVirtualSetEnumMacro(name, type) ITK_DETAIL_SetEnumMacroImpl(virtual, , name, type)
1212#define itkFinalSetEnumMacro(name, type) ITK_DETAIL_SetEnumMacroImpl(, final, name, type)
1213#define itkNonVirtualSetEnumMacro(name, type) ITK_DETAIL_SetEnumMacroImpl(, , name, type)
1214#define itkSetEnumMacro(name, type) ITK_DETAIL_SetEnumMacroImpl(virtual, , name, type)
1216
1217// Get an enum-typed member. Creates Get"name"(). Implementation detail; use the public wrappers below.
1218#define ITK_DETAIL_GetEnumMacroImpl(virtualKeyword, finalKeyword, name, type) \
1219 virtualKeyword type Get##name() const finalKeyword { return this->m_##name; } \
1220 ITK_MACROEND_NOOP_STATEMENT
1221
1225#define itkVirtualGetEnumMacro(name, type) ITK_DETAIL_GetEnumMacroImpl(virtual, , name, type)
1226#define itkFinalGetEnumMacro(name, type) ITK_DETAIL_GetEnumMacroImpl(, final, name, type)
1227#define itkNonVirtualGetEnumMacro(name, type) ITK_DETAIL_GetEnumMacroImpl(, , name, type)
1228#define itkGetEnumMacro(name, type) ITK_DETAIL_GetEnumMacroImpl(virtual, , name, type)
1230
1231// Set a std::string member from char*/std::string. Creates Set"name"(). Implementation detail; use the public wrappers
1232// below.
1233#define ITK_DETAIL_SetStringMacroImpl(virtualKeyword, finalKeyword, name) \
1234 virtualKeyword void Set##name(const char * _arg) finalKeyword \
1235 { \
1236 if (_arg && (_arg == this->m_##name)) \
1237 { \
1238 return; \
1239 } \
1240 if (_arg) \
1241 { \
1242 this->m_##name = _arg; \
1243 } \
1244 else \
1245 { \
1246 this->m_##name = ""; \
1247 } \
1248 this->Modified(); \
1249 } \
1250 virtualKeyword void Set##name(const std::string & _arg) finalKeyword { this->Set##name(_arg.c_str()); } \
1251 ITK_MACROEND_NOOP_STATEMENT
1252
1256#define itkVirtualSetStringMacro(name) ITK_DETAIL_SetStringMacroImpl(virtual, , name)
1257#define itkFinalSetStringMacro(name) ITK_DETAIL_SetStringMacroImpl(, final, name)
1258#define itkNonVirtualSetStringMacro(name) ITK_DETAIL_SetStringMacroImpl(, , name)
1259#define itkSetStringMacro(name) ITK_DETAIL_SetStringMacroImpl(virtual, , name)
1261
1262// Get a std::string member as const char*. Creates Get"name"(). Implementation detail; use the public wrappers below.
1263#define ITK_DETAIL_GetStringMacroImpl(virtualKeyword, finalKeyword, name) \
1264 virtualKeyword const char * Get##name() const finalKeyword { return this->m_##name.c_str(); } \
1265 ITK_MACROEND_NOOP_STATEMENT
1266
1270#define itkVirtualGetStringMacro(name) ITK_DETAIL_GetStringMacroImpl(virtual, , name)
1271#define itkFinalGetStringMacro(name) ITK_DETAIL_GetStringMacroImpl(, final, name)
1272#define itkNonVirtualGetStringMacro(name) ITK_DETAIL_GetStringMacroImpl(, , name)
1273#define itkGetStringMacro(name) ITK_DETAIL_GetStringMacroImpl(virtual, , name)
1275
1276// clang-format off
1277// Set a value constrained between min/max limits. Creates Set"name"(). Implementation detail; use the public wrappers below.
1278#define ITK_DETAIL_SetClampMacroImpl(virtualKeyword, finalKeyword, name, type, min, max) \
1279 virtualKeyword void Set##name(type _arg) finalKeyword \
1280 { \
1281 const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1282 itkDebugMacro("setting " << #name " to " << _arg); \
1283 ITK_GCC_PRAGMA_PUSH \
1284 ITK_GCC_SUPPRESS_Wfloat_equal \
1285 if (this->m_##name != temp_extrema) \
1286 { \
1287 this->m_##name = temp_extrema; \
1288 this->Modified(); \
1289 } \
1290 ITK_GCC_PRAGMA_POP \
1291 } \
1292 ITK_MACROEND_NOOP_STATEMENT
1293// clang-format on
1294
1298#define itkVirtualSetClampMacro(name, type, min, max) ITK_DETAIL_SetClampMacroImpl(virtual, , name, type, min, max)
1299#define itkFinalSetClampMacro(name, type, min, max) ITK_DETAIL_SetClampMacroImpl(, final, name, type, min, max)
1300#define itkNonVirtualSetClampMacro(name, type, min, max) ITK_DETAIL_SetClampMacroImpl(, , name, type, min, max)
1301#define itkSetClampMacro(name, type, min, max) ITK_DETAIL_SetClampMacroImpl(virtual, , name, type, min, max)
1303
1304// Set object pointer (Object reference-counted). Creates Set"name"(). Implementation detail; use the public wrappers
1305// below.
1306#define ITK_DETAIL_SetObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1307 virtualKeyword void Set##name(type * _arg) finalKeyword \
1308 { \
1309 itkDebugMacro("setting " << #name " to " << _arg); \
1310 if (this->m_##name != _arg) \
1311 { \
1312 this->m_##name = _arg; \
1313 this->Modified(); \
1314 } \
1315 } \
1316 ITK_MACROEND_NOOP_STATEMENT
1317
1321#define itkVirtualSetObjectMacro(name, type) ITK_DETAIL_SetObjectMacroImpl(virtual, , name, type)
1322#define itkFinalSetObjectMacro(name, type) ITK_DETAIL_SetObjectMacroImpl(, final, name, type)
1323#define itkNonVirtualSetObjectMacro(name, type) ITK_DETAIL_SetObjectMacroImpl(, , name, type)
1324#define itkSetObjectMacro(name, type) ITK_DETAIL_SetObjectMacroImpl(virtual, , name, type)
1326// NOTE: A class can use either itkGetModifiableObjectMacro
1327// or itkGetObjectMacro, but not both.
1328// A class can use either itkGetModifiableObjectMacro
1329// or itkGetConstObjectMacro, but not both.
1330// If the desired behavior is to only provide const
1331// access to the itkObject ivar, then use itkGetConstObjectMacro,
1332// else use itkGetModifiableObjectMacro for read/write access to
1333// the ivar.
1334// It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1335// for backwards compatibility.
1336// If the ITK_LEGACY_REMOVE=FALSE, then it is
1337// permissible to use itkGetObjectMacro which
1338// defines both signatures itk::GetXXX() and
1339// itk::GetModifiableXXX()
1340
1341// Get a raw const pointer to an object. Creates Get"name"(). Implementation detail; use the public wrappers below.
1342#define ITK_DETAIL_GetConstObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1343 virtualKeyword const type * Get##name() const finalKeyword { return this->m_##name.GetPointer(); } \
1344 ITK_MACROEND_NOOP_STATEMENT
1345
1349#define itkVirtualGetConstObjectMacro(name, type) ITK_DETAIL_GetConstObjectMacroImpl(virtual, , name, type)
1350#define itkFinalGetConstObjectMacro(name, type) ITK_DETAIL_GetConstObjectMacroImpl(, final, name, type)
1351#define itkNonVirtualGetConstObjectMacro(name, type) ITK_DETAIL_GetConstObjectMacroImpl(, , name, type)
1352#define itkGetConstObjectMacro(name, type) ITK_DETAIL_GetConstObjectMacroImpl(virtual, , name, type)
1354
1355// ITK_DETAIL_GetObjectMacroImpl / ITK_DETAIL_GetModifiableObjectMacroImpl are
1356// implementation details; use the public wrappers below.
1357#if defined(ITK_FUTURE_LEGACY_REMOVE)
1358// In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1359// flag. For now, this very advanced feature is only available
1360// through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1361// ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1362// to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1363// Do not invoke ITK_DETAIL_GetObjectMacroImpl directly from user code; use the public wrappers below.
1364# define ITK_DETAIL_GetObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1365 virtualKeyword type * Get##name() finalKeyword \
1366 { \
1367 purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1368 } \
1369 ITK_MACROEND_NOOP_STATEMENT
1370
1371// Do not invoke ITK_DETAIL_GetModifiableObjectMacroImpl directly from user code; use the public wrappers below.
1372# define ITK_DETAIL_GetModifiableObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1373 virtualKeyword type * GetModifiable##name() finalKeyword { return this->m_##name.GetPointer(); } \
1374 ITK_DETAIL_GetConstObjectMacroImpl(virtualKeyword, finalKeyword, name, type)
1375
1376#else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1377// Get a raw pointer to an object. Creates Get"name"(). Implementation detail; use the public wrappers below.
1378# define ITK_DETAIL_GetObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1379 virtualKeyword type * Get##name() finalKeyword { return this->m_##name.GetPointer(); } \
1380 ITK_MACROEND_NOOP_STATEMENT
1381
1382// Do not invoke ITK_DETAIL_GetModifiableObjectMacroImpl directly from user code; use the public wrappers below.
1383# define ITK_DETAIL_GetModifiableObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1384 virtualKeyword type * GetModifiable##name() finalKeyword { return this->m_##name.GetPointer(); } \
1385 ITK_DETAIL_GetConstObjectMacroImpl(virtualKeyword, finalKeyword, name, type); \
1386 ITK_DETAIL_GetObjectMacroImpl(virtualKeyword, finalKeyword, name, type)
1387#endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1388
1394#define itkVirtualGetObjectMacro(name, type) ITK_DETAIL_GetObjectMacroImpl(virtual, , name, type)
1395#define itkFinalGetObjectMacro(name, type) ITK_DETAIL_GetObjectMacroImpl(, final, name, type)
1396#define itkNonVirtualGetObjectMacro(name, type) ITK_DETAIL_GetObjectMacroImpl(, , name, type)
1397#define itkGetObjectMacro(name, type) ITK_DETAIL_GetObjectMacroImpl(virtual, , name, type)
1398
1399#define itkVirtualGetModifiableObjectMacro(name, type) ITK_DETAIL_GetModifiableObjectMacroImpl(virtual, , name, type)
1400#define itkFinalGetModifiableObjectMacro(name, type) ITK_DETAIL_GetModifiableObjectMacroImpl(, final, name, type)
1401#define itkNonVirtualGetModifiableObjectMacro(name, type) ITK_DETAIL_GetModifiableObjectMacroImpl(, , name, type)
1402#define itkGetModifiableObjectMacro(name, type) ITK_DETAIL_GetModifiableObjectMacroImpl(virtual, , name, type)
1404
1405// For backwards compatibility define ITK_EXPORT to nothing
1406#define ITK_EXPORT
1407
1408
1409// Get a const reference to a smart pointer to an object. Creates Get"name"(). Implementation detail; use the public
1410// wrappers below.
1411#define ITK_DETAIL_GetConstReferenceObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1412 virtualKeyword const typename type::Pointer & Get##name() const finalKeyword { return this->m_##name; } \
1413 ITK_MACROEND_NOOP_STATEMENT
1414
1418#define itkVirtualGetConstReferenceObjectMacro(name, type) \
1419 ITK_DETAIL_GetConstReferenceObjectMacroImpl(virtual, , name, type)
1420#define itkFinalGetConstReferenceObjectMacro(name, type) \
1421 ITK_DETAIL_GetConstReferenceObjectMacroImpl(, final, name, type)
1422#define itkNonVirtualGetConstReferenceObjectMacro(name, type) \
1423 ITK_DETAIL_GetConstReferenceObjectMacroImpl(, , name, type)
1424#define itkGetConstReferenceObjectMacro(name, type) ITK_DETAIL_GetConstReferenceObjectMacroImpl(virtual, , name, type)
1426
1427// Set a const object pointer (Object reference-counted). Creates Set"name"(). Implementation detail; use the public
1428// wrappers below.
1429#define ITK_DETAIL_SetConstObjectMacroImpl(virtualKeyword, finalKeyword, name, type) \
1430 virtualKeyword void Set##name(const type * _arg) finalKeyword \
1431 { \
1432 itkDebugMacro("setting " << #name " to " << _arg); \
1433 if (this->m_##name != _arg) \
1434 { \
1435 this->m_##name = _arg; \
1436 this->Modified(); \
1437 } \
1438 } \
1439 ITK_MACROEND_NOOP_STATEMENT
1440
1444#define itkVirtualSetConstObjectMacro(name, type) ITK_DETAIL_SetConstObjectMacroImpl(virtual, , name, type)
1445#define itkFinalSetConstObjectMacro(name, type) ITK_DETAIL_SetConstObjectMacroImpl(, final, name, type)
1446#define itkNonVirtualSetConstObjectMacro(name, type) ITK_DETAIL_SetConstObjectMacroImpl(, , name, type)
1447#define itkSetConstObjectMacro(name, type) ITK_DETAIL_SetConstObjectMacroImpl(virtual, , name, type)
1449// Create "name"On()/"name"Off(). Requires a Set method. Implementation detail; use the public wrappers below.
1450#define ITK_DETAIL_BooleanMacroImpl(virtualKeyword, finalKeyword, name) \
1451 virtualKeyword void name##On() finalKeyword { this->Set##name(true); } \
1452 virtualKeyword void name##Off() finalKeyword { this->Set##name(false); } \
1453 ITK_MACROEND_NOOP_STATEMENT
1454
1458#define itkVirtualBooleanMacro(name) ITK_DETAIL_BooleanMacroImpl(virtual, , name)
1459#define itkFinalBooleanMacro(name) ITK_DETAIL_BooleanMacroImpl(, final, name)
1460#define itkNonVirtualBooleanMacro(name) ITK_DETAIL_BooleanMacroImpl(, , name)
1461#define itkBooleanMacro(name) ITK_DETAIL_BooleanMacroImpl(virtual, , name)
1463
1472template <typename MemberContainerType, typename CopyFromValueType, typename LoopEndType>
1473bool
1474ContainerFillWithCheck(MemberContainerType & m, const CopyFromValueType & c, const LoopEndType N)
1475{
1476 bool value_updated = false;
1477 for (unsigned int i = 0; i < N; ++i)
1478 {
1479 ITK_GCC_PRAGMA_PUSH
1480 ITK_GCC_SUPPRESS_Wfloat_equal
1481 if (m[i] != c)
1482 {
1483 m[i] = c;
1484 value_updated = true;
1485 }
1486 ITK_GCC_PRAGMA_POP
1487 }
1488 return value_updated;
1489}
1490
1499template <typename MemberContainerType, typename CopyFromContainerType, typename LoopEndType>
1500bool
1501ContainerCopyWithCheck(MemberContainerType & m, const CopyFromContainerType & c, const LoopEndType N)
1502{
1503 bool value_updated = false;
1504 for (LoopEndType i = 0; i < N; ++i)
1505 {
1506 ITK_GCC_PRAGMA_PUSH
1507 ITK_GCC_SUPPRESS_Wfloat_equal
1508 if (m[i] != c[i])
1509 {
1510 m[i] = c[i];
1511 value_updated = true;
1512 }
1513 ITK_GCC_PRAGMA_POP
1514 }
1515 return value_updated;
1516}
1517
1518// clang-format off
1519// Copy `count` values into the object. Creates Set"name"(). Implementation detail; use the public wrappers below.
1520#define ITK_DETAIL_SetVectorMacroImpl(virtualKeyword, finalKeyword, name, type, count) \
1521 virtualKeyword void Set##name(type data[]) finalKeyword \
1522 { \
1523 if (ContainerCopyWithCheck(this->m_##name, data, count)) \
1524 { \
1525 this->Modified(); \
1526 } \
1527 } \
1528 ITK_MACROEND_NOOP_STATEMENT
1529// clang-format on
1530
1535#define itkVirtualSetVectorMacro(name, type, count) ITK_DETAIL_SetVectorMacroImpl(virtual, , name, type, count)
1536#define itkFinalSetVectorMacro(name, type, count) ITK_DETAIL_SetVectorMacroImpl(, final, name, type, count)
1537#define itkNonVirtualSetVectorMacro(name, type, count) ITK_DETAIL_SetVectorMacroImpl(, , name, type, count)
1538#define itkSetVectorMacro(name, type, count) ITK_DETAIL_SetVectorMacroImpl(virtual, , name, type, count)
1540
1541// Return pointer to type (array of type), for efficiency. Creates Get"name"(). Implementation detail; use the public
1542// wrappers below.
1543#define ITK_DETAIL_GetVectorMacroImpl(virtualKeyword, finalKeyword, name, type, count) \
1544 virtualKeyword type * Get##name() const finalKeyword { return this->m_##name; } \
1545 ITK_MACROEND_NOOP_STATEMENT
1546
1549#define itkVirtualGetVectorMacro(name, type, count) ITK_DETAIL_GetVectorMacroImpl(virtual, , name, type, count)
1550#define itkFinalGetVectorMacro(name, type, count) ITK_DETAIL_GetVectorMacroImpl(, final, name, type, count)
1551#define itkNonVirtualGetVectorMacro(name, type, count) ITK_DETAIL_GetVectorMacroImpl(, , name, type, count)
1552#define itkGetVectorMacro(name, type, count) ITK_DETAIL_GetVectorMacroImpl(virtual, , name, type, count)
1554
1559#define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1560
1567#define itkGPUKernelMacro(kernel) \
1568 kernel \
1569 { \
1570 public: \
1571 ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1572 kernel() = delete; \
1573 ~kernel() = delete; \
1574 static const char * GetOpenCLSource(); \
1575 }
1577#define itkGetOpenCLSourceFromKernelMacro(kernel) \
1578 static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); } \
1579 ITK_MACROEND_NOOP_STATEMENT
1580
1581// A useful macro in the PrintSelf method for printing member variables
1582// which are pointers to object based on the LightObject class.
1583#define itkPrintSelfObjectMacro(name) \
1584 if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1585 { \
1586 os << indent << #name << ": (null)" << std::endl; \
1587 } \
1588 else \
1589 { \
1590 os << indent << #name << ": " << std::endl; \
1591 this->m_##name->Print(os, indent.GetNextIndent()); \
1592 } \
1593 ITK_MACROEND_NOOP_STATEMENT
1594
1595
1596// A useful macro in the PrintSelf method for printing boolean member
1597// variables.
1598#define itkPrintSelfBooleanMacro(name) \
1599 os << indent << #name << ": " << (this->m_##name ? "On" : "Off") << std::endl; \
1600 ITK_MACROEND_NOOP_STATEMENT
1601
1602
1603// Set a decorated output. Defines Set"name"Output() and Set"name"(value). Implementation detail; use the public
1604// wrappers below.
1605#define ITK_DETAIL_SetDecoratedOutputMacroImpl(virtualKeyword, finalKeyword, name, type) \
1606 virtualKeyword void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) finalKeyword \
1607 { \
1608 itkDebugMacro("setting output " #name " to " << _arg); \
1609 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1610 { \
1611 this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1612 this->Modified(); \
1613 } \
1614 } \
1615 virtualKeyword void Set##name(const type & _arg) finalKeyword \
1616 { \
1617 using DecoratorType = SimpleDataObjectDecorator<type>; \
1618 itkDebugMacro("setting output " #name " to " << _arg); \
1619 DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1620 if (output) \
1621 { \
1622 if (output->Get() == _arg) \
1623 { \
1624 return; \
1625 } \
1626 else \
1627 { \
1628 output->Set(_arg); \
1629 } \
1630 } \
1631 else \
1632 { \
1633 auto newOutput = DecoratorType::New(); \
1634 newOutput->Set(_arg); \
1635 this->Set##name##Output(newOutput); \
1636 } \
1637 } \
1638 ITK_MACROEND_NOOP_STATEMENT
1639
1642#define itkVirtualSetDecoratedOutputMacro(name, type) ITK_DETAIL_SetDecoratedOutputMacroImpl(virtual, , name, type)
1643#define itkFinalSetDecoratedOutputMacro(name, type) ITK_DETAIL_SetDecoratedOutputMacroImpl(, final, name, type)
1644#define itkNonVirtualSetDecoratedOutputMacro(name, type) ITK_DETAIL_SetDecoratedOutputMacroImpl(, , name, type)
1645#define itkSetDecoratedOutputMacro(name, type) ITK_DETAIL_SetDecoratedOutputMacroImpl(virtual, , name, type)
1647
1648// Get a decorated output. Defines Get"name"Output() and Get"name"(). Implementation detail; use the public wrappers
1649// below.
1650#define ITK_DETAIL_GetDecoratedOutputMacroImpl(virtualKeyword, finalKeyword, name, type) \
1651 virtualKeyword const SimpleDataObjectDecorator<type> * Get##name##Output() const finalKeyword \
1652 { \
1653 itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1654 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1655 } \
1656 virtualKeyword const type & Get##name() const finalKeyword \
1657 { \
1658 itkDebugMacro("Getting output " #name); \
1659 using DecoratorType = SimpleDataObjectDecorator<type>; \
1660 const DecoratorType * output = \
1661 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1662 if (output == nullptr) \
1663 { \
1664 itkExceptionStringMacro("output" #name " is not set"); \
1665 } \
1666 return output->Get(); \
1667 } \
1668 ITK_MACROEND_NOOP_STATEMENT
1669
1672#define itkVirtualGetDecoratedOutputMacro(name, type) ITK_DETAIL_GetDecoratedOutputMacroImpl(virtual, , name, type)
1673#define itkFinalGetDecoratedOutputMacro(name, type) ITK_DETAIL_GetDecoratedOutputMacroImpl(, final, name, type)
1674#define itkNonVirtualGetDecoratedOutputMacro(name, type) ITK_DETAIL_GetDecoratedOutputMacroImpl(, , name, type)
1675#define itkGetDecoratedOutputMacro(name, type) ITK_DETAIL_GetDecoratedOutputMacroImpl(virtual, , name, type)
1677// ITK_FUTURE_DEPRECATED is only for internal use, within the implementation of ITK. It allows triggering "deprecated"
1678// warnings when legacy support is removed, which warn that a specific feature may be removed in the future.
1679#if defined(ITK_LEGACY_REMOVE) && !defined(ITK_LEGACY_SILENT)
1680# define ITK_FUTURE_DEPRECATED(message) [[deprecated(message)]]
1681#else
1682# define ITK_FUTURE_DEPRECATED(message)
1683#endif
1684
1685#if __cplusplus >= 202002L
1686# define ITK_NODISCARD(message) [[nodiscard(message)]]
1687#else
1688# define ITK_NODISCARD(message) [[nodiscard]]
1689#endif
1690
1691//-*-*-*
1692
1693#if defined(ITK_LEGACY_REMOVE)
1694# define itkExposeEnumValue(name) \
1695 static_assert(false, "ERROR: Replace static_cast<int>(name) with with proper enumeration instead of integer")
1696
1697# define ITK_NOEXCEPT_OR_THROW static_assert(false, "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT")
1698
1699# define ITK_DELETE_FUNCTION static_assert(false, "ERROR: ITK_DELETE_FUNCTION must be replaced with `= delete`"
1700# define ITK_CONSTEXPR_FUNC static_assert(false, "ERROR: ITK_CONSTEXPR_FUNC must be replaced with 'constexpr'")
1701# define ITK_CONSTEXPR_VAR static_assert(false, "ERROR: ITK_CONSTEXPR_VAR must be replaced with 'constexpr'")
1702
1703# define ITK_FALLTHROUGH static_assert(false, "ERROR: ITK_FALLTHROUGH must be replaced with '[[fallthrough]]'")
1704
1705// Defines which used to be in itk_compiler_detection.h
1706# define ITK_ALIGNAS static_assert(false, "ERROR: ITK_ALIGNAS must be replaced with 'alignas'")
1707# define ITK_ALIGNOF static_assert(false, "ERROR: ITK_ALIGNOF must be replaced with 'alignof'")
1708# define ITK_DEPRECATED static_assert(false, "ERROR: ITK_DEPRECATED must be replaced with '[[deprecated]]'")
1709# define ITK_DEPRECATED_MSG \
1710 static_assert(false, "ERROR: ITK_DEPRECATED_MSG must be replaced with '[[deprecated(MSG)]]'")
1711# define ITK_CONSTEXPR static_assert(false, "ERROR: ITK_CONSTEXPR must be replaced with 'constexpr'")
1712# define ITK_DELETED_FUNCTION static_assert(false, "ERROR: ITK_DELETED_FUNCTION must be replaced with '= delete'")
1713# define ITK_EXTERN_TEMPLATE static_assert(false, "ERROR: ITK_EXTERN_TEMPLATE must be replaced with 'extern'")
1714# define ITK_FINAL static_assert(false, "ERROR: ITK_FINAL must be replaced with 'final'")
1715# define ITK_NOEXCEPT static_assert(false, "ERROR: ITK_NOEXCEPT must be replaced with 'noexcept'")
1716# define ITK_NOEXCEPT_EXPR static_assert(false, "ERROR: ITK_NOEXCEPT_EXPR must be replaced with 'noexcept'")
1717# define ITK_NULLPTR static_assert(false, "ERROR: ITK_NULLPTR must be replaced with 'nullptr'")
1718# define ITK_OVERRIDE static_assert(false, "ERROR: ITK_OVERRIDE must be replaced with 'override'")
1719# define ITK_STATIC_ASSERT static_assert(false, "ERROR: ITK_STATIC_ASSERT must be replaced with 'static_assert'")
1720# define ITK_STATIC_ASSERT_MSG \
1721 static_assert(false, "ERROR: ITK_STATIC_ASSERT_MSG must be replaced with 'static_assert'")
1722# define ITK_THREAD_LOCAL static_assert(false, "ERROR: ITK_THREAD_LOCAL must be replaced with 'thread_local'")
1723
1724// A macro for methods which are const in ITKv5 and ITKv6 require const for functions
1725# define ITKv5_CONST static_assert(false, "ERROR: ITKv5_CONST must be replaced with 'const'")
1726
1727# define ITK_ITERATOR_VIRTUAL static_assert(false, "ERROR: ITK_ITERATOR_VIRTUAL must be removed'")
1728# define ITK_ITERATOR_OVERRIDE static_assert(false, "ERROR: ITK_ITERATOR_OVERRIDE must be removed")
1729# define ITK_ITERATOR_FINAL static_assert(false, "ERROR: ITK_ITERATOR_FINAL must be removed")
1730
1731#else
1732// DEPRECATED: These macros are left here for compatibility with remote modules.
1733// Once they have been removed from all known remote modules, this code should
1734// be removed.
1735
1736// Future remove `#define itkExposeEnumValue(name)`
1737// "Replace type of `name` with proper enumeration instead of integer.
1738# define itkExposeEnumValue(name) static_cast<int>(name)
1739
1740
1741# define ITK_NOEXCEPT_OR_THROW ITK_NOEXCEPT
1742
1743# define ITK_FALLTHROUGH [[fallthrough]]
1744
1745# define ITK_DELETE_FUNCTION = delete
1746
1747# define ITK_CONSTEXPR_FUNC constexpr
1748# define ITK_CONSTEXPR_VAR constexpr
1749
1750// Defines which used to be in itk_compiler_detection.h
1751# define ITK_ALIGNAS(X) alignas(X)
1752# define ITK_ALIGNOF(X) alignof(X)
1753# define ITK_DEPRECATED [[deprecated]]
1754# define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1755# define ITK_CONSTEXPR constexpr
1756# define ITK_DELETED_FUNCTION = delete
1757# define ITK_EXTERN_TEMPLATE extern
1758# define ITK_FINAL final
1759# define ITK_NOEXCEPT noexcept
1760# define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1761# define ITK_NULLPTR nullptr
1762# define ITK_OVERRIDE override
1763# define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1764# define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1765# define ITK_THREAD_LOCAL thread_local
1766
1767// A macro for methods which are const in after ITKv4
1768# define ITKv5_CONST const
1769
1770# define ITK_ITERATOR_VIRTUAL /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1771# define ITK_ITERATOR_OVERRIDE /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1772# define ITK_ITERATOR_FINAL /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1773#endif
1774
1775#define allow_inclusion_of_itkExceptionObject_h
1776// Must include itkExceptionObject.h at the end of the file
1777// because it depends on the macros defined above
1778#include "itkExceptionObject.h"
1779
1780
1781#undef allow_inclusion_of_itkExceptionObject_h
1782
1783
1784#include "itkPrintHelper.h"
1785#endif // itkMacro_h
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....