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