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// -Wmaybe-uninitialized is a real-GCC-only warning name; Apple Clang emits
121// -Wunknown-warning-option for it (which ITK's dashboard treats as fatal).
122#if defined(__GNUC__) && !defined(__clang__)
123# define ITK_GCC_SUPPRESS_Wmaybe_uninitialized ITK_PRAGMA(GCC diagnostic ignored "-Wmaybe-uninitialized")
124#else
125# define ITK_GCC_SUPPRESS_Wmaybe_uninitialized
126#endif
127
128// For Clang only (and not GCC):
129#if defined(__clang__) && defined(__has_warning)
130# define ITK_CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
131# define ITK_CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
132# if __has_warning("-Wzero-as-null-pointer-constant")
133# define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant \
134 ITK_PRAGMA(clang diagnostic ignored "-Wzero-as-null-pointer-constant")
135# else
136# define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant
137# endif
138# if __has_warning("-Wduplicate-enum")
139# define ITK_CLANG_SUPPRESS_Wduplicate_enum ITK_PRAGMA(clang diagnostic ignored "-Wduplicate-enum")
140# else
141# define ITK_CLANG_SUPPRESS_Wduplicate_enum
142# endif
143#else
144# define ITK_CLANG_PRAGMA_PUSH
145# define ITK_CLANG_PRAGMA_POP
146# define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant
147# define ITK_CLANG_SUPPRESS_Wduplicate_enum
148#endif
149
150// These were not intended as public API, but some code was nevertheless using them.
151// Support the pre ITK 5.4 spelling for compatibility.
152#define CLANG_PRAGMA_PUSH ITK_CLANG_PRAGMA_PUSH
153#define CLANG_PRAGMA_POP ITK_CLANG_PRAGMA_POP
154#define CLANG_SUPPRESS_Wfloat_equal ITK_GCC_SUPPRESS_Wfloat_equal
155
156// For GCC/Clang, to decorate printf-like functions allowing for compiler checks of format strings.
157#if defined(__GNUC__)
158# define ITK_FORMAT_PRINTF(a, b) __attribute__((format(printf, a, b)))
159#else
160# define ITK_FORMAT_PRINTF(a, b)
161#endif
162
163#if !defined(ITK_LEGACY_REMOVE)
164// Issue warning if deprecated preprocessor flag is used.
165# define CLANG_SUPPRESS_Wcpp14_extensions \
166 [[deprecated("Remove deprecated CLANG_SUPPRESS_Wcpp14_extensions c++14 warning suppression")]] void * \
167 CLANG_SUPPRESS_Wcpp14_extensions = nullptr;
168#endif
169
170// Intel compiler convenience macros
171#if defined(__INTEL_COMPILER)
172# define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
173# define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
174# define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
175#else
176# define INTEL_PRAGMA_WARN_PUSH
177# define INTEL_PRAGMA_WARN_POP
178# define INTEL_SUPPRESS_warning_1292
179#endif
180
181// Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
182//
183// This macro sets a pragma diagnostic
184//
185// Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
186//
187// These macros respectively push and pop the diagnostic context
188//
189#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
190# define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
191# define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
192# define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
193#else
194# define ITK_GCC_PRAGMA_DIAG(x)
195# define ITK_GCC_PRAGMA_DIAG_PUSH()
196# define ITK_GCC_PRAGMA_DIAG_POP()
197#endif
198
199/*
200 * ITK only supports MSVC++ 14.2 and greater
201 * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
202 */
203#if defined(_MSC_VER) && (_MSC_VER < 1920)
204# error "MSVC versions before Visual Studio 2019 are not supported"
205#endif
206#if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
207# error "SUNPro C++ < 5.14.0 is not supported"
208#endif
209#if defined(__CYGWIN__)
210# error "The Cygwin compiler is not supported"
211#endif
212#if defined(__BORLANDC__)
213# error "The Borland C compiler is not supported"
214#endif
215#if defined(__MWERKS__)
216# error "The MetroWerks compiler is not supported"
217#endif
218#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7)
219# error "GCC < 7 is not supported"
220#endif
221#if defined(__sgi)
222// This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
223// TODO: At some future point, it may be necessary to
224// define a minimum __sgi version that will work.
225# error "The SGI compiler is not supported"
226#endif
227#if defined(__apple_build_version__) && (__apple_build_version__ < 12000032)
228# error "AppleClang < Xcode 12.4 is not supported"
229#elif defined(__clang__) && (__clang_major__ < 5)
230# error "Clang < 5 is not supported"
231#endif
232#if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910)
233# error "Intel C++ < 19.1 is not supported4"
234#endif
235
236// Setup symbol exports
237#if defined(_WIN32) || defined(WIN32)
238# define ITK_ABI_IMPORT __declspec(dllimport)
239# define ITK_ABI_EXPORT __declspec(dllexport)
240# define ITK_ABI_HIDDEN
241#else
242# ifdef __GNUC__
243# define ITK_ABI_IMPORT __attribute__((visibility("default")))
244# define ITK_ABI_EXPORT __attribute__((visibility("default")))
245# define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
246# else
247# define ITK_ABI_IMPORT
248# define ITK_ABI_EXPORT
249# define ITK_ABI_HIDDEN
250# endif
251#endif
252
253// Setup symbol exports
254#ifndef ITK_TEMPLATE_EXPORT
255# ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
256# define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
257# else
258# define ITK_TEMPLATE_EXPORT
259# endif
260#endif
261
262// Setup symbol exports
263#ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
264# define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
265#else
266# define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
267#endif
268
269#ifndef ITK_FORWARD_EXPORT
270// If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
271# if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
272 defined(USE_COMPILER_HIDDEN_VISIBILITY)
273# define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
274# else
275# define ITK_FORWARD_EXPORT
276# endif
277#endif
278
279
301#define itkNewMacro(x) \
302 itkSimpleNewMacro(x); \
303 itkCreateAnotherMacro(x); \
304 itkCloneMacro(x); \
305 ITK_MACROEND_NOOP_STATEMENT
307#define itkSimpleNewMacro(x) \
308 static Pointer New() \
309 { \
310 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
311 if (smartPtr == nullptr) \
312 { \
313 smartPtr = new x(); \
314 } \
315 smartPtr->UnRegister(); \
316 return smartPtr; \
317 } \
318 ITK_MACROEND_NOOP_STATEMENT
319
320#define itkCreateAnotherMacro(x) \
321 ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
322 ITK_MACROEND_NOOP_STATEMENT
323
324#define itkCloneMacro(x) \
325 Pointer Clone() const \
326 { \
327 Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
328 return rval; \
329 } \
330 ITK_MACROEND_NOOP_STATEMENT
331
336#define itkFactoryOnlyNewMacro(x) \
337 itkSimpleFactoryOnlyNewMacro(x); \
338 itkCreateAnotherMacro(x); \
339 itkCloneMacro(x); \
340 ITK_MACROEND_NOOP_STATEMENT
342#define itkSimpleFactoryOnlyNewMacro(x) \
343 static auto New() -> Pointer \
344 { \
345 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
346 if (smartPtr == nullptr) \
347 { \
348 itkSpecializedMessageExceptionMacro(ExceptionObject, \
349 "Object factory failed to instantiate " << typeid(x).name()); \
350 } \
351 smartPtr->UnRegister(); \
352 return smartPtr; \
353 } \
354 ITK_MACROEND_NOOP_STATEMENT
355
369#define itkFactorylessNewMacro(x) \
370 static Pointer New() \
371 { \
372 auto * rawPtr = new x(); \
373 Pointer smartPtr = rawPtr; \
374 rawPtr->UnRegister(); \
375 return smartPtr; \
376 } \
377 itkCreateAnotherMacro(x); \
378 ITK_MACROEND_NOOP_STATEMENT
380//
381// A macro to disallow the copy constructor, copy assignment,
382// move constructor, and move assignment functions.
383// This should be used in the public: declarations for a class
384//
385// ITK's paradigm for smart pointer and pipeline consistency
386// prohibits the use of copy/move construction and copy/move assignment
387// functions.
388//
389#define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
390 TypeName(const TypeName &) = delete; \
391 TypeName & operator=(const TypeName &) = delete; \
392 TypeName(TypeName &&) = delete; \
393 TypeName & operator=(TypeName &&) = delete
394
395#if !defined(ITK_LEGACY_REMOVE)
396# define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
397#else
398# define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
399 static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
400#endif
401
402
411#define ITK_DEFAULT_COPY_AND_MOVE(TypeName) \
412 TypeName(const TypeName &) = default; \
413 TypeName & operator=(const TypeName &) = default; \
414 TypeName(TypeName &&) = default; \
415 TypeName & operator=(TypeName &&) = default
417
418// When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
419// the ability for operator!= to be rewritten automatically in terms of
420// operator==, as introduced with C++20. This macro is experimental. It may be
421// modified, renamed, or removed without backward compatibility support.
422#if __cplusplus >= 202002L
423# define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
424#endif
425
426// Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
427// is only for internal use within the implementation of ITK. It may be
428// modified, renamed, or removed without backward compatibility support.
429#ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
430// With C++20, operator!= is automatically rewritten in terms of the
431// corresponding operator==.
432# define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
433#else
434// For C++14 and C++17, this macro defines an operator!= member function that
435// just calls the corresponding operator== member function.
436# define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
437 bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
438 ITK_MACROEND_NOOP_STATEMENT
439#endif
440
441
442// Internal macro (not part of the public ITK API), used to implement `GetNameOfClass()` member functions.
443#define itkInternalGetNameOfClassImplementationMacro(thisClass) \
444 { \
445 static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
446 "The macro argument `" #thisClass \
447 "` appears incorrect! It should correspond with the name of this class!"); \
448 return #thisClass; \
449 } \
450 ITK_MACROEND_NOOP_STATEMENT
451
452
456#define itkVirtualGetNameOfClassMacro(thisClass) \
457 virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
458
459#define itkOverrideGetNameOfClassMacro(thisClass) \
460 const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
461
462#ifdef ITK_FUTURE_LEGACY_REMOVE
463# define itkTypeMacro(thisClass, superclass) \
464 static_assert(false, \
465 "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
466 "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
467# define itkTypeMacroNoParent(thisClass) \
468 static_assert(false, \
469 "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
470 "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
471#else
476# define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
477# define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
478#endif
479
480
481namespace itk
482{
490#ifndef ITK_FUTURE_LEGACY_REMOVE
491extern ITKCommon_EXPORT void
492OutputWindowDisplayText(const char *);
493
494extern ITKCommon_EXPORT void
495OutputWindowDisplayErrorText(const char *);
496
497extern ITKCommon_EXPORT void
498OutputWindowDisplayWarningText(const char *);
499
500extern ITKCommon_EXPORT void
501OutputWindowDisplayGenericOutputText(const char *);
502
503extern ITKCommon_EXPORT void
504OutputWindowDisplayDebugText(const char *);
505#endif
506
507// New context-aware versions of output display functions
508extern ITKCommon_EXPORT void
509OutputWindowDisplayDebugText(const char * file,
510 unsigned int line,
511 const char * className,
512 const void * objectAddress,
513 const char * message);
514
515extern ITKCommon_EXPORT void
516OutputWindowDisplayWarningText(const char * file,
517 unsigned int line,
518 const char * className,
519 const void * objectAddress,
520 const char * message);
521
522extern ITKCommon_EXPORT void
523OutputWindowDisplayErrorText(const char * file,
524 unsigned int line,
525 const char * className,
526 const void * objectAddress,
527 const char * message);
528
529extern ITKCommon_EXPORT void
530OutputWindowDisplayGenericOutputText(const char * file, unsigned int line, const char * message);
532
533} // end namespace itk
534
535// The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
541#if defined(NDEBUG)
542# define itkDebugMacro(x) ITK_NOOP_STATEMENT
543# define itkDebugStatement(x) ITK_NOOP_STATEMENT
544#else
545# define itkDebugMacro(x) \
546 { \
547 using namespace ::itk::print_helper; /* for ostream << std::vector<T> */ \
548 if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
549 { \
550 std::ostringstream itkmsg; \
551 itkmsg << "" x; \
552 ::itk::OutputWindowDisplayDebugText(__FILE__, __LINE__, this->GetNameOfClass(), this, itkmsg.str().c_str()); \
553 } \
554 } \
555 ITK_MACROEND_NOOP_STATEMENT
556// The itkDebugStatement is to be used to protect code that is only
557// used in the itkDebugMacro
558# define itkDebugStatement(x) x
559#endif
564#define itkWarningMacro(x) \
565 { \
566 if (::itk::Object::GetGlobalWarningDisplay()) \
567 { \
568 std::ostringstream itkmsg; \
569 itkmsg << "" x; \
570 ::itk::OutputWindowDisplayWarningText(__FILE__, __LINE__, this->GetNameOfClass(), this, itkmsg.str().c_str()); \
571 } \
572 } \
573 ITK_MACROEND_NOOP_STATEMENT
574
575
576#define itkWarningStatement(x) x
577
578#if defined(ITK_CPP_FUNCTION)
579# if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
580# define ITK_LOCATION __FUNCSIG__
581# elif defined(__GNUC__)
582# define ITK_LOCATION __PRETTY_FUNCTION__
583# else
584# define ITK_LOCATION __FUNCTION__
585# endif
586#else
587# define ITK_LOCATION "unknown"
588#endif
589
590#define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
591 namespace itk \
592 { \
593 class newexcp : public parentexcp \
594 { \
595 public: \
596 /* default message provides backward compatibility for a given exception type */ \
597 static constexpr const char * const default_exception_message = whatmessage; \
598 /* Inherit the constructors from its base class. */ \
599 using parentexcp::parentexcp; \
600 itkOverrideGetNameOfClassMacro(newexcp); \
601 }; \
602 } \
603 ITK_MACROEND_NOOP_STATEMENT
604
605
606#define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
607 { \
608 std::ostringstream exceptionDescriptionOutputStringStream; \
609 exceptionDescriptionOutputStringStream << "" x; \
610 throw ::itk::ExceptionType( \
611 std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
612 } \
613 ITK_MACROEND_NOOP_STATEMENT
614
615#define itkSpecializedExceptionMacro(ExceptionType) \
616 throw ::itk::ExceptionType( \
617 std::string{ __FILE__ }, __LINE__, ::itk::ExceptionType::default_exception_message, std::string{ ITK_LOCATION });
618
619
623#define itkExceptionMacro(x) \
624 { \
625 std::ostringstream exceptionDescriptionOutputStringStream; \
626 exceptionDescriptionOutputStringStream << "" x; \
627 throw ::itk::ExceptionObject(std::string{ __FILE__ }, \
628 __LINE__, \
629 exceptionDescriptionOutputStringStream.str(), \
630 std::string{ ITK_LOCATION }, \
631 this); \
632 } \
633 ITK_MACROEND_NOOP_STATEMENT
634
635#define itkExceptionStringMacro(x) \
636 { \
637 throw ::itk::ExceptionObject( \
638 std::string{ __FILE__ }, __LINE__, std::string{ x }, std::string{ ITK_LOCATION }, this); \
639 } \
640 ITK_MACROEND_NOOP_STATEMENT
641
642#define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
643
644#define itkGenericOutputMacro(x) \
645 { \
646 if (::itk::Object::GetGlobalWarningDisplay()) \
647 { \
648 std::ostringstream itkmsg; \
649 itkmsg << "" x; \
650 ::itk::OutputWindowDisplayGenericOutputText(__FILE__, __LINE__, itkmsg.str().c_str()); \
651 } \
652 } \
653 ITK_MACROEND_NOOP_STATEMENT
654
655//----------------------------------------------------------------------------
656// Macros for simplifying the use of logging
657//
658#define itkLogMacro(x, y) \
659 { \
660 if (this->GetLogger()) \
661 { \
662 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
663 } \
664 } \
665 ITK_MACROEND_NOOP_STATEMENT
666
667#define itkLogMacroStatic(obj, x, y) \
668 { \
669 if (obj->GetLogger()) \
670 { \
671 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
672 } \
673 } \
674 ITK_MACROEND_NOOP_STATEMENT
675
676//----------------------------------------------------------------------------
677// Setup legacy code policy.
678//
679// CMake options:
680// - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
681// - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
682// of legacy code will not produce compiler warnings.
683// - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
684// of legacy code will produce compiler warnings
685//
686// ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
687//
688// Source files that test the legacy code may define ITK_LEGACY_TEST
689// like this:
690//
691// #define ITK_LEGACY_TEST
692// #include "itkClassWithDeprecatedMethod.h"
693//
694// in order to silence the warnings for calling deprecated methods.
695// No other source files in ITK should call the methods since they are
696// provided only for compatibility with older user code.
697
698// Define itkLegacyMacro to mark legacy methods where they are
699// declared in their class. Example usage:
700//
701// // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
702// itkLegacyMacro(void MyMethod();)
703//
704// See below for what to do for the method definition.
705#if defined(ITK_LEGACY_REMOVE)
706# define itkLegacyMacro(method) /* no ';' */
707#else
708# if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
709// Provide legacy methods with no warnings.
710# define itkLegacyMacro(method) method /* no ';' */
711# else
712// Request compile-time warnings for uses of deprecated methods.
713# define itkLegacyMacro(method) [[deprecated]] method /* no ';' */
714# endif
715#endif
716
717// Macros to create runtime deprecation warning messages in function
718// bodies. Example usage:
719//
720// #if !defined( ITK_LEGACY_REMOVE )
721// void itkMyClass::MyOldMethod()
722// {
723// itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
724// }
725//
726// void itkMyClass::MyMethod()
727// {
728// itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
729// itkMyClass::MyOtherMethod);
730// }
731// #endif
732//
733// NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
734// itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
735// are purposefully not defined when ITK_LEGACY_REMOVE is on,
736// because these macros are only relevant inside code segments
737// that are conditionally compiled only when ITK_LEGACY_REMOVE
738// is off.
739#if defined(ITK_LEGACY_SILENT)
740# define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
741# define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
742# define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
743# define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
744#else
745# define itkLegacyBodyMacro(method, version) \
746 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
747# define itkLegacyReplaceBodyMacro(method, version, replace) \
748 itkWarningMacro(#method " was deprecated for ITK " #version \
749 " and will be removed in a future version. Use " #replace " instead.")
750# define itkGenericLegacyBodyMacro(method, version) \
751 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
752# define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
753 itkGenericOutputMacro(#method " was deprecated for ITK " #version \
754 " and will be removed in a future version. Use " #replace " instead.")
755#endif
756
757// Most modern x86 CPUs have 64 byte aligned blocks which are used for
758// the cache lines. By aligning multi-threaded structures with the
759// cache lines, false shared can be reduced, and performance
760// increased.
761constexpr size_t ITK_CACHE_LINE_ALIGNMENT{ 64 };
762
763//
764// itkPadStruct will add padding to a structure to ensure a minimum size
765// for ensuring that adjacent structures do not share CACHE lines.
766// Each struct will take up some multiple of cacheline sizes.
767// This is particularly useful for arrays of thread private variables.
768//
769#define itkPadStruct(mincachesize, oldtype, newtype) \
770 struct newtype : public oldtype \
771 { \
772 char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
773 }
774
775//
776// itkAlignedTypedef is a macro which creates a new type to make a
777// data structure aligned.
778//
779#if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
780# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
781#elif defined(_MSC_VER)
782# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
783#else
784# define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
785#endif
786
787#if defined(ITK_FUTURE_LEGACY_REMOVE)
788//=============================================================================
789/*
790NOTE: DEPRECATED - This macro is not longer needed to support modern
791compilers.
792
793 Define a common way of declaring a templated function as a friend inside a class.
794 - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
795
796 The following templated function
797
798 template <T>
799 T add(const T & a, const T & b);
800
801 is declared as friend with
802
803 class A
804 {
805 public:
806 friend Self add<>( const Self & a, const Self & b );
807 }
808
809*/
810# define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
811#else // LEGACY_REMOVE
812# define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
813#endif
814
815//--------------------------------------------------------------------------------
816// Helper macros for Template Meta-Programming techniques of for-loops
817// unrolling
818//--------------------------------------------------------------------------------
819
820//--------------------------------------------------------------------------------
821// Macro that generates an unrolled for loop for assigning elements of one array
822// to elements of another array The array are assumed to be of same length
823// (dimension), and this is also assumed to be the value of NumberOfIterations.
824// No verification of size is performed. Casting is performed as part of the
825// assignment, by using the DestinationElementType as the casting type.
826// Source and destination array types must have defined operator[] in their
827// API.
828#define itkForLoopAssignmentMacro( \
829 DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
830 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
831 { \
832 DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
833 } \
834 ITK_MACROEND_NOOP_STATEMENT
835
836//--------------------------------------------------------------------------------
837// Macro that generates an unrolled for loop for rounding and assigning
838// elements of one array to elements of another array The array are assumed to
839// be of same length (dimension), and this is also assumed to be the value of
840// NumberOfIterations. No verification of size is performed. Casting is
841// performed as part of the assignment, by using the DestinationElementType as
842// the casting type.
843// Source and destination array types must have defined operator[] in their
844// API.
845#define itkForLoopRoundingAndAssignmentMacro( \
846 DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
847 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
848 { \
849 DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
850 } \
851 ITK_MACROEND_NOOP_STATEMENT
852
853// end of Template Meta Programming helper macros
854
855#if !defined(NDEBUG) && !defined(ITK_WRAPPING)
856
857# ifdef __GLIBC__
858# define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
859# else
860# define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
861# endif
862
863#else
864# define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
865#endif
866
867#define itkAssertOrThrowMacro(test, message) \
868 if (!(test)) \
869 { \
870 std::ostringstream msgstr; \
871 msgstr << message; \
872 itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
873 } \
874 ITK_MACROEND_NOOP_STATEMENT
875
876#if !defined(NDEBUG) && !defined(ITK_WRAPPING)
877# define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
878#else
879# define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
880#endif
881
882
883// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
884// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
885// !! The ITK Get/Set Macros for various types !!
886// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
887// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
888
889#ifdef ITK_FUTURE_LEGACY_REMOVE
890# define itkStaticConstMacro(name, type, value) \
891 "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
892# define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
893#else
908# define itkStaticConstMacro(name, type, value) static constexpr type name = value
909
910# define itkGetStaticConstMacro(name) (Self::name)
911#endif
912
915#define itkSetInputMacro(name, type) \
916 virtual void Set##name(const type * _arg) \
917 { \
918 itkDebugMacro("setting input " #name " to " << _arg); \
919 if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
920 { \
921 this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
922 this->Modified(); \
923 } \
924 } \
925 ITK_MACROEND_NOOP_STATEMENT
929#define itkGetInputMacro(name, type) \
930 virtual const type * Get##name() const \
931 { \
932 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
933 return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
934 } \
935 ITK_MACROEND_NOOP_STATEMENT
937// clang-format off
940#define itkSetDecoratedInputMacro(name, type) \
941 virtual void Set## name## Input(const SimpleDataObjectDecorator<type> * _arg) \
942 { \
943 itkDebugMacro("setting input " #name " to " << _arg); \
944 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
945 { \
946 this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
947 this->Modified(); \
948 } \
949 } \
950 virtual void Set## name(const SimpleDataObjectDecorator<type> * _arg) { this->Set## name## Input(_arg); } \
951 virtual void Set## name(const type & _arg) \
952 { \
953 using DecoratorType = SimpleDataObjectDecorator<type>; \
954 itkDebugMacro("setting input " #name " to " << _arg); \
955 const DecoratorType * oldInput = \
956 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
957 ITK_GCC_PRAGMA_PUSH \
958 ITK_GCC_SUPPRESS_Wfloat_equal \
959 if (oldInput && oldInput->Get() == _arg) \
960 { \
961 return; \
962 } \
963 ITK_GCC_PRAGMA_POP \
964 auto newInput = DecoratorType::New(); \
965 newInput->Set(_arg); \
966 this->Set## name## Input(newInput); \
967 } \
968 ITK_MACROEND_NOOP_STATEMENT
969// clang-format on
973#define itkGetDecoratedInputMacro(name, type) \
974 virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
975 { \
976 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
977 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
978 } \
979 virtual const type & Get##name() const \
980 { \
981 itkDebugMacro("Getting input " #name); \
982 using DecoratorType = SimpleDataObjectDecorator<type>; \
983 const DecoratorType * input = \
984 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
985 if (input == nullptr) \
986 { \
987 itkExceptionStringMacro("input" #name " is not set"); \
988 } \
989 return input->Get(); \
990 } \
991 ITK_MACROEND_NOOP_STATEMENT
995#define itkSetGetDecoratedInputMacro(name, type) \
996 itkSetDecoratedInputMacro(name, type); \
997 itkGetDecoratedInputMacro(name, type)
998
1004#define itkSetDecoratedObjectInputMacro(name, type) \
1005 virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
1006 { \
1007 itkDebugMacro("setting input " #name " to " << _arg); \
1008 if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
1009 { \
1010 this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
1011 this->Modified(); \
1012 } \
1013 } \
1014 virtual void Set##name(const type * _arg) \
1015 { \
1016 using DecoratorType = DataObjectDecorator<type>; \
1017 itkDebugMacro("setting input " #name " to " << _arg); \
1018 const DecoratorType * oldInput = \
1019 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
1020 if (oldInput && oldInput->Get() == _arg) \
1021 { \
1022 return; \
1023 } \
1024 auto newInput = DecoratorType::New(); \
1025 newInput->Set(_arg); \
1026 this->Set##name##Input(newInput); \
1027 } \
1028 ITK_MACROEND_NOOP_STATEMENT
1035#define itkGetDecoratedObjectInputMacro(name, type) \
1036 virtual const DataObjectDecorator<type> * Get##name##Input() const \
1037 { \
1038 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
1039 return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
1040 } \
1041 virtual const type * Get##name() const \
1042 { \
1043 itkDebugMacro("Getting input " #name); \
1044 using DecoratorType = DataObjectDecorator<type>; \
1045 const DecoratorType * input = \
1046 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
1047 if (input == nullptr) \
1048 { \
1049 return nullptr; \
1050 } \
1051 return input->Get(); \
1052 } \
1053 ITK_MACROEND_NOOP_STATEMENT
1057#define itkSetGetDecoratedObjectInputMacro(name, type) \
1058 itkSetDecoratedObjectInputMacro(name, type); \
1059 itkGetDecoratedObjectInputMacro(name, type)
1060
1062// clang-format off
1063#define itkSetMacro(name, type) \
1064 virtual void Set## name(type _arg) \
1065 { \
1066 itkDebugMacro("setting " #name " to " << _arg); \
1067 ITK_GCC_PRAGMA_PUSH \
1068 ITK_GCC_SUPPRESS_Wfloat_equal \
1069 if (this->m_## name != _arg) \
1070 { \
1071 this->m_## name = std::move(_arg); \
1072 this->Modified(); \
1073 } \
1074 ITK_GCC_PRAGMA_POP \
1075 } \
1076 ITK_MACROEND_NOOP_STATEMENT
1077// clang-format on
1078
1081#define itkGetMacro(name, type) \
1082 virtual type Get##name() { return this->m_##name; } \
1083 ITK_MACROEND_NOOP_STATEMENT
1089#define itkGetConstMacro(name, type) \
1090 virtual type Get##name() const { return this->m_##name; } \
1091 ITK_MACROEND_NOOP_STATEMENT
1098#define itkGetConstReferenceMacro(name, type) \
1099 virtual const type & Get##name() const { return this->m_##name; } \
1100 ITK_MACROEND_NOOP_STATEMENT
1107#define itkSetEnumMacro(name, type) \
1108 virtual void Set##name(const type _arg) \
1109 { \
1110 itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1111 if (this->m_##name != _arg) \
1112 { \
1113 this->m_##name = _arg; \
1114 this->Modified(); \
1115 } \
1116 } \
1117 ITK_MACROEND_NOOP_STATEMENT
1124#define itkGetEnumMacro(name, type) \
1125 virtual type Get##name() const { return this->m_##name; } \
1126 ITK_MACROEND_NOOP_STATEMENT
1132#define itkSetStringMacro(name) \
1133 virtual void Set##name(const char * _arg) \
1134 { \
1135 if (_arg && (_arg == this->m_##name)) \
1136 { \
1137 return; \
1138 } \
1139 if (_arg) \
1140 { \
1141 this->m_##name = _arg; \
1142 } \
1143 else \
1144 { \
1145 this->m_##name = ""; \
1146 } \
1147 this->Modified(); \
1148 } \
1149 virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1150 ITK_MACROEND_NOOP_STATEMENT
1152
1156#define itkGetStringMacro(name) \
1157 virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1158 ITK_MACROEND_NOOP_STATEMENT
1159
1160// clang-format off
1165#define itkSetClampMacro(name, type, min, max) \
1166 virtual void Set## name(type _arg) \
1167 { \
1168 const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1169 itkDebugMacro("setting " << #name " to " << _arg); \
1170 ITK_GCC_PRAGMA_PUSH \
1171 ITK_GCC_SUPPRESS_Wfloat_equal \
1172 if (this->m_## name != temp_extrema) \
1173 { \
1174 this->m_## name = temp_extrema; \
1175 this->Modified(); \
1176 } \
1177 ITK_GCC_PRAGMA_POP \
1178 } \
1179 ITK_MACROEND_NOOP_STATEMENT
1180// clang-format on
1182// clang-format off
1187#define itkSetObjectMacro(name, type) \
1188 virtual void Set## name(type * _arg) \
1189 { \
1190 itkDebugMacro("setting " << #name " to " << _arg); \
1191 if (this->m_## name != _arg) \
1192 { \
1193 this->m_## name = _arg; \
1194 this->Modified(); \
1195 } \
1196 } \
1197 ITK_MACROEND_NOOP_STATEMENT
1198// clang-format on
1208// NOTE: A class can use either itkGetModifiableObjectMacro
1209// or itkGetObjectMacro, but not both.
1210// A class can use either itkGetModifiableObjectMacro
1211// or itkGetConstObjectMacro, but not both.
1212// If the desired behavior is to only provide const
1213// access to the itkObject ivar, then use itkGetConstObjectMacro,
1214// else use itkGetModifiableObjectMacro for read/write access to
1215// the ivar.
1216// It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1217// for backwards compatibility.
1218// If the ITK_LEGACY_REMOVE=FALSE, then it is
1219// permissible to use itkGetObjectMacro which
1220// defines both signatures itk::GetXXX() and
1221// itk::GetModifiableXXX()
1222
1225#define itkGetConstObjectMacro(name, type) \
1226 virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1227 ITK_MACROEND_NOOP_STATEMENT
1228
1229
1230#if defined(ITK_FUTURE_LEGACY_REMOVE)
1231// In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1232// flag. For now, this very advanced feature is only available
1233// through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1234// ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1235// to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1236# define itkGetObjectMacro(name, type) \
1237 virtual type * Get##name() \
1238 { \
1239 purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1240 } \
1241 ITK_MACROEND_NOOP_STATEMENT
1242
1243# define itkGetModifiableObjectMacro(name, type) \
1244 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1245 itkGetConstObjectMacro(name, type)
1246
1247#else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1251# define itkGetObjectMacro(name, type) \
1252 virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1253 ITK_MACROEND_NOOP_STATEMENT
1254# define itkGetModifiableObjectMacro(name, type) \
1255 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1256 itkGetConstObjectMacro(name, type); \
1257 itkGetObjectMacro(name, type)
1259#endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1260
1261// For backwards compatibility define ITK_EXPORT to nothing
1262#define ITK_EXPORT
1263
1264
1267#define itkGetConstReferenceObjectMacro(name, type) \
1268 virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1269 ITK_MACROEND_NOOP_STATEMENT
1270
1275#define itkSetConstObjectMacro(name, type) \
1276 virtual void Set##name(const type * _arg) \
1277 { \
1278 itkDebugMacro("setting " << #name " to " << _arg); \
1279 if (this->m_##name != _arg) \
1280 { \
1281 this->m_##name = _arg; \
1282 this->Modified(); \
1283 } \
1284 } \
1285 ITK_MACROEND_NOOP_STATEMENT
1290#define itkBooleanMacro(name) \
1291 virtual void name##On() { this->Set##name(true); } \
1292 virtual void name##Off() { this->Set##name(false); } \
1293 ITK_MACROEND_NOOP_STATEMENT
1295
1304template <typename MemberContainerType, typename CopyFromValueType, typename LoopEndType>
1305bool
1306ContainerFillWithCheck(MemberContainerType & m, const CopyFromValueType & c, const LoopEndType N)
1307{
1308 bool value_updated = false;
1309 for (unsigned int i = 0; i < N; ++i)
1310 {
1311 ITK_GCC_PRAGMA_PUSH
1312 ITK_GCC_SUPPRESS_Wfloat_equal
1313 if (m[i] != c)
1314 {
1315 m[i] = c;
1316 value_updated = true;
1317 }
1318 ITK_GCC_PRAGMA_POP
1319 }
1320 return value_updated;
1321}
1322
1331template <typename MemberContainerType, typename CopyFromContainerType, typename LoopEndType>
1332bool
1333ContainerCopyWithCheck(MemberContainerType & m, const CopyFromContainerType & c, const LoopEndType N)
1334{
1335 bool value_updated = false;
1336 for (LoopEndType i = 0; i < N; ++i)
1337 {
1338 ITK_GCC_PRAGMA_PUSH
1339 ITK_GCC_SUPPRESS_Wfloat_equal
1340 if (m[i] != c[i])
1341 {
1342 m[i] = c[i];
1343 value_updated = true;
1344 }
1345 ITK_GCC_PRAGMA_POP
1346 }
1347 return value_updated;
1348}
1349
1350// clang-format off
1355#define itkSetVectorMacro(name, type, count) \
1356 virtual void Set## name(type data[]) \
1357 { \
1358 if (ContainerCopyWithCheck( this->m_## name, data, count)) \
1359 { \
1360 this->Modified(); \
1361 } \
1362 } \
1363 ITK_MACROEND_NOOP_STATEMENT
1364// clang-format on
1368#define itkGetVectorMacro(name, type, count) \
1369 virtual type * Get##name() const { return this->m_##name; } \
1370 ITK_MACROEND_NOOP_STATEMENT
1371
1376#define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1377
1384#define itkGPUKernelMacro(kernel) \
1385 kernel \
1386 { \
1387 public: \
1388 ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1389 kernel() = delete; \
1390 ~kernel() = delete; \
1391 static const char * GetOpenCLSource(); \
1392 }
1394#define itkGetOpenCLSourceFromKernelMacro(kernel) \
1395 static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); } \
1396 ITK_MACROEND_NOOP_STATEMENT
1397
1398// A useful macro in the PrintSelf method for printing member variables
1399// which are pointers to object based on the LightObject class.
1400#define itkPrintSelfObjectMacro(name) \
1401 if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1402 { \
1403 os << indent << #name << ": (null)" << std::endl; \
1404 } \
1405 else \
1406 { \
1407 os << indent << #name << ": " << std::endl; \
1408 this->m_##name->Print(os, indent.GetNextIndent()); \
1409 } \
1410 ITK_MACROEND_NOOP_STATEMENT
1411
1412
1413// A useful macro in the PrintSelf method for printing boolean member
1414// variables.
1415#define itkPrintSelfBooleanMacro(name) \
1416 os << indent << #name << ": " << (this->m_##name ? "On" : "Off") << std::endl; \
1417 ITK_MACROEND_NOOP_STATEMENT
1418
1419
1422#define itkSetDecoratedOutputMacro(name, type) \
1423 virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1424 { \
1425 itkDebugMacro("setting output " #name " to " << _arg); \
1426 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1427 { \
1428 this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1429 this->Modified(); \
1430 } \
1431 } \
1432 virtual void Set##name(const type & _arg) \
1433 { \
1434 using DecoratorType = SimpleDataObjectDecorator<type>; \
1435 itkDebugMacro("setting output " #name " to " << _arg); \
1436 DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1437 if (output) \
1438 { \
1439 if (output->Get() == _arg) \
1440 { \
1441 return; \
1442 } \
1443 else \
1444 { \
1445 output->Set(_arg); \
1446 } \
1447 } \
1448 else \
1449 { \
1450 auto newOutput = DecoratorType::New(); \
1451 newOutput->Set(_arg); \
1452 this->Set##name##Output(newOutput); \
1453 } \
1454 } \
1455 ITK_MACROEND_NOOP_STATEMENT
1459#define itkGetDecoratedOutputMacro(name, type) \
1460 virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1461 { \
1462 itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1463 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1464 } \
1465 virtual const type & Get##name() const \
1466 { \
1467 itkDebugMacro("Getting output " #name); \
1468 using DecoratorType = SimpleDataObjectDecorator<type>; \
1469 const DecoratorType * output = \
1470 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1471 if (output == nullptr) \
1472 { \
1473 itkExceptionStringMacro("output" #name " is not set"); \
1474 } \
1475 return output->Get(); \
1476 } \
1477 ITK_MACROEND_NOOP_STATEMENT
1479// ITK_FUTURE_DEPRECATED is only for internal use, within the implementation of ITK. It allows triggering "deprecated"
1480// warnings when legacy support is removed, which warn that a specific feature may be removed in the future.
1481#if defined(ITK_LEGACY_REMOVE) && !defined(ITK_LEGACY_SILENT)
1482# define ITK_FUTURE_DEPRECATED(message) [[deprecated(message)]]
1483#else
1484# define ITK_FUTURE_DEPRECATED(message)
1485#endif
1486
1487#if __cplusplus >= 202002L
1488# define ITK_NODISCARD(message) [[nodiscard(message)]]
1489#else
1490# define ITK_NODISCARD(message) [[nodiscard]]
1491#endif
1492
1493//-*-*-*
1494
1495#if defined(ITK_LEGACY_REMOVE)
1496# define itkExposeEnumValue(name) \
1497 static_assert(false, "ERROR: Replace static_cast<int>(name) with with proper enumeration instead of integer")
1498
1499# define ITK_NOEXCEPT_OR_THROW static_assert(false, "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT")
1500
1501# define ITK_DELETE_FUNCTION static_assert(false, "ERROR: ITK_DELETE_FUNCTION must be replaced with `= delete`"
1502# define ITK_CONSTEXPR_FUNC static_assert(false, "ERROR: ITK_CONSTEXPR_FUNC must be replaced with 'constexpr'")
1503# define ITK_CONSTEXPR_VAR static_assert(false, "ERROR: ITK_CONSTEXPR_VAR must be replaced with 'constexpr'")
1504
1505# define ITK_FALLTHROUGH static_assert(false, "ERROR: ITK_FALLTHROUGH must be replaced with '[[fallthrough]]'")
1506
1507// Defines which used to be in itk_compiler_detection.h
1508# define ITK_ALIGNAS static_assert(false, "ERROR: ITK_ALIGNAS must be replaced with 'alignas'")
1509# define ITK_ALIGNOF static_assert(false, "ERROR: ITK_ALIGNOF must be replaced with 'alignof'")
1510# define ITK_DEPRECATED static_assert(false, "ERROR: ITK_DEPRECATED must be replaced with '[[deprecated]]'")
1511# define ITK_DEPRECATED_MSG \
1512 static_assert(false, "ERROR: ITK_DEPRECATED_MSG must be replaced with '[[deprecated(MSG)]]'")
1513# define ITK_CONSTEXPR static_assert(false, "ERROR: ITK_CONSTEXPR must be replaced with 'constexpr'")
1514# define ITK_DELETED_FUNCTION static_assert(false, "ERROR: ITK_DELETED_FUNCTION must be replaced with '= delete'")
1515# define ITK_EXTERN_TEMPLATE static_assert(false, "ERROR: ITK_EXTERN_TEMPLATE must be replaced with 'extern'")
1516# define ITK_FINAL static_assert(false, "ERROR: ITK_FINAL must be replaced with 'final'")
1517# define ITK_NOEXCEPT static_assert(false, "ERROR: ITK_NOEXCEPT must be replaced with 'noexcept'")
1518# define ITK_NOEXCEPT_EXPR static_assert(false, "ERROR: ITK_NOEXCEPT_EXPR must be replaced with 'noexcept'")
1519# define ITK_NULLPTR static_assert(false, "ERROR: ITK_NULLPTR must be replaced with 'nullptr'")
1520# define ITK_OVERRIDE static_assert(false, "ERROR: ITK_OVERRIDE must be replaced with 'override'")
1521# define ITK_STATIC_ASSERT static_assert(false, "ERROR: ITK_STATIC_ASSERT must be replaced with 'static_assert'")
1522# define ITK_STATIC_ASSERT_MSG \
1523 static_assert(false, "ERROR: ITK_STATIC_ASSERT_MSG must be replaced with 'static_assert'")
1524# define ITK_THREAD_LOCAL static_assert(false, "ERROR: ITK_THREAD_LOCAL must be replaced with 'thread_local'")
1525
1526// A macro for methods which are const in ITKv5 and ITKv6 require const for functions
1527# define ITKv5_CONST static_assert(false, "ERROR: ITKv5_CONST must be replaced with 'const'")
1528
1529# define ITK_ITERATOR_VIRTUAL static_assert(false, "ERROR: ITK_ITERATOR_VIRTUAL must be removed'")
1530# define ITK_ITERATOR_OVERRIDE static_assert(false, "ERROR: ITK_ITERATOR_OVERRIDE must be removed")
1531# define ITK_ITERATOR_FINAL static_assert(false, "ERROR: ITK_ITERATOR_FINAL must be removed")
1532
1533#else
1534// DEPRECATED: These macros are left here for compatibility with remote modules.
1535// Once they have been removed from all known remote modules, this code should
1536// be removed.
1537
1538// Future remove `#define itkExposeEnumValue(name)`
1539// "Replace type of `name` with proper enumeration instead of integer.
1540# define itkExposeEnumValue(name) static_cast<int>(name)
1541
1542
1543# define ITK_NOEXCEPT_OR_THROW ITK_NOEXCEPT
1544
1545# define ITK_FALLTHROUGH [[fallthrough]]
1546
1547# define ITK_DELETE_FUNCTION = delete
1548
1549# define ITK_CONSTEXPR_FUNC constexpr
1550# define ITK_CONSTEXPR_VAR constexpr
1551
1552// Defines which used to be in itk_compiler_detection.h
1553# define ITK_ALIGNAS(X) alignas(X)
1554# define ITK_ALIGNOF(X) alignof(X)
1555# define ITK_DEPRECATED [[deprecated]]
1556# define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1557# define ITK_CONSTEXPR constexpr
1558# define ITK_DELETED_FUNCTION = delete
1559# define ITK_EXTERN_TEMPLATE extern
1560# define ITK_FINAL final
1561# define ITK_NOEXCEPT noexcept
1562# define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1563# define ITK_NULLPTR nullptr
1564# define ITK_OVERRIDE override
1565# define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1566# define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1567# define ITK_THREAD_LOCAL thread_local
1568
1569// A macro for methods which are const in after ITKv4
1570# define ITKv5_CONST const
1571
1572# define ITK_ITERATOR_VIRTUAL /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1573# define ITK_ITERATOR_OVERRIDE /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1574# define ITK_ITERATOR_FINAL /*purposefully empty for ITKv6, iterators are not virtual for performance reasons*/
1575#endif
1576
1577#define allow_inclusion_of_itkExceptionObject_h
1578// Must include itkExceptionObject.h at the end of the file
1579// because it depends on the macros defined above
1580#include "itkExceptionObject.h"
1581
1582
1583#undef allow_inclusion_of_itkExceptionObject_h
1584#endif // itkMacro_h
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....