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 ITK_PRAGMA(clang diagnostic ignored "-Wzero-as-null-pointer-constant")
125 #else
126 # define ITK_CLANG_PRAGMA_PUSH
127 # define ITK_CLANG_PRAGMA_POP
128 # define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant
129 #endif
130 
131 // These were not intended as public API, but some code was nevertheless using them.
132 // Support the pre ITK 5.4 spelling for compatibility.
133 #define CLANG_PRAGMA_PUSH ITK_CLANG_PRAGMA_PUSH
134 #define CLANG_PRAGMA_POP ITK_CLANG_PRAGMA_POP
135 #define CLANG_SUPPRESS_Wfloat_equal ITK_GCC_SUPPRESS_Wfloat_equal
136 
137 #if !defined(ITK_LEGACY_REMOVE)
138 // Issue warning if deprecated preprocessor flag is used.
139 # define CLANG_SUPPRESS_Wcpp14_extensions \
140  [[deprecated("Remove deprecated CLANG_SUPPRESS_Wcpp14_extensions c++14 warning suppression")]] void * \
141  CLANG_SUPPRESS_Wcpp14_extensions = nullptr;
142 #endif
143 
144 // Intel compiler convenience macros
145 #if defined(__INTEL_COMPILER)
146 # define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
147 # define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
148 # define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
149 #else
150 # define INTEL_PRAGMA_WARN_PUSH
151 # define INTEL_PRAGMA_WARN_POP
152 # define INTEL_SUPPRESS_warning_1292
153 #endif
154 
155 // Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
156 //
157 // This macro sets a pragma diagnostic
158 //
159 // Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
160 //
161 // These macros respectively push and pop the diagnostic context
162 //
163 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
164 # define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
165 # define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
166 # define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
167 #else
168 # define ITK_GCC_PRAGMA_DIAG(x)
169 # define ITK_GCC_PRAGMA_DIAG_PUSH()
170 # define ITK_GCC_PRAGMA_DIAG_POP()
171 #endif
172 
173 /*
174  * ITK only supports MSVC++ 14.2 and greater
175  * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
176  */
177 #if defined(_MSC_VER) && (_MSC_VER < 1920)
178 # error "MSVC versions before Visual Studio 2019 are not supported"
179 #endif
180 #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
181 # error "SUNPro C++ < 5.14.0 is not supported"
182 #endif
183 #if defined(__CYGWIN__)
184 # error "The Cygwin compiler is not supported"
185 #endif
186 #if defined(__BORLANDC__)
187 # error "The Borland C compiler is not supported"
188 #endif
189 #if defined(__MWERKS__)
190 # error "The MetroWerks compiler is not supported"
191 #endif
192 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7)
193 # error "GCC < 7 is not supported"
194 #endif
195 #if defined(__sgi)
196 // This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
197 // TODO: At some future point, it may be necessary to
198 // define a minimum __sgi version that will work.
199 # error "The SGI compiler is not supported"
200 #endif
201 #if defined(__APPLE__)
202 # if defined(__clang__) && (__cplusplus < 201703L)
203 # error "Apple LLVM compiling with a standard less than C++17 is not supported"
204 # endif
205 #elif defined(__clang__) && (__clang_major__ < 5)
206 # error "Clang < 5 is not supported"
207 #endif
208 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910)
209 # error "Intel C++ < 19.1 is not supported4"
210 #endif
211 
212 // Setup symbol exports
213 #if defined(_WIN32) || defined(WIN32)
214 # define ITK_ABI_IMPORT __declspec(dllimport)
215 # define ITK_ABI_EXPORT __declspec(dllexport)
216 # define ITK_ABI_HIDDEN
217 #else
218 # ifdef __GNUC__
219 # define ITK_ABI_IMPORT __attribute__((visibility("default")))
220 # define ITK_ABI_EXPORT __attribute__((visibility("default")))
221 # define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
222 # else
223 # define ITK_ABI_IMPORT
224 # define ITK_ABI_EXPORT
225 # define ITK_ABI_HIDDEN
226 # endif
227 #endif
228 
229 // Setup symbol exports
230 #ifndef ITK_TEMPLATE_EXPORT
231 # ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
232 # define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
233 # else
234 # define ITK_TEMPLATE_EXPORT
235 # endif
236 #endif
237 
238 // Setup symbol exports
239 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
240 # define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
241 #else
242 # define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
243 #endif
244 
245 #ifndef ITK_FORWARD_EXPORT
246 // If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
247 # if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
248  defined(USE_COMPILER_HIDDEN_VISIBILITY)
249 # define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
250 # else
251 # define ITK_FORWARD_EXPORT
252 # endif
253 #endif
254 
255 
276 #define itkNewMacro(x) \
277  itkSimpleNewMacro(x); \
278  itkCreateAnotherMacro(x); \
279  itkCloneMacro(x); \
280  ITK_MACROEND_NOOP_STATEMENT
281 
283 #define itkSimpleNewMacro(x) \
284  static Pointer New() \
285  { \
286  Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
287  if (smartPtr == nullptr) \
288  { \
289  smartPtr = new x(); \
290  } \
291  smartPtr->UnRegister(); \
292  return smartPtr; \
293  } \
294  ITK_MACROEND_NOOP_STATEMENT
295 
296 #define itkCreateAnotherMacro(x) \
297  ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
298  ITK_MACROEND_NOOP_STATEMENT
299 
300 #define itkCloneMacro(x) \
301  Pointer Clone() const \
302  { \
303  Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
304  return rval; \
305  } \
306  ITK_MACROEND_NOOP_STATEMENT
307 
311 #define itkFactoryOnlyNewMacro(x) \
312  itkSimpleFactoryOnlyNewMacro(x); \
313  itkCreateAnotherMacro(x); \
314  itkCloneMacro(x); \
315  ITK_MACROEND_NOOP_STATEMENT
316 
318 #define itkSimpleFactoryOnlyNewMacro(x) \
319  static auto New()->Pointer \
320  { \
321  Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
322  if (smartPtr == nullptr) \
323  { \
324  itkSpecializedMessageExceptionMacro(ExceptionObject, \
325  "Object factory failed to instantiate " << typeid(x).name()); \
326  } \
327  smartPtr->UnRegister(); \
328  return smartPtr; \
329  } \
330  ITK_MACROEND_NOOP_STATEMENT
331 
344 #define itkFactorylessNewMacro(x) \
345  static Pointer New() \
346  { \
347  x * rawPtr = new x(); \
348  Pointer smartPtr = rawPtr; \
349  rawPtr->UnRegister(); \
350  return smartPtr; \
351  } \
352  itkCreateAnotherMacro(x); \
353  ITK_MACROEND_NOOP_STATEMENT
354 
356 //
357 // A macro to disallow the copy constructor, copy assignment,
358 // move constructor, and move assignment functions.
359 // This should be used in the public: declarations for a class
360 //
361 // ITK's paradigm for smart pointer and pipeline consistency
362 // prohibits the use of copy/move construction and copy/move assignment
363 // functions.
364 //
365 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
366  TypeName(const TypeName &) = delete; \
367  TypeName & operator=(const TypeName &) = delete; \
368  TypeName(TypeName &&) = delete; \
369  TypeName & operator=(TypeName &&) = delete
370 
371 #if !defined(ITK_LEGACY_REMOVE)
372 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
373 #else
374 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
375  static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
376 #endif
377 
378 
386 #define ITK_DEFAULT_COPY_AND_MOVE(TypeName) \
387  TypeName(const TypeName &) = default; \
388  TypeName & operator=(const TypeName &) = default; \
389  TypeName(TypeName &&) = default; \
390  TypeName & operator=(TypeName &&) = default
391 
394 // When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
395 // the ability for operator!= to be rewritten automatically in terms of
396 // operator==, as introduced with C++20. This macro is experimental. It may be
397 // modified, renamed, or removed without backward compatibility support.
398 #if __cplusplus >= 202002L
399 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
400 #endif
401 
402 // Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
403 // is only for internal use within the implementation of ITK. It may be
404 // modified, renamed, or removed without backward compatibility support.
405 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
406 // With C++20, operator!= is automatically rewritten in terms of the
407 // corresponding operator==.
408 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
409 #else
410 // For C++14 and C++17, this macro defines an operator!= member function that
411 // just calls the corresponding operator== member function.
412 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
413  bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
414  ITK_MACROEND_NOOP_STATEMENT
415 #endif
416 
417 
418 // Internal macro (not part of the public ITK API), used to implement `GetNameOfClass()` member functions.
419 #define itkInternalGetNameOfClassImplementationMacro(thisClass) \
420  { \
421  static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
422  "The macro argument `" #thisClass \
423  "` appears incorrect! It should correspond with the name of this class!"); \
424  return #thisClass; \
425  } \
426  ITK_MACROEND_NOOP_STATEMENT
427 
428 
432 #define itkVirtualGetNameOfClassMacro(thisClass) \
433  virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
434 
435 #define itkOverrideGetNameOfClassMacro(thisClass) \
436  const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
437 
438 #ifdef ITK_FUTURE_LEGACY_REMOVE
439 # define itkTypeMacro(thisClass, superclass) \
440  static_assert(false, \
441  "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
442  "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
443 # define itkTypeMacroNoParent(thisClass) \
444  static_assert(false, \
445  "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
446  "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
447 #else
448 
452 # define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
453 # define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
454 #endif
455 
456 
457 namespace itk
458 {
465 extern ITKCommon_EXPORT void
466 OutputWindowDisplayText(const char *);
469 extern ITKCommon_EXPORT void
470 OutputWindowDisplayErrorText(const char *);
471 
472 extern ITKCommon_EXPORT void
473 OutputWindowDisplayWarningText(const char *);
474 
475 extern ITKCommon_EXPORT void
476 OutputWindowDisplayGenericOutputText(const char *);
477 
478 extern ITKCommon_EXPORT void
479 OutputWindowDisplayDebugText(const char *);
480 
481 } // end namespace itk
482 
483 // The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
488 #if defined(NDEBUG)
489 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
490 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
491 #else
492 # define itkDebugMacro(x) \
493  { \
494  using namespace ::itk::print_helper; /* for ostream << std::vector<T> */ \
495  if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
496  { \
497  std::ostringstream itkmsg; \
498  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
499  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
500  ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
501  } \
502  } \
503  ITK_MACROEND_NOOP_STATEMENT
504 // The itkDebugStatement is to be used to protect code that is only
505 // used in the itkDebugMacro
506 # define itkDebugStatement(x) x
507 #endif
508 
513 #define itkWarningMacro(x) \
514  { \
515  if (::itk::Object::GetGlobalWarningDisplay()) \
516  { \
517  std::ostringstream itkmsg; \
518  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << '\n' \
519  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
520  ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
521  } \
522  } \
523  ITK_MACROEND_NOOP_STATEMENT
524 
527 #define itkWarningStatement(x) x
528 
529 #if defined(ITK_CPP_FUNCTION)
530 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
531 # define ITK_LOCATION __FUNCSIG__
532 # elif defined(__GNUC__)
533 # define ITK_LOCATION __PRETTY_FUNCTION__
534 # else
535 # define ITK_LOCATION __FUNCTION__
536 # endif
537 #else
538 # define ITK_LOCATION "unknown"
539 #endif
540 
541 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
542  namespace itk \
543  { \
544  class newexcp : public parentexcp \
545  { \
546  public: \
547  /* default message provides backward compatibility for a given exception type */ \
548  static constexpr const char * const default_exception_message = whatmessage; \
549  /* Inherit the constructors from its base class. */ \
550  using parentexcp::parentexcp; \
551  itkOverrideGetNameOfClassMacro(newexcp); \
552  }; \
553  } \
554  ITK_MACROEND_NOOP_STATEMENT
555 
556 
557 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
558  { \
559  std::ostringstream exceptionDescriptionOutputStringStream; \
560  exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
561  throw ::itk::ExceptionType( \
562  std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
563  } \
564  ITK_MACROEND_NOOP_STATEMENT
565 
566 #define itkSpecializedExceptionMacro(ExceptionType) \
567  itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
568 
572 #define itkExceptionMacro(x) \
573  itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
574 
575 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
576 
577 #define itkGenericOutputMacro(x) \
578  { \
579  if (::itk::Object::GetGlobalWarningDisplay()) \
580  { \
581  std::ostringstream itkmsg; \
582  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
583  ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
584  } \
585  } \
586  ITK_MACROEND_NOOP_STATEMENT
587 
588 //----------------------------------------------------------------------------
589 // Macros for simplifying the use of logging
590 //
591 #define itkLogMacro(x, y) \
592  { \
593  if (this->GetLogger()) \
594  { \
595  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
596  } \
597  } \
598  ITK_MACROEND_NOOP_STATEMENT
599 
600 #define itkLogMacroStatic(obj, x, y) \
601  { \
602  if (obj->GetLogger()) \
603  { \
604  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
605  } \
606  } \
607  ITK_MACROEND_NOOP_STATEMENT
608 
609 //----------------------------------------------------------------------------
610 // Setup legacy code policy.
611 //
612 // CMake options:
613 // - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
614 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
615 // of legacy code will not produce compiler warnings.
616 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
617 // of legacy code will produce compiler warnings
618 //
619 // ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
620 //
621 // Source files that test the legacy code may define ITK_LEGACY_TEST
622 // like this:
623 //
624 // #define ITK_LEGACY_TEST
625 // #include "itkClassWithDeprecatedMethod.h"
626 //
627 // in order to silence the warnings for calling deprecated methods.
628 // No other source files in ITK should call the methods since they are
629 // provided only for compatibility with older user code.
630 
631 // Define itkLegacyMacro to mark legacy methods where they are
632 // declared in their class. Example usage:
633 //
634 // // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
635 // itkLegacyMacro(void MyMethod());
636 //
637 // See below for what to do for the method definition.
638 #if defined(ITK_LEGACY_REMOVE)
639 # define itkLegacyMacro(method) /* no ';' */
640 #else
641 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
642 // Provide legacy methods with no warnings.
643 # define itkLegacyMacro(method) method
644 # else
645 // Request compile-time warnings for uses of deprecated methods.
646 # define itkLegacyMacro(method) [[deprecated]] method
647 # endif
648 #endif
649 
650 // Macros to create runtime deprecation warning messages in function
651 // bodies. Example usage:
652 //
653 // #if !defined( ITK_LEGACY_REMOVE )
654 // void itkMyClass::MyOldMethod()
655 // {
656 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
657 // }
658 //
659 // void itkMyClass::MyMethod()
660 // {
661 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
662 // itkMyClass::MyOtherMethod);
663 // }
664 // #endif
665 //
666 // NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
667 // itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
668 // are purposefully not defined when ITK_LEGACY_REMOVE is on,
669 // because these macros are only relevant inside code segments
670 // that are conditionally compiled only when ITK_LEGACY_REMOVE
671 // is off.
672 #if defined(ITK_LEGACY_SILENT)
673 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
674 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
675 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
676 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
677 #else
678 # define itkLegacyBodyMacro(method, version) \
679  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
680 # define itkLegacyReplaceBodyMacro(method, version, replace) \
681  itkWarningMacro(#method " was deprecated for ITK " #version \
682  " and will be removed in a future version. Use " #replace " instead.")
683 # define itkGenericLegacyBodyMacro(method, version) \
684  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
685 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
686  itkGenericOutputMacro(#method " was deprecated for ITK " #version \
687  " and will be removed in a future version. Use " #replace " instead.")
688 #endif
689 
690 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
691 // the cache lines. By aligning multi-threaded structures with the
692 // cache lines, false shared can be reduced, and performance
693 // increased.
694 #define ITK_CACHE_LINE_ALIGNMENT 64
695 
696 //
697 // itkPadStruct will add padding to a structure to ensure a minimum size
698 // for ensuring that adjacent structures do not share CACHE lines.
699 // Each struct will take up some multiple of cacheline sizes.
700 // This is particularly useful for arrays of thread private variables.
701 //
702 #define itkPadStruct(mincachesize, oldtype, newtype) \
703  struct newtype : public oldtype \
704  { \
705  char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
706  }
707 
708 //
709 // itkAlignedTypedef is a macro which creates a new type to make a
710 // data structure aligned.
711 //
712 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
713 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
714 #elif defined(_MSC_VER)
715 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
716 #else
717 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
718 #endif
719 
720 #if defined(ITK_FUTURE_LEGACY_REMOVE)
721 //=============================================================================
722 /*
723 NOTE: DEPRECATED - This macro is not longer needed to support modern
724 compilers.
725 
726  Define a common way of declaring a templated function as a friend inside a class.
727  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
728 
729  The following templated function
730 
731  template <T>
732  T add(const T & a, const T & b);
733 
734  is declared as friend with
735 
736  class A
737  {
738  public:
739  friend Self add<>( const Self & a, const Self & b );
740  }
741 
742 */
743 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
744 #else // LEGACY_REMOVE
745 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
746 #endif
747 
748 //--------------------------------------------------------------------------------
749 // Helper macros for Template Meta-Programming techniques of for-loops
750 // unrolling
751 //--------------------------------------------------------------------------------
752 
753 //--------------------------------------------------------------------------------
754 // Macro that generates an unrolled for loop for assigning elements of one array
755 // to elements of another array The array are assumed to be of same length
756 // (dimension), and this is also assumed to be the value of NumberOfIterations.
757 // No verification of size is performed. Casting is performed as part of the
758 // assignment, by using the DestinationElementType as the casting type.
759 // Source and destination array types must have defined operator[] in their
760 // API.
761 #define itkForLoopAssignmentMacro( \
762  DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
763  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
764  { \
765  DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
766  } \
767  ITK_MACROEND_NOOP_STATEMENT
768 
769 //--------------------------------------------------------------------------------
770 // Macro that generates an unrolled for loop for rounding and assigning
771 // elements of one array to elements of another array The array are assumed to
772 // be of same length (dimension), and this is also assumed to be the value of
773 // NumberOfIterations. No verification of size is performed. Casting is
774 // performed as part of the assignment, by using the DestinationElementType as
775 // the casting type.
776 // Source and destination array types must have defined operator[] in their
777 // API.
778 #define itkForLoopRoundingAndAssignmentMacro( \
779  DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
780  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
781  { \
782  DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
783  } \
784  ITK_MACROEND_NOOP_STATEMENT
785 
786 // end of Template Meta Programming helper macros
787 
788 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
789 
790 # ifdef __GLIBC__
791 # define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
792 # else
793 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
794 # endif
795 
796 #else
797 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
798 #endif
799 
800 #define itkAssertOrThrowMacro(test, message) \
801  if (!(test)) \
802  { \
803  std::ostringstream msgstr; \
804  msgstr << message; \
805  itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
806  } \
807  ITK_MACROEND_NOOP_STATEMENT
808 
809 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
810 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
811 #else
812 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
813 #endif
814 
815 
816 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
817 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
818 // !! The ITK Get/Set Macros for various types !!
819 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
820 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
821 
822 #ifdef ITK_FUTURE_LEGACY_REMOVE
823 # define itkStaticConstMacro(name, type, value) \
824  "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
825 # define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
826 #else
827 
841 # define itkStaticConstMacro(name, type, value) static constexpr type name = value
842 
843 # define itkGetStaticConstMacro(name) (Self::name)
844 #endif
845 
847 #define itkSetInputMacro(name, type) \
848  virtual void Set##name(const type * _arg) \
849  { \
850  itkDebugMacro("setting input " #name " to " << _arg); \
851  if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
852  { \
853  this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
854  this->Modified(); \
855  } \
856  } \
857  ITK_MACROEND_NOOP_STATEMENT
858 
861 #define itkGetInputMacro(name, type) \
862  virtual const type * Get##name() const \
863  { \
864  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
865  return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
866  } \
867  ITK_MACROEND_NOOP_STATEMENT
868 
870 // clang-format off
872 #define itkSetDecoratedInputMacro(name, type) \
873  virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
874  { \
875  itkDebugMacro("setting input " #name " to " << _arg); \
876  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
877  { \
878  this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
879  this->Modified(); \
880  } \
881  } \
882  virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
883  virtual void Set##name(const type & _arg) \
884  { \
885  using DecoratorType = SimpleDataObjectDecorator<type>; \
886  itkDebugMacro("setting input " #name " to " << _arg); \
887  const DecoratorType * oldInput = \
888  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
889  ITK_GCC_PRAGMA_PUSH \
890  ITK_GCC_SUPPRESS_Wfloat_equal \
891  if (oldInput && oldInput->Get() == _arg) \
892  { \
893  return; \
894  } \
895  ITK_GCC_PRAGMA_POP \
896  auto newInput = DecoratorType::New(); \
897  newInput->Set(_arg); \
898  this->Set##name##Input(newInput); \
899  } \
900  ITK_MACROEND_NOOP_STATEMENT
901 // clang-format on
905 #define itkGetDecoratedInputMacro(name, type) \
906  virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
907  { \
908  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
909  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
910  } \
911  virtual const type & Get##name() const \
912  { \
913  itkDebugMacro("Getting input " #name); \
914  using DecoratorType = SimpleDataObjectDecorator<type>; \
915  const DecoratorType * input = \
916  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
917  if (input == nullptr) \
918  { \
919  itkExceptionMacro("input" #name " is not set"); \
920  } \
921  return input->Get(); \
922  } \
923  ITK_MACROEND_NOOP_STATEMENT
924 
928 #define itkSetGetDecoratedInputMacro(name, type) \
929  itkSetDecoratedInputMacro(name, type); \
930  itkGetDecoratedInputMacro(name, type)
931 
936 #define itkSetDecoratedObjectInputMacro(name, type) \
937  virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
938  { \
939  itkDebugMacro("setting input " #name " to " << _arg); \
940  if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
941  { \
942  this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
943  this->Modified(); \
944  } \
945  } \
946  virtual void Set##name(const type * _arg) \
947  { \
948  using DecoratorType = DataObjectDecorator<type>; \
949  itkDebugMacro("setting input " #name " to " << _arg); \
950  const DecoratorType * oldInput = \
951  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
952  if (oldInput && oldInput->Get() == _arg) \
953  { \
954  return; \
955  } \
956  auto newInput = DecoratorType::New(); \
957  newInput->Set(_arg); \
958  this->Set##name##Input(newInput); \
959  } \
960  ITK_MACROEND_NOOP_STATEMENT
961 
967 #define itkGetDecoratedObjectInputMacro(name, type) \
968  virtual const DataObjectDecorator<type> * Get##name##Input() const \
969  { \
970  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
971  return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
972  } \
973  virtual const type * Get##name() const \
974  { \
975  itkDebugMacro("Getting input " #name); \
976  using DecoratorType = DataObjectDecorator<type>; \
977  const DecoratorType * input = \
978  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
979  if (input == nullptr) \
980  { \
981  return nullptr; \
982  } \
983  return input->Get(); \
984  } \
985  ITK_MACROEND_NOOP_STATEMENT
986 
990 #define itkSetGetDecoratedObjectInputMacro(name, type) \
991  itkSetDecoratedObjectInputMacro(name, type); \
992  itkGetDecoratedObjectInputMacro(name, type)
993 
995 // clang-format off
996 #define itkSetMacro(name, type) \
997  virtual void Set##name(type _arg) \
998  { \
999  itkDebugMacro("setting " #name " to " << _arg); \
1000  ITK_GCC_PRAGMA_PUSH \
1001  ITK_GCC_SUPPRESS_Wfloat_equal \
1002  if (this->m_##name != _arg) \
1003  { \
1004  this->m_##name = std::move(_arg); \
1005  this->Modified(); \
1006  } \
1007  ITK_GCC_PRAGMA_POP \
1008  } \
1009  ITK_MACROEND_NOOP_STATEMENT
1010 // clang-format on
1011 
1013 #define itkGetMacro(name, type) \
1014  virtual type Get##name() { return this->m_##name; } \
1015  ITK_MACROEND_NOOP_STATEMENT
1016 
1021 #define itkGetConstMacro(name, type) \
1022  virtual type Get##name() const { return this->m_##name; } \
1023  ITK_MACROEND_NOOP_STATEMENT
1024 
1030 #define itkGetConstReferenceMacro(name, type) \
1031  virtual const type & Get##name() const { return this->m_##name; } \
1032  ITK_MACROEND_NOOP_STATEMENT
1033 
1039 #define itkSetEnumMacro(name, type) \
1040  virtual void Set##name(const type _arg) \
1041  { \
1042  itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1043  if (this->m_##name != _arg) \
1044  { \
1045  this->m_##name = _arg; \
1046  this->Modified(); \
1047  } \
1048  } \
1049  ITK_MACROEND_NOOP_STATEMENT
1050 
1056 #define itkGetEnumMacro(name, type) \
1057  virtual type Get##name() const { return this->m_##name; } \
1058  ITK_MACROEND_NOOP_STATEMENT
1059 
1064 #define itkSetStringMacro(name) \
1065  virtual void Set##name(const char * _arg) \
1066  { \
1067  if (_arg && (_arg == this->m_##name)) \
1068  { \
1069  return; \
1070  } \
1071  if (_arg) \
1072  { \
1073  this->m_##name = _arg; \
1074  } \
1075  else \
1076  { \
1077  this->m_##name = ""; \
1078  } \
1079  this->Modified(); \
1080  } \
1081  virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1082  ITK_MACROEND_NOOP_STATEMENT
1083 
1089 #define itkGetStringMacro(name) \
1090  virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1091  ITK_MACROEND_NOOP_STATEMENT
1092 
1093 // clang-format off
1097 #define itkSetClampMacro(name, type, min, max) \
1098  virtual void Set##name(type _arg) \
1099  { \
1100  const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1101  itkDebugMacro("setting " << #name " to " << _arg); \
1102  ITK_GCC_PRAGMA_PUSH \
1103  ITK_GCC_SUPPRESS_Wfloat_equal \
1104  if (this->m_##name != temp_extrema) \
1105  { \
1106  this->m_##name = temp_extrema; \
1107  this->Modified(); \
1108  } \
1109  ITK_GCC_PRAGMA_POP \
1110  } \
1111  ITK_MACROEND_NOOP_STATEMENT
1112 // clang-format on
1115 // clang-format off
1119 #define itkSetObjectMacro(name, type) \
1120  virtual void Set##name(type * _arg) \
1121  { \
1122  itkDebugMacro("setting " << #name " to " << _arg); \
1123  if (this->m_##name != _arg) \
1124  { \
1125  this->m_##name = _arg; \
1126  this->Modified(); \
1127  } \
1128  } \
1129  ITK_MACROEND_NOOP_STATEMENT
1130 // clang-format on
1141 // NOTE: A class can use either itkGetModifiableObjectMacro
1142 // or itkGetObjectMacro, but not both.
1143 // A class can use either itkGetModifiableObjectMacro
1144 // or itkGetConstObjectMacro, but not both.
1145 // If the desired behavior is to only provide const
1146 // access to the itkObject ivar, then use itkGetConstObjectMacro,
1147 // else use itkGetModifiableObjectMacro for read/write access to
1148 // the ivar.
1149 // It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1150 // for backwards compatibility.
1151 // If the ITK_LEGACY_REMOVE=FALSE, then it is
1152 // permissible to use itkGetObjectMacro which
1153 // defines both signatures itk::GetXXX() and
1154 // itk::GetModifiableXXX()
1155 
1158 #define itkGetConstObjectMacro(name, type) \
1159  virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1160  ITK_MACROEND_NOOP_STATEMENT
1161 
1162 
1163 #if defined(ITK_FUTURE_LEGACY_REMOVE)
1164 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1165 // flag. For now, this very advanced feature is only available
1166 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1167 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1168 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1169 # define itkGetObjectMacro(name, type) \
1170  virtual type * Get##name() \
1171  { \
1172  purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1173  } \
1174  ITK_MACROEND_NOOP_STATEMENT
1175 
1176 # define itkGetModifiableObjectMacro(name, type) \
1177  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1178  itkGetConstObjectMacro(name, type)
1179 
1180 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1181 
1183 # define itkGetObjectMacro(name, type) \
1184  virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1185  ITK_MACROEND_NOOP_STATEMENT
1186 # define itkGetModifiableObjectMacro(name, type) \
1187  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1188  itkGetConstObjectMacro(name, type); \
1189  itkGetObjectMacro(name, type)
1190 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1191 
1193 // For backwards compatibility define ITK_EXPORT to nothing
1194 #define ITK_EXPORT
1195 
1196 
1199 #define itkGetConstReferenceObjectMacro(name, type) \
1200  virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1201  ITK_MACROEND_NOOP_STATEMENT
1202 
1206 #define itkSetConstObjectMacro(name, type) \
1207  virtual void Set##name(const type * _arg) \
1208  { \
1209  itkDebugMacro("setting " << #name " to " << _arg); \
1210  if (this->m_##name != _arg) \
1211  { \
1212  this->m_##name = _arg; \
1213  this->Modified(); \
1214  } \
1215  } \
1216  ITK_MACROEND_NOOP_STATEMENT
1217 
1221 #define itkBooleanMacro(name) \
1222  virtual void name##On() { this->Set##name(true); } \
1223  virtual void name##Off() { this->Set##name(false); } \
1224  ITK_MACROEND_NOOP_STATEMENT
1225 
1227 // clang-format off
1231 #define itkSetVectorMacro(name, type, count) \
1232  virtual void Set##name(type data[]) \
1233  { \
1234  unsigned int i; \
1235  for (i = 0; i < count; ++i) \
1236  { \
1237  ITK_GCC_PRAGMA_PUSH \
1238  ITK_GCC_SUPPRESS_Wfloat_equal \
1239  if (data[i] != this->m_##name[i]) \
1240  { \
1241  break; \
1242  } \
1243  ITK_GCC_PRAGMA_POP \
1244  } \
1245  if (i < count) \
1246  { \
1247  this->Modified(); \
1248  for (i = 0; i < count; ++i) \
1249  { \
1250  this->m_##name[i] = data[i]; \
1251  } \
1252  } \
1253  } \
1254  ITK_MACROEND_NOOP_STATEMENT
1255 // clang-format on
1260 #define itkGetVectorMacro(name, type, count) \
1261  virtual type * Get##name() const { return this->m_##name; } \
1262  ITK_MACROEND_NOOP_STATEMENT
1263 
1268 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel) ITK_MACROEND_NOOP_STATEMENT
1269 
1275 #define itkGPUKernelMacro(kernel) \
1276  kernel \
1277  { \
1278  public: \
1279  ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1280  kernel() = delete; \
1281  ~kernel() = delete; \
1282  static const char * GetOpenCLSource(); \
1283  } \
1284  ITK_MACROEND_NOOP_STATEMENT
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: itkAnnulusOperator.h:24