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# include "itkPrintHelper.h" // for ostream operator<<std::vector<T>
52#endif
53
54#include <sstream>
55#include <type_traits> // For is_same, remove_const, and remove_reference.
56
61namespace itk
62{
63// end namespace itk - this is here for documentation purposes
64}
65
68#define itkNotUsed(x)
69
70// clang-format off
81#define ITK_NOOP_STATEMENT static_assert(true, "")
82
83/* NOTE: The ITK_MACROEND_NOOP_STATEMENT is used at the end
84 * of ITK supported macros to ensure that when the macro
85 * is used in the code base that the line must have ';' after
86 * the macro is used. This makes formatting visually similar
87 * to functions, and greatly improves the clang-format
88 * behaviors for indentation. This also assists
89 * modern IDE's and removes 1000's of warnings about
90 * unused statements or unnecessary ';' when macros are
91 * used. */
92#define ITK_MACROEND_NOOP_STATEMENT ITK_NOOP_STATEMENT
93// clang-format on
94
95// Define ITK_PRAGMA macro.
96//
97// It sets "#pragma" preprocessor directives without expecting the arguments
98// to be quoted.
99#define ITK_PRAGMA(x) _Pragma(#x)
100
101// The GCC/Clang compilers have many useful non-default compiler warnings
102// that tend to have a high false positive rate or are otherwise not always appropriate.
103// The following set of defines allows us to suppress instances of said warnings.
104
105// For GCC and Clang (Clang also identifies itself as GCC, and supports these pragmas):
106#if defined(__GNUC__)
107# define ITK_GCC_PRAGMA_PUSH ITK_PRAGMA(GCC diagnostic push)
108# define ITK_GCC_PRAGMA_POP ITK_PRAGMA(GCC diagnostic pop)
109# define ITK_GCC_SUPPRESS_Wfloat_equal ITK_PRAGMA(GCC diagnostic ignored "-Wfloat-equal")
110# define ITK_GCC_SUPPRESS_Wformat_nonliteral ITK_PRAGMA(GCC diagnostic ignored "-Wformat-nonliteral")
111# define ITK_GCC_SUPPRESS_Warray_bounds ITK_PRAGMA(GCC diagnostic ignored "-Warray-bounds")
112#else
113# define ITK_GCC_PRAGMA_PUSH
114# define ITK_GCC_PRAGMA_POP
115# define ITK_GCC_SUPPRESS_Wfloat_equal
116# define ITK_GCC_SUPPRESS_Wformat_nonliteral
117# define ITK_GCC_SUPPRESS_Warray_bounds
118#endif
119
120// For Clang only (and not GCC):
121#if defined(__clang__) && defined(__has_warning)
122# define ITK_CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
123# define ITK_CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
124# define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant \
125 ITK_PRAGMA(clang diagnostic ignored "-Wzero-as-null-pointer-constant")
126#else
127# define ITK_CLANG_PRAGMA_PUSH
128# define ITK_CLANG_PRAGMA_POP
129# define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant
130#endif
131
132// These were not intended as public API, but some code was nevertheless using them.
133// Support the pre ITK 5.4 spelling for compatibility.
134#define CLANG_PRAGMA_PUSH ITK_CLANG_PRAGMA_PUSH
135#define CLANG_PRAGMA_POP ITK_CLANG_PRAGMA_POP
136#define CLANG_SUPPRESS_Wfloat_equal ITK_GCC_SUPPRESS_Wfloat_equal
137
138#if !defined(ITK_LEGACY_REMOVE)
139// Issue warning if deprecated preprocessor flag is used.
140# define CLANG_SUPPRESS_Wcpp14_extensions \
141 [[deprecated("Remove deprecated CLANG_SUPPRESS_Wcpp14_extensions c++14 warning suppression")]] void * \
142 CLANG_SUPPRESS_Wcpp14_extensions = nullptr;
143#endif
144
145// Intel compiler convenience macros
146#if defined(__INTEL_COMPILER)
147# define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
148# define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
149# define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
150#else
151# define INTEL_PRAGMA_WARN_PUSH
152# define INTEL_PRAGMA_WARN_POP
153# define INTEL_SUPPRESS_warning_1292
154#endif
155
156// Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
157//
158// This macro sets a pragma diagnostic
159//
160// Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
161//
162// These macros respectively push and pop the diagnostic context
163//
164#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
165# define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
166# define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
167# define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
168#else
169# define ITK_GCC_PRAGMA_DIAG(x)
170# define ITK_GCC_PRAGMA_DIAG_PUSH()
171# define ITK_GCC_PRAGMA_DIAG_POP()
172#endif
173
174/*
175 * ITK only supports MSVC++ 14.2 and greater
176 * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
177 */
178#if defined(_MSC_VER) && (_MSC_VER < 1920)
179# error "MSVC versions before Visual Studio 2019 are not supported"
180#endif
181#if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
182# error "SUNPro C++ < 5.14.0 is not supported"
183#endif
184#if defined(__CYGWIN__)
185# error "The Cygwin compiler is not supported"
186#endif
187#if defined(__BORLANDC__)
188# error "The Borland C compiler is not supported"
189#endif
190#if defined(__MWERKS__)
191# error "The MetroWerks compiler is not supported"
192#endif
193#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7)
194# error "GCC < 7 is not supported"
195#endif
196#if defined(__sgi)
197// This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
198// TODO: At some future point, it may be necessary to
199// define a minimum __sgi version that will work.
200# error "The SGI compiler is not supported"
201#endif
202#if defined(__APPLE__)
203# if defined(__clang__) && (__cplusplus < 201703L)
204# error "Apple LLVM compiling with a standard less than C++17 is not supported"
205# endif
206#elif defined(__clang__) && (__clang_major__ < 5)
207# error "Clang < 5 is not supported"
208#endif
209#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910)
210# error "Intel C++ < 19.1 is not supported4"
211#endif
212
213// Setup symbol exports
214#if defined(_WIN32) || defined(WIN32)
215# define ITK_ABI_IMPORT __declspec(dllimport)
216# define ITK_ABI_EXPORT __declspec(dllexport)
217# define ITK_ABI_HIDDEN
218#else
219# ifdef __GNUC__
220# define ITK_ABI_IMPORT __attribute__((visibility("default")))
221# define ITK_ABI_EXPORT __attribute__((visibility("default")))
222# define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
223# else
224# define ITK_ABI_IMPORT
225# define ITK_ABI_EXPORT
226# define ITK_ABI_HIDDEN
227# endif
228#endif
229
230// Setup symbol exports
231#ifndef ITK_TEMPLATE_EXPORT
232# ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
233# define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
234# else
235# define ITK_TEMPLATE_EXPORT
236# endif
237#endif
238
239// Setup symbol exports
240#ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
241# define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
242#else
243# define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
244#endif
245
246#ifndef ITK_FORWARD_EXPORT
247// If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
248# if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
249 defined(USE_COMPILER_HIDDEN_VISIBILITY)
250# define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
251# else
252# define ITK_FORWARD_EXPORT
253# endif
254#endif
255
256
278#define itkNewMacro(x) \
279 itkSimpleNewMacro(x); \
280 itkCreateAnotherMacro(x); \
281 itkCloneMacro(x); \
282 ITK_MACROEND_NOOP_STATEMENT
284#define itkSimpleNewMacro(x) \
285 static Pointer New() \
286 { \
287 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
288 if (smartPtr == nullptr) \
289 { \
290 smartPtr = new x(); \
291 } \
292 smartPtr->UnRegister(); \
293 return smartPtr; \
294 } \
295 ITK_MACROEND_NOOP_STATEMENT
296
297#define itkCreateAnotherMacro(x) \
298 ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
299 ITK_MACROEND_NOOP_STATEMENT
300
301#define itkCloneMacro(x) \
302 Pointer Clone() const \
303 { \
304 Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
305 return rval; \
306 } \
307 ITK_MACROEND_NOOP_STATEMENT
308
313#define itkFactoryOnlyNewMacro(x) \
314 itkSimpleFactoryOnlyNewMacro(x); \
315 itkCreateAnotherMacro(x); \
316 itkCloneMacro(x); \
317 ITK_MACROEND_NOOP_STATEMENT
319#define itkSimpleFactoryOnlyNewMacro(x) \
320 static auto New() -> Pointer \
321 { \
322 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
323 if (smartPtr == nullptr) \
324 { \
325 itkSpecializedMessageExceptionMacro(ExceptionObject, \
326 "Object factory failed to instantiate " << typeid(x).name()); \
327 } \
328 smartPtr->UnRegister(); \
329 return smartPtr; \
330 } \
331 ITK_MACROEND_NOOP_STATEMENT
332
346#define itkFactorylessNewMacro(x) \
347 static Pointer New() \
348 { \
349 auto * rawPtr = new x(); \
350 Pointer smartPtr = rawPtr; \
351 rawPtr->UnRegister(); \
352 return smartPtr; \
353 } \
354 itkCreateAnotherMacro(x); \
355 ITK_MACROEND_NOOP_STATEMENT
357//
358// A macro to disallow the copy constructor, copy assignment,
359// move constructor, and move assignment functions.
360// This should be used in the public: declarations for a class
361//
362// ITK's paradigm for smart pointer and pipeline consistency
363// prohibits the use of copy/move construction and copy/move assignment
364// functions.
365//
366#define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
367 TypeName(const TypeName &) = delete; \
368 TypeName & operator=(const TypeName &) = delete; \
369 TypeName(TypeName &&) = delete; \
370 TypeName & operator=(TypeName &&) = delete
371
372#if !defined(ITK_LEGACY_REMOVE)
373# define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
374#else
375# define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
376 static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
377#endif
378
379
388#define ITK_DEFAULT_COPY_AND_MOVE(TypeName) \
389 TypeName(const TypeName &) = default; \
390 TypeName & operator=(const TypeName &) = default; \
391 TypeName(TypeName &&) = default; \
392 TypeName & operator=(TypeName &&) = default
394
395// When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
396// the ability for operator!= to be rewritten automatically in terms of
397// operator==, as introduced with C++20. This macro is experimental. It may be
398// modified, renamed, or removed without backward compatibility support.
399#if __cplusplus >= 202002L
400# define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
401#endif
402
403// Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
404// is only for internal use within the implementation of ITK. It may be
405// modified, renamed, or removed without backward compatibility support.
406#ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
407// With C++20, operator!= is automatically rewritten in terms of the
408// corresponding operator==.
409# define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
410#else
411// For C++14 and C++17, this macro defines an operator!= member function that
412// just calls the corresponding operator== member function.
413# define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
414 bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
415 ITK_MACROEND_NOOP_STATEMENT
416#endif
417
418
419// Internal macro (not part of the public ITK API), used to implement `GetNameOfClass()` member functions.
420#define itkInternalGetNameOfClassImplementationMacro(thisClass) \
421 { \
422 static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
423 "The macro argument `" #thisClass \
424 "` appears incorrect! It should correspond with the name of this class!"); \
425 return #thisClass; \
426 } \
427 ITK_MACROEND_NOOP_STATEMENT
428
429
433#define itkVirtualGetNameOfClassMacro(thisClass) \
434 virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
435
436#define itkOverrideGetNameOfClassMacro(thisClass) \
437 const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
438
439#ifdef ITK_FUTURE_LEGACY_REMOVE
440# define itkTypeMacro(thisClass, superclass) \
441 static_assert(false, \
442 "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
443 "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
444# define itkTypeMacroNoParent(thisClass) \
445 static_assert(false, \
446 "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
447 "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
448#else
453# define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
454# define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
455#endif
456
457
458namespace itk
459{
467extern ITKCommon_EXPORT void
468OutputWindowDisplayText(const char *);
469
470extern ITKCommon_EXPORT void
471OutputWindowDisplayErrorText(const char *);
472
473extern ITKCommon_EXPORT void
474OutputWindowDisplayWarningText(const char *);
475
476extern ITKCommon_EXPORT void
477OutputWindowDisplayGenericOutputText(const char *);
478
479extern ITKCommon_EXPORT void
480OutputWindowDisplayDebugText(const char *);
482
483} // end namespace itk
484
485// The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
491#if defined(NDEBUG)
492# define itkDebugMacro(x) ITK_NOOP_STATEMENT
493# define itkDebugStatement(x) ITK_NOOP_STATEMENT
494#else
495# define itkDebugMacro(x) \
496 { \
497 using namespace ::itk::print_helper; /* for ostream << std::vector<T> */ \
498 if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
499 { \
500 std::ostringstream itkmsg; \
501 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
502 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
503 ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
504 } \
505 } \
506 ITK_MACROEND_NOOP_STATEMENT
507// The itkDebugStatement is to be used to protect code that is only
508// used in the itkDebugMacro
509# define itkDebugStatement(x) x
510#endif
515#define itkWarningMacro(x) \
516 { \
517 if (::itk::Object::GetGlobalWarningDisplay()) \
518 { \
519 std::ostringstream itkmsg; \
520 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << '\n' \
521 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
522 ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
523 } \
524 } \
525 ITK_MACROEND_NOOP_STATEMENT
526
527
528#define itkWarningStatement(x) x
529
530#if defined(ITK_CPP_FUNCTION)
531# if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
532# define ITK_LOCATION __FUNCSIG__
533# elif defined(__GNUC__)
534# define ITK_LOCATION __PRETTY_FUNCTION__
535# else
536# define ITK_LOCATION __FUNCTION__
537# endif
538#else
539# define ITK_LOCATION "unknown"
540#endif
541
542#define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
543 namespace itk \
544 { \
545 class newexcp : public parentexcp \
546 { \
547 public: \
548 /* default message provides backward compatibility for a given exception type */ \
549 static constexpr const char * const default_exception_message = whatmessage; \
550 /* Inherit the constructors from its base class. */ \
551 using parentexcp::parentexcp; \
552 itkOverrideGetNameOfClassMacro(newexcp); \
553 }; \
554 } \
555 ITK_MACROEND_NOOP_STATEMENT
556
557
558#define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
559 { \
560 std::ostringstream exceptionDescriptionOutputStringStream; \
561 exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
562 throw ::itk::ExceptionType( \
563 std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
564 } \
565 ITK_MACROEND_NOOP_STATEMENT
566
567#define itkSpecializedExceptionMacro(ExceptionType) \
568 itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
569
573#define itkExceptionMacro(x) \
574 itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
575
576#define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
577
578#define itkGenericOutputMacro(x) \
579 { \
580 if (::itk::Object::GetGlobalWarningDisplay()) \
581 { \
582 std::ostringstream itkmsg; \
583 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
584 ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
585 } \
586 } \
587 ITK_MACROEND_NOOP_STATEMENT
588
589//----------------------------------------------------------------------------
590// Macros for simplifying the use of logging
591//
592#define itkLogMacro(x, y) \
593 { \
594 if (this->GetLogger()) \
595 { \
596 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
597 } \
598 } \
599 ITK_MACROEND_NOOP_STATEMENT
600
601#define itkLogMacroStatic(obj, x, y) \
602 { \
603 if (obj->GetLogger()) \
604 { \
605 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
606 } \
607 } \
608 ITK_MACROEND_NOOP_STATEMENT
609
610//----------------------------------------------------------------------------
611// Setup legacy code policy.
612//
613// CMake options:
614// - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
615// - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
616// of legacy code will not produce compiler warnings.
617// - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
618// of legacy code will produce compiler warnings
619//
620// ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
621//
622// Source files that test the legacy code may define ITK_LEGACY_TEST
623// like this:
624//
625// #define ITK_LEGACY_TEST
626// #include "itkClassWithDeprecatedMethod.h"
627//
628// in order to silence the warnings for calling deprecated methods.
629// No other source files in ITK should call the methods since they are
630// provided only for compatibility with older user code.
631
632// Define itkLegacyMacro to mark legacy methods where they are
633// declared in their class. Example usage:
634//
635// // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
636// itkLegacyMacro(void MyMethod();)
637//
638// See below for what to do for the method definition.
639#if defined(ITK_LEGACY_REMOVE)
640# define itkLegacyMacro(method) /* no ';' */
641#else
642# if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
643// Provide legacy methods with no warnings.
644# define itkLegacyMacro(method) method /* no ';' */
645# else
646// Request compile-time warnings for uses of deprecated methods.
647# define itkLegacyMacro(method) [[deprecated]] method /* no ';' */
648# endif
649#endif
650
651// Macros to create runtime deprecation warning messages in function
652// bodies. Example usage:
653//
654// #if !defined( ITK_LEGACY_REMOVE )
655// void itkMyClass::MyOldMethod()
656// {
657// itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
658// }
659//
660// void itkMyClass::MyMethod()
661// {
662// itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
663// itkMyClass::MyOtherMethod);
664// }
665// #endif
666//
667// NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
668// itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
669// are purposefully not defined when ITK_LEGACY_REMOVE is on,
670// because these macros are only relevant inside code segments
671// that are conditionally compiled only when ITK_LEGACY_REMOVE
672// is off.
673#if defined(ITK_LEGACY_SILENT)
674# define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
675# define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
676# define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
677# define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
678#else
679# define itkLegacyBodyMacro(method, version) \
680 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
681# define itkLegacyReplaceBodyMacro(method, version, replace) \
682 itkWarningMacro(#method " was deprecated for ITK " #version \
683 " and will be removed in a future version. Use " #replace " instead.")
684# define itkGenericLegacyBodyMacro(method, version) \
685 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
686# define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
687 itkGenericOutputMacro(#method " was deprecated for ITK " #version \
688 " and will be removed in a future version. Use " #replace " instead.")
689#endif
690
691// Most modern x86 CPUs have 64 byte aligned blocks which are used for
692// the cache lines. By aligning multi-threaded structures with the
693// cache lines, false shared can be reduced, and performance
694// increased.
695#define ITK_CACHE_LINE_ALIGNMENT 64
696
697//
698// itkPadStruct will add padding to a structure to ensure a minimum size
699// for ensuring that adjacent structures do not share CACHE lines.
700// Each struct will take up some multiple of cacheline sizes.
701// This is particularly useful for arrays of thread private variables.
702//
703#define itkPadStruct(mincachesize, oldtype, newtype) \
704 struct newtype : public oldtype \
705 { \
706 char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
707 }
708
709//
710// itkAlignedTypedef is a macro which creates a new type to make a
711// data structure aligned.
712//
713#if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
714# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
715#elif defined(_MSC_VER)
716# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
717#else
718# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
719#endif
720
721#if defined(ITK_FUTURE_LEGACY_REMOVE)
722//=============================================================================
723/*
724NOTE: DEPRECATED - This macro is not longer needed to support modern
725compilers.
726
727 Define a common way of declaring a templated function as a friend inside a class.
728 - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
729
730 The following templated function
731
732 template <T>
733 T add(const T & a, const T & b);
734
735 is declared as friend with
736
737 class A
738 {
739 public:
740 friend Self add<>( const Self & a, const Self & b );
741 }
742
743*/
744# define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
745#else // LEGACY_REMOVE
746# define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
747#endif
748
749//--------------------------------------------------------------------------------
750// Helper macros for Template Meta-Programming techniques of for-loops
751// unrolling
752//--------------------------------------------------------------------------------
753
754//--------------------------------------------------------------------------------
755// Macro that generates an unrolled for loop for assigning elements of one array
756// to elements of another array The array are assumed to be of same length
757// (dimension), and this is also assumed to be the value of NumberOfIterations.
758// No verification of size is performed. Casting is performed as part of the
759// assignment, by using the DestinationElementType as the casting type.
760// Source and destination array types must have defined operator[] in their
761// API.
762#define itkForLoopAssignmentMacro( \
763 DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
764 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
765 { \
766 DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
767 } \
768 ITK_MACROEND_NOOP_STATEMENT
769
770//--------------------------------------------------------------------------------
771// Macro that generates an unrolled for loop for rounding and assigning
772// elements of one array to elements of another array The array are assumed to
773// be of same length (dimension), and this is also assumed to be the value of
774// NumberOfIterations. No verification of size is performed. Casting is
775// performed as part of the assignment, by using the DestinationElementType as
776// the casting type.
777// Source and destination array types must have defined operator[] in their
778// API.
779#define itkForLoopRoundingAndAssignmentMacro( \
780 DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
781 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
782 { \
783 DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
784 } \
785 ITK_MACROEND_NOOP_STATEMENT
786
787// end of Template Meta Programming helper macros
788
789#if !defined(NDEBUG) && !defined(ITK_WRAPPING)
790
791# ifdef __GLIBC__
792# define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
793# else
794# define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
795# endif
796
797#else
798# define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
799#endif
800
801#define itkAssertOrThrowMacro(test, message) \
802 if (!(test)) \
803 { \
804 std::ostringstream msgstr; \
805 msgstr << message; \
806 itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
807 } \
808 ITK_MACROEND_NOOP_STATEMENT
809
810#if !defined(NDEBUG) && !defined(ITK_WRAPPING)
811# define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
812#else
813# define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
814#endif
815
816
817// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
818// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
819// !! The ITK Get/Set Macros for various types !!
820// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
821// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
822
823#ifdef ITK_FUTURE_LEGACY_REMOVE
824# define itkStaticConstMacro(name, type, value) \
825 "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
826# define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
827#else
842# define itkStaticConstMacro(name, type, value) static constexpr type name = value
843
844# define itkGetStaticConstMacro(name) (Self::name)
845#endif
846
849#define itkSetInputMacro(name, type) \
850 virtual void Set##name(const type * _arg) \
851 { \
852 itkDebugMacro("setting input " #name " to " << _arg); \
853 if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
854 { \
855 this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
856 this->Modified(); \
857 } \
858 } \
859 ITK_MACROEND_NOOP_STATEMENT
863#define itkGetInputMacro(name, type) \
864 virtual const type * Get##name() const \
865 { \
866 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
867 return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
868 } \
869 ITK_MACROEND_NOOP_STATEMENT
871// clang-format off
874#define itkSetDecoratedInputMacro(name, type) \
875 virtual void Set## name## Input(const SimpleDataObjectDecorator<type> * _arg) \
876 { \
877 itkDebugMacro("setting input " #name " to " << _arg); \
878 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
879 { \
880 this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
881 this->Modified(); \
882 } \
883 } \
884 virtual void Set## name(const SimpleDataObjectDecorator<type> * _arg) { this->Set## name## Input(_arg); } \
885 virtual void Set## name(const type & _arg) \
886 { \
887 using DecoratorType = SimpleDataObjectDecorator<type>; \
888 itkDebugMacro("setting input " #name " to " << _arg); \
889 const DecoratorType * oldInput = \
890 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
891 ITK_GCC_PRAGMA_PUSH \
892 ITK_GCC_SUPPRESS_Wfloat_equal \
893 if (oldInput && oldInput->Get() == _arg) \
894 { \
895 return; \
896 } \
897 ITK_GCC_PRAGMA_POP \
898 auto newInput = DecoratorType::New(); \
899 newInput->Set(_arg); \
900 this->Set## name## Input(newInput); \
901 } \
902 ITK_MACROEND_NOOP_STATEMENT
903// clang-format on
907#define itkGetDecoratedInputMacro(name, type) \
908 virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
909 { \
910 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
911 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
912 } \
913 virtual const type & Get##name() const \
914 { \
915 itkDebugMacro("Getting input " #name); \
916 using DecoratorType = SimpleDataObjectDecorator<type>; \
917 const DecoratorType * input = \
918 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
919 if (input == nullptr) \
920 { \
921 itkExceptionMacro("input" #name " is not set"); \
922 } \
923 return input->Get(); \
924 } \
925 ITK_MACROEND_NOOP_STATEMENT
929#define itkSetGetDecoratedInputMacro(name, type) \
930 itkSetDecoratedInputMacro(name, type); \
931 itkGetDecoratedInputMacro(name, type)
932
938#define itkSetDecoratedObjectInputMacro(name, type) \
939 virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
940 { \
941 itkDebugMacro("setting input " #name " to " << _arg); \
942 if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
943 { \
944 this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
945 this->Modified(); \
946 } \
947 } \
948 virtual void Set##name(const type * _arg) \
949 { \
950 using DecoratorType = DataObjectDecorator<type>; \
951 itkDebugMacro("setting input " #name " to " << _arg); \
952 const DecoratorType * oldInput = \
953 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
954 if (oldInput && oldInput->Get() == _arg) \
955 { \
956 return; \
957 } \
958 auto newInput = DecoratorType::New(); \
959 newInput->Set(_arg); \
960 this->Set##name##Input(newInput); \
961 } \
962 ITK_MACROEND_NOOP_STATEMENT
969#define itkGetDecoratedObjectInputMacro(name, type) \
970 virtual const DataObjectDecorator<type> * Get##name##Input() const \
971 { \
972 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
973 return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
974 } \
975 virtual const type * Get##name() const \
976 { \
977 itkDebugMacro("Getting input " #name); \
978 using DecoratorType = DataObjectDecorator<type>; \
979 const DecoratorType * input = \
980 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
981 if (input == nullptr) \
982 { \
983 return nullptr; \
984 } \
985 return input->Get(); \
986 } \
987 ITK_MACROEND_NOOP_STATEMENT
991#define itkSetGetDecoratedObjectInputMacro(name, type) \
992 itkSetDecoratedObjectInputMacro(name, type); \
993 itkGetDecoratedObjectInputMacro(name, type)
994
996// clang-format off
997#define itkSetMacro(name, type) \
998 virtual void Set## name(type _arg) \
999 { \
1000 itkDebugMacro("setting " #name " to " << _arg); \
1001 ITK_GCC_PRAGMA_PUSH \
1002 ITK_GCC_SUPPRESS_Wfloat_equal \
1003 if (this->m_## name != _arg) \
1004 { \
1005 this->m_## name = std::move(_arg); \
1006 this->Modified(); \
1007 } \
1008 ITK_GCC_PRAGMA_POP \
1009 } \
1010 ITK_MACROEND_NOOP_STATEMENT
1011// clang-format on
1012
1015#define itkGetMacro(name, type) \
1016 virtual type Get##name() { return this->m_##name; } \
1017 ITK_MACROEND_NOOP_STATEMENT
1023#define itkGetConstMacro(name, type) \
1024 virtual type Get##name() const { return this->m_##name; } \
1025 ITK_MACROEND_NOOP_STATEMENT
1032#define itkGetConstReferenceMacro(name, type) \
1033 virtual const type & Get##name() const { return this->m_##name; } \
1034 ITK_MACROEND_NOOP_STATEMENT
1041#define itkSetEnumMacro(name, type) \
1042 virtual void Set##name(const type _arg) \
1043 { \
1044 itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1045 if (this->m_##name != _arg) \
1046 { \
1047 this->m_##name = _arg; \
1048 this->Modified(); \
1049 } \
1050 } \
1051 ITK_MACROEND_NOOP_STATEMENT
1058#define itkGetEnumMacro(name, type) \
1059 virtual type Get##name() const { return this->m_##name; } \
1060 ITK_MACROEND_NOOP_STATEMENT
1066#define itkSetStringMacro(name) \
1067 virtual void Set##name(const char * _arg) \
1068 { \
1069 if (_arg && (_arg == this->m_##name)) \
1070 { \
1071 return; \
1072 } \
1073 if (_arg) \
1074 { \
1075 this->m_##name = _arg; \
1076 } \
1077 else \
1078 { \
1079 this->m_##name = ""; \
1080 } \
1081 this->Modified(); \
1082 } \
1083 virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1084 ITK_MACROEND_NOOP_STATEMENT
1086
1090#define itkGetStringMacro(name) \
1091 virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1092 ITK_MACROEND_NOOP_STATEMENT
1093
1094// clang-format off
1099#define itkSetClampMacro(name, type, min, max) \
1100 virtual void Set## name(type _arg) \
1101 { \
1102 const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1103 itkDebugMacro("setting " << #name " to " << _arg); \
1104 ITK_GCC_PRAGMA_PUSH \
1105 ITK_GCC_SUPPRESS_Wfloat_equal \
1106 if (this->m_## name != temp_extrema) \
1107 { \
1108 this->m_## name = temp_extrema; \
1109 this->Modified(); \
1110 } \
1111 ITK_GCC_PRAGMA_POP \
1112 } \
1113 ITK_MACROEND_NOOP_STATEMENT
1114// clang-format on
1116// clang-format off
1121#define itkSetObjectMacro(name, type) \
1122 virtual void Set## name(type * _arg) \
1123 { \
1124 itkDebugMacro("setting " << #name " to " << _arg); \
1125 if (this->m_## name != _arg) \
1126 { \
1127 this->m_## name = _arg; \
1128 this->Modified(); \
1129 } \
1130 } \
1131 ITK_MACROEND_NOOP_STATEMENT
1132// clang-format on
1142// NOTE: A class can use either itkGetModifiableObjectMacro
1143// or itkGetObjectMacro, but not both.
1144// A class can use either itkGetModifiableObjectMacro
1145// or itkGetConstObjectMacro, but not both.
1146// If the desired behavior is to only provide const
1147// access to the itkObject ivar, then use itkGetConstObjectMacro,
1148// else use itkGetModifiableObjectMacro for read/write access to
1149// the ivar.
1150// It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1151// for backwards compatibility.
1152// If the ITK_LEGACY_REMOVE=FALSE, then it is
1153// permissible to use itkGetObjectMacro which
1154// defines both signatures itk::GetXXX() and
1155// itk::GetModifiableXXX()
1156
1159#define itkGetConstObjectMacro(name, type) \
1160 virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1161 ITK_MACROEND_NOOP_STATEMENT
1162
1163
1164#if defined(ITK_FUTURE_LEGACY_REMOVE)
1165// In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1166// flag. For now, this very advanced feature is only available
1167// through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1168// ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1169// to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1170# define itkGetObjectMacro(name, type) \
1171 virtual type * Get##name() \
1172 { \
1173 purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1174 } \
1175 ITK_MACROEND_NOOP_STATEMENT
1176
1177# define itkGetModifiableObjectMacro(name, type) \
1178 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1179 itkGetConstObjectMacro(name, type)
1180
1181#else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1185# define itkGetObjectMacro(name, type) \
1186 virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1187 ITK_MACROEND_NOOP_STATEMENT
1188# define itkGetModifiableObjectMacro(name, type) \
1189 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1190 itkGetConstObjectMacro(name, type); \
1191 itkGetObjectMacro(name, type)
1193#endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1194
1195// For backwards compatibility define ITK_EXPORT to nothing
1196#define ITK_EXPORT
1197
1198
1201#define itkGetConstReferenceObjectMacro(name, type) \
1202 virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1203 ITK_MACROEND_NOOP_STATEMENT
1204
1209#define itkSetConstObjectMacro(name, type) \
1210 virtual void Set##name(const type * _arg) \
1211 { \
1212 itkDebugMacro("setting " << #name " to " << _arg); \
1213 if (this->m_##name != _arg) \
1214 { \
1215 this->m_##name = _arg; \
1216 this->Modified(); \
1217 } \
1218 } \
1219 ITK_MACROEND_NOOP_STATEMENT
1224#define itkBooleanMacro(name) \
1225 virtual void name##On() { this->Set##name(true); } \
1226 virtual void name##Off() { this->Set##name(false); } \
1227 ITK_MACROEND_NOOP_STATEMENT
1229
1238template <typename MemberContainerType, typename CopyFromValueType, typename LoopEndType>
1239bool
1240ContainerFillWithCheck(MemberContainerType & m, const CopyFromValueType & c, const LoopEndType N)
1241{
1242 bool value_updated = false;
1243 for (unsigned int i = 0; i < N; ++i)
1244 {
1245 ITK_GCC_PRAGMA_PUSH
1246 ITK_GCC_SUPPRESS_Wfloat_equal
1247 if (m[i] != c)
1248 {
1249 m[i] = c;
1250 value_updated = true;
1251 }
1252 ITK_GCC_PRAGMA_POP
1253 }
1254 return value_updated;
1255}
1256
1265template <typename MemberContainerType, typename CopyFromContainerType, typename LoopEndType>
1266bool
1267ContainerCopyWithCheck(MemberContainerType & m, const CopyFromContainerType & c, const LoopEndType N)
1268{
1269 bool value_updated = false;
1270 for (LoopEndType i = 0; i < N; ++i)
1271 {
1272 ITK_GCC_PRAGMA_PUSH
1273 ITK_GCC_SUPPRESS_Wfloat_equal
1274 if (m[i] != c[i])
1275 {
1276 m[i] = c[i];
1277 value_updated = true;
1278 }
1279 ITK_GCC_PRAGMA_POP
1280 }
1281 return value_updated;
1282}
1283
1284// clang-format off
1289#define itkSetVectorMacro(name, type, count) \
1290 virtual void Set## name(type data[]) \
1291 { \
1292 if (ContainerCopyWithCheck( this->m_## name, data, count)) \
1293 { \
1294 this->Modified(); \
1295 } \
1296 } \
1297 ITK_MACROEND_NOOP_STATEMENT
1298// clang-format on
1302#define itkGetVectorMacro(name, type, count) \
1303 virtual type * Get##name() const { return this->m_##name; } \
1304 ITK_MACROEND_NOOP_STATEMENT
1305
1310#define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1311
1318#define itkGPUKernelMacro(kernel) \
1319 kernel \
1320 { \
1321 public: \
1322 ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1323 kernel() = delete; \
1324 ~kernel() = delete; \
1325 static const char * GetOpenCLSource(); \
1326 }
1328#define itkGetOpenCLSourceFromKernelMacro(kernel) \
1329 static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); } \
1330 ITK_MACROEND_NOOP_STATEMENT
1331
1332// A useful macro in the PrintSelf method for printing member variables
1333// which are pointers to object based on the LightObject class.
1334#define itkPrintSelfObjectMacro(name) \
1335 if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1336 { \
1337 os << indent << #name << ": (null)" << std::endl; \
1338 } \
1339 else \
1340 { \
1341 os << indent << #name << ": " << std::endl; \
1342 this->m_##name->Print(os, indent.GetNextIndent()); \
1343 } \
1344 ITK_MACROEND_NOOP_STATEMENT
1345
1346
1347// A useful macro in the PrintSelf method for printing boolean member
1348// variables.
1349#define itkPrintSelfBooleanMacro(name) \
1350 os << indent << #name << ": " << (this->m_##name ? "On" : "Off") << std::endl; \
1351 ITK_MACROEND_NOOP_STATEMENT
1352
1353
1356#define itkSetDecoratedOutputMacro(name, type) \
1357 virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1358 { \
1359 itkDebugMacro("setting output " #name " to " << _arg); \
1360 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1361 { \
1362 this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1363 this->Modified(); \
1364 } \
1365 } \
1366 virtual void Set##name(const type & _arg) \
1367 { \
1368 using DecoratorType = SimpleDataObjectDecorator<type>; \
1369 itkDebugMacro("setting output " #name " to " << _arg); \
1370 DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1371 if (output) \
1372 { \
1373 if (output->Get() == _arg) \
1374 { \
1375 return; \
1376 } \
1377 else \
1378 { \
1379 output->Set(_arg); \
1380 } \
1381 } \
1382 else \
1383 { \
1384 auto newOutput = DecoratorType::New(); \
1385 newOutput->Set(_arg); \
1386 this->Set##name##Output(newOutput); \
1387 } \
1388 } \
1389 ITK_MACROEND_NOOP_STATEMENT
1393#define itkGetDecoratedOutputMacro(name, type) \
1394 virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1395 { \
1396 itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1397 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1398 } \
1399 virtual const type & Get##name() const \
1400 { \
1401 itkDebugMacro("Getting output " #name); \
1402 using DecoratorType = SimpleDataObjectDecorator<type>; \
1403 const DecoratorType * output = \
1404 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1405 if (output == nullptr) \
1406 { \
1407 itkExceptionMacro("output" #name " is not set"); \
1408 } \
1409 return output->Get(); \
1410 } \
1411 ITK_MACROEND_NOOP_STATEMENT
1413// ITK_FUTURE_DEPRECATED is only for internal use, within the implementation of ITK. It allows triggering "deprecated"
1414// warnings when legacy support is removed, which warn that a specific feature may be removed in the future.
1415#if defined(ITK_LEGACY_REMOVE) && !defined(ITK_LEGACY_SILENT)
1416# define ITK_FUTURE_DEPRECATED(message) [[deprecated(message)]]
1417#else
1418# define ITK_FUTURE_DEPRECATED(message)
1419#endif
1420
1421#if __cplusplus >= 202002L
1422# define ITK_NODISCARD(message) [[nodiscard(message)]]
1423#else
1424# define ITK_NODISCARD(message) [[nodiscard]]
1425#endif
1426
1427//-*-*-*
1428
1429#if defined(ITK_LEGACY_REMOVE)
1430# define itkExposeEnumValue(name) \
1431 static_assert(false, "ERROR: Replace static_cast<int>(name) with with proper enumeration instead of integer")
1432
1433# define ITK_NOEXCEPT_OR_THROW static_assert(false, "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT")
1434
1435# define ITK_DELETE_FUNCTION static_assert(false, "ERROR: ITK_DELETE_FUNCTION must be replaced with `= delete`"
1436# define ITK_CONSTEXPR_FUNC static_assert(false, "ERROR: ITK_CONSTEXPR_FUNC must be replaced with 'constexpr'")
1437# define ITK_CONSTEXPR_VAR static_assert(false, "ERROR: ITK_CONSTEXPR_VAR must be replaced with 'constexpr'")
1438
1439# define ITK_FALLTHROUGH static_assert(false, "ERROR: ITK_FALLTHROUGH must be replaced with '[[fallthrough]]'")
1440
1441// Defines which used to be in itk_compiler_detection.h
1442# define ITK_ALIGNAS static_assert(false, "ERROR: ITK_ALIGNAS must be replaced with 'alignas'")
1443# define ITK_ALIGNOF static_assert(false, "ERROR: ITK_ALIGNOF must be replaced with 'alignof'")
1444# define ITK_DEPRECATED static_assert(false, "ERROR: ITK_DEPRECATED must be replaced with '[[deprecated]]'")
1445# define ITK_DEPRECATED_MSG \
1446 static_assert(false, "ERROR: ITK_DEPRECATED_MSG must be replaced with '[[deprecated(MSG)]]'")
1447# define ITK_CONSTEXPR static_assert(false, "ERROR: ITK_CONSTEXPR must be replaced with 'constexpr'")
1448# define ITK_DELETED_FUNCTION static_assert(false, "ERROR: ITK_DELETED_FUNCTION must be replaced with '= delete'")
1449# define ITK_EXTERN_TEMPLATE static_assert(false, "ERROR: ITK_EXTERN_TEMPLATE must be replaced with 'extern'")
1450# define ITK_FINAL static_assert(false, "ERROR: ITK_FINAL must be replaced with 'final'")
1451# define ITK_NOEXCEPT static_assert(false, "ERROR: ITK_NOEXCEPT must be replaced with 'noexcept'")
1452# define ITK_NOEXCEPT_EXPR static_assert(false, "ERROR: ITK_NOEXCEPT_EXPR must be replaced with 'noexcept'")
1453# define ITK_NULLPTR static_assert(false, "ERROR: ITK_NULLPTR must be replaced with 'nullptr'")
1454# define ITK_OVERRIDE static_assert(false, "ERROR: ITK_OVERRIDE must be replaced with 'override'")
1455# define ITK_STATIC_ASSERT static_assert(false, "ERROR: ITK_STATIC_ASSERT must be replaced with 'static_assert'")
1456# define ITK_STATIC_ASSERT_MSG \
1457 static_assert(false, "ERROR: ITK_STATIC_ASSERT_MSG must be replaced with 'static_assert'")
1458# define ITK_THREAD_LOCAL static_assert(false, "ERROR: ITK_THREAD_LOCAL must be replaced with 'thread_local'")
1459
1460// A macro for methods which are const in ITKv5 and ITKv6 require const for functions
1461# define ITKv5_CONST static_assert(false, "ERROR: ITKv5_CONST must be replaced with 'const'")
1462
1463# define ITK_ITERATOR_VIRTUAL static_assert(false, "ERROR: ITK_ITERATOR_VIRTUAL must be removed'")
1464# define ITK_ITERATOR_OVERRIDE static_assert(false, "ERROR: ITK_ITERATOR_OVERRIDE must be removed")
1465# define ITK_ITERATOR_FINAL static_assert(false, "ERROR: ITK_ITERATOR_FINAL must be removed")
1466
1467#else
1468// DEPRECATED: These macros are left here for compatibility with remote modules.
1469// Once they have been removed from all known remote modules, this code should
1470// be removed.
1471
1472// Future remove `#define itkExposeEnumValue(name)`
1473// "Replace type of `name` with proper enumeration instead of integer.
1474# define itkExposeEnumValue(name) static_cast<int>(name)
1475
1476
1477# define ITK_NOEXCEPT_OR_THROW ITK_NOEXCEPT
1478
1479# define ITK_FALLTHROUGH [[fallthrough]]
1480
1481# define ITK_DELETE_FUNCTION = delete
1482
1483# define ITK_CONSTEXPR_FUNC constexpr
1484# define ITK_CONSTEXPR_VAR constexpr
1485
1486// Defines which used to be in itk_compiler_detection.h
1487# define ITK_ALIGNAS(X) alignas(X)
1488# define ITK_ALIGNOF(X) alignof(X)
1489# define ITK_DEPRECATED [[deprecated]]
1490# define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1491# define ITK_CONSTEXPR constexpr
1492# define ITK_DELETED_FUNCTION = delete
1493# define ITK_EXTERN_TEMPLATE extern
1494# define ITK_FINAL final
1495# define ITK_NOEXCEPT noexcept
1496# define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1497# define ITK_NULLPTR nullptr
1498# define ITK_OVERRIDE override
1499# define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1500# define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1501# define ITK_THREAD_LOCAL thread_local
1502
1503// A macro for methods which are const in after ITKv4
1504# define ITKv5_CONST const
1505
1506# define ITK_ITERATOR_VIRTUAL /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1507# define ITK_ITERATOR_OVERRIDE /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1508# define ITK_ITERATOR_FINAL /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1509#endif
1510
1511#define allow_inclusion_of_itkExceptionObject_h
1512// Must include itkExceptionObject.h at the end of the file
1513// because it depends on the macros defined above
1514#include "itkExceptionObject.h"
1515
1516
1517#undef allow_inclusion_of_itkExceptionObject_h
1518#endif // itkMacro_h
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....