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