ITK  5.4.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
71 
81 #define ITK_NOOP_STATEMENT static_assert(true, "")
82 
83 
84 #if defined(ITK_FUTURE_LEGACY_REMOVE)
85 
86 # define ITK_MACROEND_NOOP_STATEMENT ITK_NOOP_STATEMENT
87 #else
88 /* NOTE: The ITK_MACROEND_NOOP_STATEMENT must be defined to nothing
89  * in order to maintain backwards compatibility with earlier macro
90  * uses that may or may not have ';' after the macro is used. */
91 /* Purposefully empty */
92 # define ITK_MACROEND_NOOP_STATEMENT
93 #endif
94 // clang-format on
95 
96 // Define ITK_PRAGMA macro.
97 //
98 // It sets "#pragma" preprocessor directives without expecting the arguments
99 // to be quoted.
100 #define ITK_PRAGMA(x) _Pragma(#x)
101 
102 // The clang compiler has many useful non-default compiler warnings
103 // that tend to have a high false positive rate.
104 // The following set of defines allows us to suppress false positives
105 // and still track down suspicious code
106 #if defined(__clang__) && defined(__has_warning)
107 # define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
108 # define CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
109 # if __has_warning("-Wfloat-equal")
110 # define CLANG_SUPPRESS_Wfloat_equal ITK_PRAGMA(clang diagnostic ignored "-Wfloat-equal")
111 # else
112 # define CLANG_SUPPRESS_Wfloat_equal
113 # endif
114 # if __has_warning("-Wc++14-extensions")
115 # define CLANG_SUPPRESS_Wcpp14_extensions ITK_PRAGMA(clang diagnostic ignored "-Wc++14-extensions")
116 # else
117 # define CLANG_SUPPRESS_Wcpp14_extensions
118 # endif
119 #else
120 # define CLANG_PRAGMA_PUSH
121 # define CLANG_PRAGMA_POP
122 # define CLANG_SUPPRESS_Wfloat_equal
123 # define CLANG_SUPPRESS_Wcpp14_extensions
124 #endif
125 
126 // Intel compiler convenience macros
127 #if defined(__INTEL_COMPILER)
128 # define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
129 # define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
130 # define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
131 #else
132 # define INTEL_PRAGMA_WARN_PUSH
133 # define INTEL_PRAGMA_WARN_POP
134 # define INTEL_SUPPRESS_warning_1292
135 #endif
136 
137 // Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
138 //
139 // This macro sets a pragma diagnostic
140 //
141 // Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
142 //
143 // These macros respectively push and pop the diagnostic context
144 //
145 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
146 # define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
147 # define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
148 # define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
149 #else
150 # define ITK_GCC_PRAGMA_DIAG(x)
151 # define ITK_GCC_PRAGMA_DIAG_PUSH()
152 # define ITK_GCC_PRAGMA_DIAG_POP()
153 #endif
154 
155 /*
156  * ITK only supports MSVC++ 14.2 and greater
157  * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
158  */
159 #if defined(_MSC_VER) && (_MSC_VER < 1920)
160 # error "MSVC versions before Visual Studio 2019 are not supported under ITKv5.4"
161 #endif
162 #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
163 # error "SUNPro C++ < 5.14.0 is not supported under ITKv5 and above"
164 #endif
165 #if defined(__CYGWIN__)
166 # error "The Cygwin compiler is not supported in ITKv4 and above"
167 #endif
168 #if defined(__BORLANDC__)
169 # error "The Borland C compiler is not supported in ITKv4 and above"
170 #endif
171 #if defined(__MWERKS__)
172 # error "The MetroWerks compiler is not supported in ITKv4 and above"
173 #endif
174 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7)
175 # error "GCC < 7 is not supported under ITKv5.4"
176 #endif
177 #if defined(__sgi)
178 // This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
179 // TODO: At some future point, it may be necessary to
180 // define a minimum __sgi version that will work.
181 # error "The SGI compiler is not supported under ITKv4 and above"
182 #endif
183 #if defined(__APPLE__)
184 # if defined(__clang__) && (__cplusplus < 201703L)
185 # error "Apple LLVM compiling with a standard less than C++17 is not supported under ITKv5.4"
186 # endif
187 #elif defined(__clang__) && (__clang_major__ < 5)
188 # error "Clang < 5 is not supported under ITKv5.4"
189 #endif
190 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910)
191 # error "Intel C++ < 19.1 is not supported under ITKv5.4"
192 #endif
193 
194 // Setup symbol exports
195 #if defined(_WIN32) || defined(WIN32)
196 # define ITK_ABI_IMPORT __declspec(dllimport)
197 # define ITK_ABI_EXPORT __declspec(dllexport)
198 # define ITK_ABI_HIDDEN
199 #else
200 # ifdef __GNUC__
201 # define ITK_ABI_IMPORT __attribute__((visibility("default")))
202 # define ITK_ABI_EXPORT __attribute__((visibility("default")))
203 # define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
204 # else
205 # define ITK_ABI_IMPORT
206 # define ITK_ABI_EXPORT
207 # define ITK_ABI_HIDDEN
208 # endif
209 #endif
210 
211 // Setup symbol exports
212 #ifndef ITK_TEMPLATE_EXPORT
213 # ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
214 # define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
215 # else
216 # define ITK_TEMPLATE_EXPORT
217 # endif
218 #endif
219 
220 // Setup symbol exports
221 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
222 # define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
223 #else
224 # define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
225 #endif
226 
227 #ifndef ITK_FORWARD_EXPORT
228 // If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
229 # if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
230  defined(USE_COMPILER_HIDDEN_VISIBILITY)
231 # define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
232 # else
233 # define ITK_FORWARD_EXPORT
234 # endif
235 #endif
236 
237 
238 //-*-*-*
239 // The following deprecations should be removed in ITKV6 and later
240 // NOTE DEPRECATED should be ITK_NOEXCEPT
241 #define ITK_NOEXCEPT_OR_THROW error "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT"
242 // NOTE DEPRECATED! should be ITK_COMPILER_CXX_STATIC_ASSERT
243 #if !defined(ITK_LEGACY_REMOVE)
244 # define ITK_DELETE_FUNCTION = delete
245 #else
246 # define ITK_DELETE_FUNCTION error "Replace ITK_DELETE_FUNCTION with = delete"
247 #endif
248 //-*-*-*
249 
250 // DEPRECATED: These macros are left here for compatibility with remote modules.
251 // Once they have been removed from all known remote modules, this code should
252 // be removed.
253 #if defined(ITK_FUTURE_LEGACY_REMOVE)
254 # define ITK_CONSTEXPR_FUNC "Replace ITK_CONSTEXPR_FUNC with constexpr"
255 # define ITK_CONSTEXPR_VAR "Replace ITK_CONSTEXPR_VAR with constexpr"
256 
257 # define itkExposeEnumValue(name) static_cast<int>(name)
258 // Future remove# define itkExposeEnumValue(name) "Replace type of " # name " with proper enumeration instead of
259 // integer."
260 #else
261 # define ITK_CONSTEXPR_FUNC constexpr
262 # define ITK_CONSTEXPR_VAR constexpr
263 
265 # define itkExposeEnumValue(name) static_cast<int>(name)
266 #endif
267 
268 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
269 # define ITK_FALLTHROUGH [[fallthrough]]
270 #else
271 # define ITK_FALLTHROUGH static_assert(false, "ERROR: ITK_FALLTHROUGH must be replaced with [[fallthrough]]")
272 #endif
273 
294 #define itkNewMacro(x) \
295  itkSimpleNewMacro(x); \
296  itkCreateAnotherMacro(x); \
297  itkCloneMacro(x); \
298  ITK_MACROEND_NOOP_STATEMENT
299 
301 #define itkSimpleNewMacro(x) \
302  static Pointer New() \
303  { \
304  Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
305  if (smartPtr == nullptr) \
306  { \
307  smartPtr = new x(); \
308  } \
309  smartPtr->UnRegister(); \
310  return smartPtr; \
311  } \
312  ITK_MACROEND_NOOP_STATEMENT
313 
314 #define itkCreateAnotherMacro(x) \
315  ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
316  ITK_MACROEND_NOOP_STATEMENT
317 
318 #define itkCloneMacro(x) \
319  Pointer Clone() const \
320  { \
321  Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
322  return rval; \
323  } \
324  ITK_MACROEND_NOOP_STATEMENT
325 
329 #define itkFactoryOnlyNewMacro(x) \
330  itkSimpleFactoryOnlyNewMacro(x); \
331  itkCreateAnotherMacro(x); \
332  itkCloneMacro(x); \
333  ITK_MACROEND_NOOP_STATEMENT
334 
336 #define itkSimpleFactoryOnlyNewMacro(x) \
337  static auto New()->Pointer \
338  { \
339  Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
340  if (smartPtr == nullptr) \
341  { \
342  itkSpecializedMessageExceptionMacro(ExceptionObject, \
343  "Object factory failed to instantiate " << typeid(x).name()); \
344  } \
345  smartPtr->UnRegister(); \
346  return smartPtr; \
347  } \
348  ITK_MACROEND_NOOP_STATEMENT
349 
362 #define itkFactorylessNewMacro(x) \
363  static Pointer New() \
364  { \
365  x * rawPtr = new x(); \
366  Pointer smartPtr = rawPtr; \
367  rawPtr->UnRegister(); \
368  return smartPtr; \
369  } \
370  itkCreateAnotherMacro(x); \
371  ITK_MACROEND_NOOP_STATEMENT
372 
374 //
375 // A macro to disallow the copy constructor, copy assignment,
376 // move constructor, and move assignment functions.
377 // This should be used in the public: declarations for a class
378 //
379 // ITK's paradigm for smart pointer and pipeline consistency
380 // prohibits the use of copy/move construction and copy/move assignment
381 // functions.
382 //
383 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
384  TypeName(const TypeName &) = delete; \
385  TypeName & operator=(const TypeName &) = delete; \
386  TypeName(TypeName &&) = delete; \
387  TypeName & operator=(TypeName &&) = delete
388 
389 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
390 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
391 #else
392 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
393  static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
394 #endif
395 
396 
397 // When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
398 // the ability for operator!= to be rewritten automatically in terms of
399 // operator==, as introduced with C++20. This macro is experimental. It may be
400 // modified, renamed, or removed without backward compatibility support.
401 #if __cplusplus >= 202002L
402 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
403 #endif
404 
405 // Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
406 // is only for internal use within the implementation of ITK. It may be
407 // modified, renamed, or removed without backward compatibility support.
408 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
409 // With C++20, operator!= is automatically rewritten in terms of the
410 // corresponding operator==.
411 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
412 #else
413 // For C++14 and C++17, this macro defines an operator!= member function that
414 // just calls the corresponding operator== member function.
415 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
416  bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
417  ITK_MACROEND_NOOP_STATEMENT
418 #endif
419 
420 
421 // Internal macro (not part of the public ITK API), used to implement `GetNameOfClass()` member functions.
422 #define itkInternalGetNameOfClassImplementationMacro(thisClass) \
423  { \
424  static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
425  "The macro argument `" #thisClass \
426  "` appears incorrect! It should correspond with the name of this class!"); \
427  return #thisClass; \
428  } \
429  ITK_MACROEND_NOOP_STATEMENT
430 
431 
435 #define itkVirtualGetNameOfClassMacro(thisClass) \
436  virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
437 
438 #define itkOverrideGetNameOfClassMacro(thisClass) \
439  const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
440 
441 #ifdef ITK_FUTURE_LEGACY_REMOVE
442 # define itkTypeMacro(thisClass, superclass) \
443  static_assert(false, \
444  "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
445  "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
446 # define itkTypeMacroNoParent(thisClass) \
447  static_assert(false, \
448  "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
449  "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
450 #else
451 
455 # define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
456 # define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
457 #endif
458 
459 
460 namespace itk
461 {
468 extern ITKCommon_EXPORT void
469 OutputWindowDisplayText(const char *);
472 extern ITKCommon_EXPORT void
473 OutputWindowDisplayErrorText(const char *);
474 
475 extern ITKCommon_EXPORT void
476 OutputWindowDisplayWarningText(const char *);
477 
478 extern ITKCommon_EXPORT void
479 OutputWindowDisplayGenericOutputText(const char *);
480 
481 extern ITKCommon_EXPORT void
482 OutputWindowDisplayDebugText(const char *);
483 
484 } // end namespace itk
485 
486 // The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
491 #if defined(NDEBUG)
492 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
493 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
494 #else
495 # define itkDebugMacro(x) \
496  do \
497  { \
498  using namespace ::itk::print_helper; /* for ostream << std::vector<T> */ \
499  if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
500  { \
501  std::ostringstream itkmsg; \
502  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
503  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
504  ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
505  } \
506  } while (0)
507 
509 // The itkDebugStatement is to be used to protect code that is only
510 // used in the itkDebugMacro
511 # define itkDebugStatement(x) x
512 #endif
513 
517 #define itkWarningMacro(x) \
518  do \
519  { \
520  if (::itk::Object::GetGlobalWarningDisplay()) \
521  { \
522  std::ostringstream itkmsg; \
523  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << '\n' \
524  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
525  ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
526  } \
527  } while (0)
528 
530 #define itkWarningStatement(x) x
531 
532 #if defined(ITK_CPP_FUNCTION)
533 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
534 # define ITK_LOCATION __FUNCSIG__
535 # elif defined(__GNUC__)
536 # define ITK_LOCATION __PRETTY_FUNCTION__
537 # else
538 # define ITK_LOCATION __FUNCTION__
539 # endif
540 #else
541 # define ITK_LOCATION "unknown"
542 #endif
543 
544 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
545  namespace itk \
546  { \
547  class newexcp : public parentexcp \
548  { \
549  public: \
550  /* default message provides backward compatibility for a given exception type */ \
551  static constexpr const char * const default_exception_message = whatmessage; \
552  /* Inherit the constructors from its base class. */ \
553  using parentexcp::parentexcp; \
554  itkOverrideGetNameOfClassMacro(newexcp); \
555  }; \
556  } \
557  ITK_MACROEND_NOOP_STATEMENT
558 
559 
560 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
561  { \
562  std::ostringstream exceptionDescriptionOutputStringStream; \
563  exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
564  throw ::itk::ExceptionType( \
565  std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
566  } \
567  ITK_MACROEND_NOOP_STATEMENT
568 
569 #define itkSpecializedExceptionMacro(ExceptionType) \
570  itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
571 
575 #define itkExceptionMacro(x) \
576  itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
577 
578 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
579 
580 #define itkGenericOutputMacro(x) \
581  { \
582  if (::itk::Object::GetGlobalWarningDisplay()) \
583  { \
584  std::ostringstream itkmsg; \
585  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
586  ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
587  } \
588  } \
589  ITK_MACROEND_NOOP_STATEMENT
590 
591 //----------------------------------------------------------------------------
592 // Macros for simplifying the use of logging
593 //
594 #define itkLogMacro(x, y) \
595  { \
596  if (this->GetLogger()) \
597  { \
598  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
599  } \
600  } \
601  ITK_MACROEND_NOOP_STATEMENT
602 
603 #define itkLogMacroStatic(obj, x, y) \
604  { \
605  if (obj->GetLogger()) \
606  { \
607  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
608  } \
609  } \
610  ITK_MACROEND_NOOP_STATEMENT
611 
612 //----------------------------------------------------------------------------
613 // Setup legacy code policy.
614 //
615 // CMake options:
616 // - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
617 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
618 // of legacy code will not produce compiler warnings.
619 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
620 // of legacy code will produce compiler warnings
621 //
622 // ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
623 //
624 // Source files that test the legacy code may define ITK_LEGACY_TEST
625 // like this:
626 //
627 // #define ITK_LEGACY_TEST
628 // #include "itkClassWithDeprecatedMethod.h"
629 //
630 // in order to silence the warnings for calling deprecated methods.
631 // No other source files in ITK should call the methods since they are
632 // provided only for compatibility with older user code.
633 
634 // Define itkLegacyMacro to mark legacy methods where they are
635 // declared in their class. Example usage:
636 //
637 // // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
638 // itkLegacyMacro(void MyMethod());
639 //
640 // See below for what to do for the method definition.
641 #if defined(ITK_LEGACY_REMOVE)
642 # define itkLegacyMacro(method) /* no ';' */
643 #else
644 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
645 // Provide legacy methods with no warnings.
646 # define itkLegacyMacro(method) method
647 # else
648 // Request compile-time warnings for uses of deprecated methods.
649 # define itkLegacyMacro(method) [[deprecated]] method
650 # endif
651 #endif
652 
653 // Macros to create runtime deprecation warning messages in function
654 // bodies. Example usage:
655 //
656 // #if !defined( ITK_LEGACY_REMOVE )
657 // void itkMyClass::MyOldMethod()
658 // {
659 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
660 // }
661 //
662 // void itkMyClass::MyMethod()
663 // {
664 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
665 // itkMyClass::MyOtherMethod);
666 // }
667 // #endif
668 //
669 // NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
670 // itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
671 // are purposefully not defined when ITK_LEGACY_REMOVE is on,
672 // because these macros are only relevant inside code segments
673 // that are conditionally compiled only when ITK_LEGACY_REMOVE
674 // is off.
675 #if defined(ITK_LEGACY_SILENT)
676 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
677 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
678 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
679 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
680 #else
681 # define itkLegacyBodyMacro(method, version) \
682  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
683 # define itkLegacyReplaceBodyMacro(method, version, replace) \
684  itkWarningMacro(#method " was deprecated for ITK " #version \
685  " and will be removed in a future version. Use " #replace " instead.")
686 # define itkGenericLegacyBodyMacro(method, version) \
687  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
688 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
689  itkGenericOutputMacro(#method " was deprecated for ITK " #version \
690  " and will be removed in a future version. Use " #replace " instead.")
691 #endif
692 
693 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
694 // the cache lines. By aligning multi-threaded structures with the
695 // cache lines, false shared can be reduced, and performance
696 // increased.
697 #define ITK_CACHE_LINE_ALIGNMENT 64
698 
699 //
700 // itkPadStruct will add padding to a structure to ensure a minimum size
701 // for ensuring that adjacent structures do not share CACHE lines.
702 // Each struct will take up some multiple of cacheline sizes.
703 // This is particularly useful for arrays of thread private variables.
704 //
705 #define itkPadStruct(mincachesize, oldtype, newtype) \
706  struct newtype : public oldtype \
707  { \
708  char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
709  };
710 
711 //
712 // itkAlignedTypedef is a macro which creates a new type to make a
713 // data structure aligned.
714 //
715 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
716 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
717 #elif defined(_MSC_VER)
718 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
719 #else
720 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
721 #endif
722 
723 #if defined(ITK_FUTURE_LEGACY_REMOVE)
724 //=============================================================================
725 /*
726 NOTE: DEPRECATED - This macro is not longer needed to support modern
727 compilers.
728 
729  Define a common way of declaring a templated function as a friend inside a class.
730  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
731 
732  The following templated function
733 
734  template <T>
735  T add(const T & a, const T & b);
736 
737  is declared as friend with
738 
739  class A
740  {
741  public:
742  friend Self add<>( const Self & a, const Self & b );
743  }
744 
745 */
746 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
747 #else // LEGACY_REMOVE
748 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
749 #endif
750 
751 //--------------------------------------------------------------------------------
752 // Helper macros for Template Meta-Programming techniques of for-loops
753 // unrolling
754 //--------------------------------------------------------------------------------
755 
756 //--------------------------------------------------------------------------------
757 // Macro that generates an unrolled for loop for assigning elements of one array
758 // to elements of another array The array are assumed to be of same length
759 // (dimension), and this is also assumed to be the value of NumberOfIterations.
760 // No verification of size is performed. Casting is performed as part of the
761 // assignment, by using the DestinationElementType as the casting type.
762 // Source and destination array types must have defined operator[] in their
763 // API.
764 #define itkForLoopAssignmentMacro( \
765  DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
766  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
767  { \
768  DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
769  }
770 
771 //--------------------------------------------------------------------------------
772 // Macro that generates an unrolled for loop for rounding and assigning
773 // elements of one array to elements of another array The array are assumed to
774 // be of same length (dimension), and this is also assumed to be the value of
775 // NumberOfIterations. No verification of size is performed. Casting is
776 // performed as part of the assignment, by using the DestinationElementType as
777 // the casting type.
778 // Source and destination array types must have defined operator[] in their
779 // API.
780 #define itkForLoopRoundingAndAssignmentMacro( \
781  DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
782  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
783  { \
784  DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
785  }
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  CLANG_PRAGMA_PUSH \
891  CLANG_SUPPRESS_Wfloat_equal \
892  if (oldInput && oldInput->Get() == _arg) \
893  { \
894  return; \
895  } \
896  CLANG_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  CLANG_PRAGMA_PUSH \
1002  CLANG_SUPPRESS_Wfloat_equal \
1003  if (this->m_##name != _arg) \
1004  { \
1005  this->m_##name = std::move(_arg); \
1006  this->Modified(); \
1007  } \
1008  CLANG_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  CLANG_PRAGMA_PUSH \
1104  CLANG_SUPPRESS_Wfloat_equal \
1105  if (this->m_##name != temp_extrema) \
1106  { \
1107  this->m_##name = temp_extrema; \
1108  this->Modified(); \
1109  } \
1110  CLANG_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 
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 
1226 // clang-format off
1230 #define itkSetVectorMacro(name, type, count) \
1231  virtual void Set##name(type data[]) \
1232  { \
1233  unsigned int i; \
1234  for (i = 0; i < count; ++i) \
1235  { \
1236  CLANG_PRAGMA_PUSH \
1237  CLANG_SUPPRESS_Wfloat_equal \
1238  if (data[i] != this->m_##name[i]) \
1239  { \
1240  break; \
1241  } \
1242  CLANG_PRAGMA_POP \
1243  } \
1244  if (i < count) \
1245  { \
1246  this->Modified(); \
1247  for (i = 0; i < count; ++i) \
1248  { \
1249  this->m_##name[i] = data[i]; \
1250  } \
1251  } \
1252  } \
1253  ITK_MACROEND_NOOP_STATEMENT
1254 // clang-format on
1259 #define itkGetVectorMacro(name, type, count) \
1260  virtual type * Get##name() const { return this->m_##name; } \
1261  ITK_MACROEND_NOOP_STATEMENT
1262 
1267 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1268 
1274 #define itkGPUKernelMacro(kernel) \
1275  kernel \
1276  { \
1277  public: \
1278  ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1279  kernel() = delete; \
1280  ~kernel() = delete; \
1281  static const char * GetOpenCLSource(); \
1282  }
1283 
1285 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1286  static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); }
1287 
1288 // A useful macro in the PrintSelf method for printing member variables
1289 // which are pointers to object based on the LightObject class.
1290 #define itkPrintSelfObjectMacro(name) \
1291  if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1292  { \
1293  os << indent << #name << ": (null)" << std::endl; \
1294  } \
1295  else \
1296  { \
1297  os << indent << #name << ": " << std::endl; \
1298  this->m_##name->Print(os, indent.GetNextIndent()); \
1299  } \
1300  ITK_MACROEND_NOOP_STATEMENT
1301 
1302 
1304 #define itkSetDecoratedOutputMacro(name, type) \
1305  virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1306  { \
1307  itkDebugMacro("setting output " #name " to " << _arg); \
1308  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1309  { \
1310  this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1311  this->Modified(); \
1312  } \
1313  } \
1314  virtual void Set##name(const type & _arg) \
1315  { \
1316  using DecoratorType = SimpleDataObjectDecorator<type>; \
1317  itkDebugMacro("setting output " #name " to " << _arg); \
1318  DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1319  if (output) \
1320  { \
1321  if (output->Get() == _arg) \
1322  { \
1323  return; \
1324  } \
1325  else \
1326  { \
1327  output->Set(_arg); \
1328  } \
1329  } \
1330  else \
1331  { \
1332  auto newOutput = DecoratorType::New(); \
1333  newOutput->Set(_arg); \
1334  this->Set##name##Output(newOutput); \
1335  } \
1336  } \
1337  ITK_MACROEND_NOOP_STATEMENT
1338 
1341 #define itkGetDecoratedOutputMacro(name, type) \
1342  virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1343  { \
1344  itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1345  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1346  } \
1347  virtual const type & Get##name() const \
1348  { \
1349  itkDebugMacro("Getting output " #name); \
1350  using DecoratorType = SimpleDataObjectDecorator<type>; \
1351  const DecoratorType * output = \
1352  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1353  if (output == nullptr) \
1354  { \
1355  itkExceptionMacro("output" #name " is not set"); \
1356  } \
1357  return output->Get(); \
1358  } \
1359  ITK_MACROEND_NOOP_STATEMENT
1360 
1372 #if defined(ITKV4_COMPATIBILITY)
1373 # define ITK_ITERATOR_VIRTUAL virtual
1374 # define ITK_ITERATOR_OVERRIDE override
1375 # define ITK_ITERATOR_FINAL
1376 #elif !defined(ITK_LEGACY_REMOVE)
1377 # define ITK_ITERATOR_VIRTUAL virtual
1378 # define ITK_ITERATOR_OVERRIDE override
1379 # define ITK_ITERATOR_FINAL final
1380 #else
1381 # define ITK_ITERATOR_VIRTUAL
1382 # define ITK_ITERATOR_OVERRIDE
1383 # define ITK_ITERATOR_FINAL
1384 #endif
1385 
1386 #if defined(ITKV4_COMPATIBILITY)
1387 // A macro for methods which are const in ITKv5, but not in ITKv4
1388 # define ITKv5_CONST
1389 #else
1390 // A macro for methods which are const in ITKv5, but not in ITKv4
1391 # define ITKv5_CONST const
1392 #endif
1393 
1394 #define itkExceptionObject_h
1395 #include "itkExceptionObject.h"
1396 #undef itkExceptionObject_h
1397 
1405 template <typename TTarget, typename TSource>
1406 TTarget
1407 itkDynamicCastInDebugMode(TSource x)
1408 {
1409 #ifndef NDEBUG
1410  if (x == nullptr)
1411  {
1412  return nullptr;
1413  }
1414  TTarget rval = dynamic_cast<TTarget>(x);
1415  if (rval == nullptr)
1416  {
1417  itkGenericExceptionMacro("Failed dynamic cast to " << typeid(TTarget).name()
1418  << " object type = " << x->GetNameOfClass());
1419  }
1420  return rval;
1421 #else
1422  return static_cast<TTarget>(x);
1423 #endif
1424 }
1427 #ifdef ITK_LEGACY_REMOVE
1428 # if __cplusplus >= 202002L
1429 # define ITK_NODISCARD(message) [[nodiscard(message)]]
1430 # else
1431 # define ITK_NODISCARD(message) [[nodiscard]]
1432 # endif
1433 #else
1434 # define ITK_NODISCARD(message)
1435 #endif
1436 
1437 // Defines which used to be in itk_compiler_detection.h
1438 #define ITK_ALIGNAS(X) alignas(X)
1439 #define ITK_ALIGNOF(X) alignof(X)
1440 #define ITK_DEPRECATED [[deprecated]]
1441 #define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1442 #define ITK_CONSTEXPR constexpr
1443 #define ITK_DELETED_FUNCTION = delete
1444 #define ITK_EXTERN_TEMPLATE extern
1445 #define ITK_FINAL final
1446 #define ITK_NOEXCEPT noexcept
1447 #define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1448 #define ITK_NULLPTR nullptr
1449 #define ITK_OVERRIDE override
1450 #define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1451 #define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1452 #define ITK_THREAD_LOCAL thread_local
1453 
1454 #endif // end of 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