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