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