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 #endif
52 
53 #include <sstream>
54 
59 namespace itk
60 {
61 // end namespace itk - this is here for documentation purposes
62 }
63 
66 #define itkNotUsed(x)
67 
68 // clang-format off
69 
79 #define ITK_NOOP_STATEMENT static_assert(true, "")
80 
81 
82 #if defined(ITK_FUTURE_LEGACY_REMOVE)
83 
84 # define ITK_MACROEND_NOOP_STATEMENT ITK_NOOP_STATEMENT
85 #else
86 /* NOTE: The ITK_MACROEND_NOOP_STATEMENT must be defined to nothing
87  * in order to maintain backwards compatibility with earlier macro
88  * uses that may or may not have ';' after the macro is used. */
89 /* Purposefully empty */
90 # define ITK_MACROEND_NOOP_STATEMENT
91 #endif
92 // clang-format on
93 
94 // Define ITK_PRAGMA macro.
95 //
96 // It sets "#pragma" preprocessor directives without expecting the arguments
97 // to be quoted.
98 #define ITK_PRAGMA(x) _Pragma(#x)
99 
100 // The clang compiler has many useful non-default compiler warnings
101 // that tend to have a high false positive rate.
102 // The following set of defines allows us to suppress false positives
103 // and still track down suspicious code
104 #if defined(__clang__) && defined(__has_warning)
105 # define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
106 # define CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
107 # if __has_warning("-Wfloat-equal")
108 # define CLANG_SUPPRESS_Wfloat_equal ITK_PRAGMA(clang diagnostic ignored "-Wfloat-equal")
109 # else
110 # define CLANG_SUPPRESS_Wfloat_equal
111 # endif
112 # if __has_warning("-Wc++14-extensions")
113 # define CLANG_SUPPRESS_Wcpp14_extensions ITK_PRAGMA(clang diagnostic ignored "-Wc++14-extensions")
114 # else
115 # define CLANG_SUPPRESS_Wcpp14_extensions
116 # endif
117 #else
118 # define CLANG_PRAGMA_PUSH
119 # define CLANG_PRAGMA_POP
120 # define CLANG_SUPPRESS_Wfloat_equal
121 # define CLANG_SUPPRESS_Wcpp14_extensions
122 #endif
123 
124 // Intel compiler convenience macros
125 #if defined(__INTEL_COMPILER)
126 # define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
127 # define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
128 # define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
129 #else
130 # define INTEL_PRAGMA_WARN_PUSH
131 # define INTEL_PRAGMA_WARN_POP
132 # define INTEL_SUPPRESS_warning_1292
133 #endif
134 
135 // Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
136 //
137 // This macro sets a pragma diagnostic
138 //
139 // Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
140 //
141 // These macros respectively push and pop the diagnostic context
142 //
143 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
144 # define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
145 # define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
146 # define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
147 #else
148 # define ITK_GCC_PRAGMA_DIAG(x)
149 # define ITK_GCC_PRAGMA_DIAG_PUSH()
150 # define ITK_GCC_PRAGMA_DIAG_POP()
151 #endif
152 
153 /*
154  * ITK only supports MSVC++ 14.2 and greater
155  * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
156  */
157 #if defined(_MSC_VER) && (_MSC_VER < 1920)
158 # error "MSVC versions before Visual Studio 2019 are not supported under ITKv5.4"
159 #endif
160 #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
161 # error "SUNPro C++ < 5.14.0 is not supported under ITKv5 and above"
162 #endif
163 #if defined(__CYGWIN__)
164 # error "The Cygwin compiler is not supported in ITKv4 and above"
165 #endif
166 #if defined(__BORLANDC__)
167 # error "The Borland C compiler is not supported in ITKv4 and above"
168 #endif
169 #if defined(__MWERKS__)
170 # error "The MetroWerks compiler is not supported in ITKv4 and above"
171 #endif
172 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7)
173 # error "GCC < 7 is not supported under ITKv5.4"
174 #endif
175 #if defined(__sgi)
176 // This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
177 // TODO: At some future point, it may be necessary to
178 // define a minimum __sgi version that will work.
179 # error "The SGI compiler is not supported under ITKv4 and above"
180 #endif
181 #if defined(__APPLE__)
182 # if defined(__clang__) && (__cplusplus < 201703L)
183 # error "Apple LLVM compiling with a standard less than C++17 is not supported under ITKv5.4"
184 # endif
185 #elif defined(__clang__) && (__clang_major__ < 5)
186 # error "Clang < 5 is not supported under ITKv5.4"
187 #endif
188 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910)
189 # error "Intel C++ < 19.1 is not supported under ITKv5.4"
190 #endif
191 
192 // Setup symbol exports
193 #if defined(_WIN32) || defined(WIN32)
194 # define ITK_ABI_IMPORT __declspec(dllimport)
195 # define ITK_ABI_EXPORT __declspec(dllexport)
196 # define ITK_ABI_HIDDEN
197 #else
198 # ifdef __GNUC__
199 # define ITK_ABI_IMPORT __attribute__((visibility("default")))
200 # define ITK_ABI_EXPORT __attribute__((visibility("default")))
201 # define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
202 # else
203 # define ITK_ABI_IMPORT
204 # define ITK_ABI_EXPORT
205 # define ITK_ABI_HIDDEN
206 # endif
207 #endif
208 
209 // Setup symbol exports
210 #ifndef ITK_TEMPLATE_EXPORT
211 # ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
212 # define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
213 # else
214 # define ITK_TEMPLATE_EXPORT
215 # endif
216 #endif
217 
218 // Setup symbol exports
219 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
220 # define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
221 #else
222 # define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
223 #endif
224 
225 #ifndef ITK_FORWARD_EXPORT
226 // If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
227 # if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
228  defined(USE_COMPILER_HIDDEN_VISIBILITY)
229 # define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
230 # else
231 # define ITK_FORWARD_EXPORT
232 # endif
233 #endif
234 
235 
236 //-*-*-*
237 // The following deprecations should be removed in ITKV6 and later
238 // NOTE DEPRECATED should be ITK_NOEXCEPT
239 #define ITK_NOEXCEPT_OR_THROW error "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT"
240 // NOTE DEPRECATED! should be ITK_COMPILER_CXX_STATIC_ASSERT
241 #if !defined(ITK_LEGACY_REMOVE)
242 # define ITK_DELETE_FUNCTION = delete
243 #else
244 # define ITK_DELETE_FUNCTION error "Replace ITK_DELETE_FUNCTION with = delete"
245 #endif
246 //-*-*-*
247 
248 // DEPRECATED: These macros are left here for compatibility with remote modules.
249 // Once they have been removed from all known remote modules, this code should
250 // be removed.
251 #if defined(ITK_FUTURE_LEGACY_REMOVE)
252 # define ITK_CONSTEXPR_FUNC "Replace ITK_CONSTEXPR_FUNC with constexpr"
253 # define ITK_CONSTEXPR_VAR "Replace ITK_CONSTEXPR_VAR with constexpr"
254 
255 # define itkExposeEnumValue(name) static_cast<int>(name)
256 // Future remove# define itkExposeEnumValue(name) "Replace type of " # name " with proper enumeration instead of
257 // integer."
258 #else
259 # define ITK_CONSTEXPR_FUNC constexpr
260 # define ITK_CONSTEXPR_VAR constexpr
261 
263 # define itkExposeEnumValue(name) static_cast<int>(name)
264 #endif
265 
266 // Use "ITK_FALLTHROUGH;" to annotate deliberate fall-through in switches,
267 // use it analogously to "break;". The trailing semi-colon is required.
268 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
269 # if (__GNUC__ >= 7)
270 # define ITK_FALLTHROUGH __attribute__((fallthrough))
271 # endif
272 #elif defined(__has_warning)
273 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
274 # define ITK_FALLTHROUGH [[clang::fallthrough]]
275 # endif
276 #endif
277 
278 #ifndef ITK_FALLTHROUGH
279 # define ITK_FALLTHROUGH ((void)0)
280 #endif
281 
302 #define itkNewMacro(x) \
303  itkSimpleNewMacro(x); \
304  itkCreateAnotherMacro(x); \
305  itkCloneMacro(x); \
306  ITK_MACROEND_NOOP_STATEMENT
307 
309 #define itkSimpleNewMacro(x) \
310  static Pointer New() \
311  { \
312  Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
313  if (smartPtr == nullptr) \
314  { \
315  smartPtr = new x; \
316  } \
317  smartPtr->UnRegister(); \
318  return smartPtr; \
319  } \
320  ITK_MACROEND_NOOP_STATEMENT
321 
322 #define itkCreateAnotherMacro(x) \
323  ::itk::LightObject::Pointer CreateAnother() const override \
324  { \
325  ::itk::LightObject::Pointer smartPtr; \
326  smartPtr = x::New().GetPointer(); \
327  return smartPtr; \
328  } \
329  ITK_MACROEND_NOOP_STATEMENT
330 
331 #define itkCloneMacro(x) \
332  Pointer Clone() const \
333  { \
334  Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
335  return rval; \
336  } \
337  ITK_MACROEND_NOOP_STATEMENT
338 
342 #define itkFactoryOnlyNewMacro(x) \
343  itkSimpleFactoryOnlyNewMacro(x); \
344  itkCreateAnotherMacro(x); \
345  itkCloneMacro(x); \
346  ITK_MACROEND_NOOP_STATEMENT
347 
349 #define itkSimpleFactoryOnlyNewMacro(x) \
350  static auto New()->Pointer \
351  { \
352  Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
353  if (smartPtr == nullptr) \
354  { \
355  itkSpecializedMessageExceptionMacro(ExceptionObject, \
356  "Object factory failed to instantiate " << typeid(x).name()); \
357  } \
358  smartPtr->UnRegister(); \
359  return smartPtr; \
360  } \
361  ITK_MACROEND_NOOP_STATEMENT
362 
375 #define itkFactorylessNewMacro(x) \
376  static Pointer New() \
377  { \
378  Pointer smartPtr; \
379  x * rawPtr = new x; \
380  smartPtr = rawPtr; \
381  rawPtr->UnRegister(); \
382  return smartPtr; \
383  } \
384  ::itk::LightObject::Pointer CreateAnother() const override \
385  { \
386  ::itk::LightObject::Pointer smartPtr; \
387  smartPtr = x::New().GetPointer(); \
388  return smartPtr; \
389  } \
390  ITK_MACROEND_NOOP_STATEMENT
391 
393 //
394 // A macro to disallow the copy constructor, copy assignment,
395 // move constructor, and move assignment functions.
396 // This should be used in the public: declarations for a class
397 //
398 // ITK's paradigm for smart pointer and pipeline consistency
399 // prohibits the use of copy/move construction and copy/move assignment
400 // functions.
401 //
402 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
403  TypeName(const TypeName &) = delete; \
404  TypeName & operator=(const TypeName &) = delete; \
405  TypeName(TypeName &&) = delete; \
406  TypeName & operator=(TypeName &&) = delete
407 
408 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
409 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
410 #else
411 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
412  static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
413 #endif
414 
415 
416 // When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
417 // the ability for operator!= to be rewritten automatically in terms of
418 // operator==, as introduced with C++20. This macro is experimental. It may be
419 // modified, renamed, or removed without backward compatibility support.
420 #if __cplusplus >= 202002L
421 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
422 #endif
423 
424 // Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
425 // is only for internal use within the implementation of ITK. It may be
426 // modified, renamed, or removed without backward compatibility support.
427 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
428 // With C++20, operator!= is automatically rewritten in terms of the
429 // corresponding operator==.
430 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
431 #else
432 // For C++14 and C++17, this macro defines an operator!= member function that
433 // just calls the corresponding operator== member function.
434 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
435  bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
436  ITK_MACROEND_NOOP_STATEMENT
437 #endif
438 
441 #define itkTypeMacro(thisClass, superclass) \
442  const char * GetNameOfClass() const override { return #thisClass; } \
443  ITK_MACROEND_NOOP_STATEMENT
444 
445 #define itkTypeMacroNoParent(thisClass) \
446  virtual const char * GetNameOfClass() const { return #thisClass; } \
447  ITK_MACROEND_NOOP_STATEMENT
448 
449 namespace itk
450 {
457 extern ITKCommon_EXPORT void
458 OutputWindowDisplayText(const char *);
461 extern ITKCommon_EXPORT void
462 OutputWindowDisplayErrorText(const char *);
463 
464 extern ITKCommon_EXPORT void
465 OutputWindowDisplayWarningText(const char *);
466 
467 extern ITKCommon_EXPORT void
468 OutputWindowDisplayGenericOutputText(const char *);
469 
470 extern ITKCommon_EXPORT void
471 OutputWindowDisplayDebugText(const char *);
472 } // end namespace itk
473 
474 // The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
479 #if defined(NDEBUG)
480 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
481 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
482 #else
483 # define itkDebugMacro(x) \
484  do \
485  { \
486  if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
487  { \
488  std::ostringstream itkmsg; \
489  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
490  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
491  ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
492  } \
493  } while (0)
494 
496 // The itkDebugStatement is to be used to protect code that is only
497 // used in the itkDebugMacro
498 # define itkDebugStatement(x) x
499 #endif
500 
504 #define itkWarningMacro(x) \
505  do \
506  { \
507  if (::itk::Object::GetGlobalWarningDisplay()) \
508  { \
509  std::ostringstream itkmsg; \
510  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << '\n' \
511  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
512  ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
513  } \
514  } while (0)
515 
517 #define itkWarningStatement(x) x
518 
519 #if defined(ITK_CPP_FUNCTION)
520 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
521 # define ITK_LOCATION __FUNCSIG__
522 # elif defined(__GNUC__)
523 # define ITK_LOCATION __PRETTY_FUNCTION__
524 # else
525 # define ITK_LOCATION __FUNCTION__
526 # endif
527 #else
528 # define ITK_LOCATION "unknown"
529 #endif
530 
531 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
532  namespace itk \
533  { \
534  class newexcp : public parentexcp \
535  { \
536  public: \
537  /* default message provides backward compatibility for a given exception type */ \
538  static constexpr const char * const default_exception_message = whatmessage; \
539  /* Inherit the constructors from its base class. */ \
540  using parentexcp::parentexcp; \
541  itkTypeMacro(newexcp, parentexcp); \
542  }; \
543  } \
544  ITK_MACROEND_NOOP_STATEMENT
545 
546 
547 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
548  { \
549  std::ostringstream exceptionDescriptionOutputStringStream; \
550  exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
551  throw ::itk::ExceptionType( \
552  std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
553  } \
554  ITK_MACROEND_NOOP_STATEMENT
555 
556 #define itkSpecializedExceptionMacro(ExceptionType) \
557  itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
558 
562 #define itkExceptionMacro(x) \
563  itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
564 
565 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
566 
567 #define itkGenericOutputMacro(x) \
568  { \
569  if (::itk::Object::GetGlobalWarningDisplay()) \
570  { \
571  std::ostringstream itkmsg; \
572  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
573  ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
574  } \
575  } \
576  ITK_MACROEND_NOOP_STATEMENT
577 
578 //----------------------------------------------------------------------------
579 // Macros for simplifying the use of logging
580 //
581 #define itkLogMacro(x, y) \
582  { \
583  if (this->GetLogger()) \
584  { \
585  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
586  } \
587  } \
588  ITK_MACROEND_NOOP_STATEMENT
589 
590 #define itkLogMacroStatic(obj, x, y) \
591  { \
592  if (obj->GetLogger()) \
593  { \
594  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
595  } \
596  } \
597  ITK_MACROEND_NOOP_STATEMENT
598 
599 //----------------------------------------------------------------------------
600 // Setup legacy code policy.
601 //
602 // CMake options:
603 // - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
604 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
605 // of legacy code will not produce compiler warnings.
606 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
607 // of legacy code will produce compiler warnings
608 //
609 // ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
610 //
611 // Source files that test the legacy code may define ITK_LEGACY_TEST
612 // like this:
613 //
614 // #define ITK_LEGACY_TEST
615 // #include "itkClassWithDeprecatedMethod.h"
616 //
617 // in order to silence the warnings for calling deprecated methods.
618 // No other source files in ITK should call the methods since they are
619 // provided only for compatibility with older user code.
620 
621 // Define itkLegacyMacro to mark legacy methods where they are
622 // declared in their class. Example usage:
623 //
624 // // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
625 // itkLegacyMacro(void MyMethod());
626 //
627 // See below for what to do for the method definition.
628 #if defined(ITK_LEGACY_REMOVE)
629 # define itkLegacyMacro(method) /* no ';' */
630 #else
631 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
632 // Provide legacy methods with no warnings.
633 # define itkLegacyMacro(method) method
634 # else
635 // Request compile-time warnings for uses of deprecated methods.
636 # define itkLegacyMacro(method) [[deprecated]] method
637 # endif
638 #endif
639 
640 // Macros to create runtime deprecation warning messages in function
641 // bodies. Example usage:
642 //
643 // #if !defined( ITK_LEGACY_REMOVE )
644 // void itkMyClass::MyOldMethod()
645 // {
646 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
647 // }
648 //
649 // void itkMyClass::MyMethod()
650 // {
651 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
652 // itkMyClass::MyOtherMethod);
653 // }
654 // #endif
655 //
656 // NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
657 // itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
658 // are purposefully not defined when ITK_LEGACY_REMOVE is on,
659 // because these macros are only relevant inside code segments
660 // that are conditionally compiled only when ITK_LEGACY_REMOVE
661 // is off.
662 #if defined(ITK_LEGACY_SILENT)
663 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
664 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
665 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
666 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
667 #else
668 # define itkLegacyBodyMacro(method, version) \
669  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
670 # define itkLegacyReplaceBodyMacro(method, version, replace) \
671  itkWarningMacro(#method " was deprecated for ITK " #version \
672  " and will be removed in a future version. Use " #replace " instead.")
673 # define itkGenericLegacyBodyMacro(method, version) \
674  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
675 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
676  itkGenericOutputMacro(#method " was deprecated for ITK " #version \
677  " and will be removed in a future version. Use " #replace " instead.")
678 #endif
679 
680 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
681 // the cache lines. By aligning multi-threaded structures with the
682 // cache lines, false shared can be reduced, and performance
683 // increased.
684 #define ITK_CACHE_LINE_ALIGNMENT 64
685 
686 //
687 // itkPadStruct will add padding to a structure to ensure a minimum size
688 // for ensuring that adjacent structures do not share CACHE lines.
689 // Each struct will take up some multiple of cacheline sizes.
690 // This is particularly useful for arrays of thread private variables.
691 //
692 #define itkPadStruct(mincachesize, oldtype, newtype) \
693  struct newtype : public oldtype \
694  { \
695  char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
696  };
697 
698 //
699 // itkAlignedTypedef is a macro which creates a new type to make a
700 // data structure aligned.
701 //
702 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
703 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
704 #elif defined(_MSC_VER)
705 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
706 #else
707 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
708 #endif
709 
710 #if defined(ITK_FUTURE_LEGACY_REMOVE)
711 //=============================================================================
712 /*
713 NOTE: DEPRECATED - This macro is not longer needed to support modern
714 compilers.
715 
716  Define a common way of declaring a templated function as a friend inside a class.
717  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
718 
719  The following templated function
720 
721  template <T>
722  T add(const T & a, const T & b);
723 
724  is declared as friend with
725 
726  class A
727  {
728  public:
729  friend Self add<>( const Self & a, const Self & b );
730  }
731 
732 */
733 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
734 #else // LEGACY_REMOVE
735 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
736 #endif
737 
738 //--------------------------------------------------------------------------------
739 // Helper macros for Template Meta-Programming techniques of for-loops
740 // unrolling
741 //--------------------------------------------------------------------------------
742 
743 //--------------------------------------------------------------------------------
744 // Macro that generates an unrolled for loop for assigning elements of one array
745 // to elements of another array The array are assumed to be of same length
746 // (dimension), and this is also assumed to be the value of NumberOfIterations.
747 // No verification of size is performed. Casting is performed as part of the
748 // assignment, by using the DestinationElementType as the casting type.
749 // Source and destination array types must have defined operator[] in their
750 // API.
751 #define itkForLoopAssignmentMacro( \
752  DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
753  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
754  { \
755  DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
756  }
757 
758 //--------------------------------------------------------------------------------
759 // Macro that generates an unrolled for loop for rounding and assigning
760 // elements of one array to elements of another array The array are assumed to
761 // be of same length (dimension), and this is also assumed to be the value of
762 // NumberOfIterations. No verification of size is performed. Casting is
763 // performed as part of the assignment, by using the DestinationElementType as
764 // the casting type.
765 // Source and destination array types must have defined operator[] in their
766 // API.
767 #define itkForLoopRoundingAndAssignmentMacro( \
768  DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
769  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
770  { \
771  DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
772  }
773 
774 // end of Template Meta Programming helper macros
775 
776 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
777 
778 # ifdef __GLIBC__
779 # define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
780 # else
781 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
782 # endif
783 
784 #else
785 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
786 #endif
787 
788 #define itkAssertOrThrowMacro(test, message) \
789  if (!(test)) \
790  { \
791  std::ostringstream msgstr; \
792  msgstr << message; \
793  itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
794  } \
795  ITK_MACROEND_NOOP_STATEMENT
796 
797 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
798 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
799 #else
800 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
801 #endif
802 
803 
804 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
805 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
806 // !! The ITK Get/Set Macros for various types !!
807 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
808 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
809 
810 #ifdef ITK_FUTURE_LEGACY_REMOVE
811 # define itkStaticConstMacro(name, type, value) \
812  "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
813 # define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
814 #else
815 
829 # define itkStaticConstMacro(name, type, value) static constexpr type name = value
830 
831 # define itkGetStaticConstMacro(name) (Self::name)
832 #endif
833 
835 #define itkSetInputMacro(name, type) \
836  virtual void Set##name(const type * _arg) \
837  { \
838  itkDebugMacro("setting input " #name " to " << _arg); \
839  if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
840  { \
841  this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
842  this->Modified(); \
843  } \
844  } \
845  ITK_MACROEND_NOOP_STATEMENT
846 
849 #define itkGetInputMacro(name, type) \
850  virtual const type * Get##name() const \
851  { \
852  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
853  return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
854  } \
855  ITK_MACROEND_NOOP_STATEMENT
856 
858 // clang-format off
860 #define itkSetDecoratedInputMacro(name, type) \
861  virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
862  { \
863  itkDebugMacro("setting input " #name " to " << _arg); \
864  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
865  { \
866  this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
867  this->Modified(); \
868  } \
869  } \
870  virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
871  virtual void Set##name(const type & _arg) \
872  { \
873  using DecoratorType = SimpleDataObjectDecorator<type>; \
874  itkDebugMacro("setting input " #name " to " << _arg); \
875  const DecoratorType * oldInput = \
876  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
877  CLANG_PRAGMA_PUSH \
878  CLANG_SUPPRESS_Wfloat_equal \
879  if (oldInput && oldInput->Get() == _arg) \
880  { \
881  return; \
882  } \
883  CLANG_PRAGMA_POP \
884  auto newInput = DecoratorType::New(); \
885  newInput->Set(_arg); \
886  this->Set##name##Input(newInput); \
887  } \
888  ITK_MACROEND_NOOP_STATEMENT
889 // clang-format on
893 #define itkGetDecoratedInputMacro(name, type) \
894  virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
895  { \
896  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
897  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
898  } \
899  virtual const type & Get##name() const \
900  { \
901  itkDebugMacro("Getting input " #name); \
902  using DecoratorType = SimpleDataObjectDecorator<type>; \
903  const DecoratorType * input = \
904  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
905  if (input == nullptr) \
906  { \
907  itkExceptionMacro("input" #name " is not set"); \
908  } \
909  return input->Get(); \
910  } \
911  ITK_MACROEND_NOOP_STATEMENT
912 
916 #define itkSetGetDecoratedInputMacro(name, type) \
917  itkSetDecoratedInputMacro(name, type); \
918  itkGetDecoratedInputMacro(name, type)
919 
924 #define itkSetDecoratedObjectInputMacro(name, type) \
925  virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
926  { \
927  itkDebugMacro("setting input " #name " to " << _arg); \
928  if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
929  { \
930  this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
931  this->Modified(); \
932  } \
933  } \
934  virtual void Set##name(const type * _arg) \
935  { \
936  using DecoratorType = DataObjectDecorator<type>; \
937  itkDebugMacro("setting input " #name " to " << _arg); \
938  const DecoratorType * oldInput = \
939  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
940  if (oldInput && oldInput->Get() == _arg) \
941  { \
942  return; \
943  } \
944  auto newInput = DecoratorType::New(); \
945  newInput->Set(_arg); \
946  this->Set##name##Input(newInput); \
947  } \
948  ITK_MACROEND_NOOP_STATEMENT
949 
955 #define itkGetDecoratedObjectInputMacro(name, type) \
956  virtual const DataObjectDecorator<type> * Get##name##Input() const \
957  { \
958  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
959  return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
960  } \
961  virtual const type * Get##name() const \
962  { \
963  itkDebugMacro("Getting input " #name); \
964  using DecoratorType = DataObjectDecorator<type>; \
965  const DecoratorType * input = \
966  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
967  if (input == nullptr) \
968  { \
969  return nullptr; \
970  } \
971  return input->Get(); \
972  } \
973  ITK_MACROEND_NOOP_STATEMENT
974 
978 #define itkSetGetDecoratedObjectInputMacro(name, type) \
979  itkSetDecoratedObjectInputMacro(name, type); \
980  itkGetDecoratedObjectInputMacro(name, type)
981 
983 // clang-format off
984 #define itkSetMacro(name, type) \
985  virtual void Set##name(type _arg) \
986  { \
987  itkDebugMacro("setting " #name " to " << _arg); \
988  CLANG_PRAGMA_PUSH \
989  CLANG_SUPPRESS_Wfloat_equal \
990  if (this->m_##name != _arg) \
991  { \
992  this->m_##name = std::move(_arg); \
993  this->Modified(); \
994  } \
995  CLANG_PRAGMA_POP \
996  } \
997  ITK_MACROEND_NOOP_STATEMENT
998 // clang-format on
999 
1001 #define itkGetMacro(name, type) \
1002  virtual type Get##name() { return this->m_##name; } \
1003  ITK_MACROEND_NOOP_STATEMENT
1004 
1009 #define itkGetConstMacro(name, type) \
1010  virtual type Get##name() const { return this->m_##name; } \
1011  ITK_MACROEND_NOOP_STATEMENT
1012 
1018 #define itkGetConstReferenceMacro(name, type) \
1019  virtual const type & Get##name() const { return this->m_##name; } \
1020  ITK_MACROEND_NOOP_STATEMENT
1021 
1027 #define itkSetEnumMacro(name, type) \
1028  virtual void Set##name(const type _arg) \
1029  { \
1030  itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1031  if (this->m_##name != _arg) \
1032  { \
1033  this->m_##name = _arg; \
1034  this->Modified(); \
1035  } \
1036  } \
1037  ITK_MACROEND_NOOP_STATEMENT
1038 
1044 #define itkGetEnumMacro(name, type) \
1045  virtual type Get##name() const { return this->m_##name; } \
1046  ITK_MACROEND_NOOP_STATEMENT
1047 
1052 #define itkSetStringMacro(name) \
1053  virtual void Set##name(const char * _arg) \
1054  { \
1055  if (_arg && (_arg == this->m_##name)) \
1056  { \
1057  return; \
1058  } \
1059  if (_arg) \
1060  { \
1061  this->m_##name = _arg; \
1062  } \
1063  else \
1064  { \
1065  this->m_##name = ""; \
1066  } \
1067  this->Modified(); \
1068  } \
1069  virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1070  ITK_MACROEND_NOOP_STATEMENT
1071 
1077 #define itkGetStringMacro(name) \
1078  virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1079  ITK_MACROEND_NOOP_STATEMENT
1080 
1081 // clang-format off
1085 #define itkSetClampMacro(name, type, min, max) \
1086  virtual void Set##name(type _arg) \
1087  { \
1088  const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1089  itkDebugMacro("setting " << #name " to " << _arg); \
1090  CLANG_PRAGMA_PUSH \
1091  CLANG_SUPPRESS_Wfloat_equal \
1092  if (this->m_##name != temp_extrema) \
1093  { \
1094  this->m_##name = temp_extrema; \
1095  this->Modified(); \
1096  } \
1097  CLANG_PRAGMA_POP \
1098  } \
1099  ITK_MACROEND_NOOP_STATEMENT
1100 // clang-format on
1103 // clang-format off
1107 #define itkSetObjectMacro(name, type) \
1108  virtual void Set##name(type * _arg) \
1109  { \
1110  itkDebugMacro("setting " << #name " to " << _arg); \
1111  if (this->m_##name != _arg) \
1112  { \
1113  this->m_##name = _arg; \
1114  this->Modified(); \
1115  } \
1116  } \
1117  ITK_MACROEND_NOOP_STATEMENT
1118 // clang-format on
1129 // NOTE: A class can use either itkGetModifiableObjectMacro
1130 // or itkGetObjectMacro, but not both.
1131 // A class can use either itkGetModifiableObjectMacro
1132 // or itkGetConstObjectMacro, but not both.
1133 // If the desired behavior is to only provide const
1134 // access to the itkObject ivar, then use itkGetConstObjectMacro,
1135 // else use itkGetModifiableObjectMacro for read/write access to
1136 // the ivar.
1137 // It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1138 // for backwards compatibility.
1139 // If the ITK_LEGACY_REMOVE=FALSE, then it is
1140 // permissible to use itkGetObjectMacro which
1141 // defines both signatures itk::GetXXX() and
1142 // itk::GetModifiableXXX()
1143 
1146 #define itkGetConstObjectMacro(name, type) \
1147  virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1148  ITK_MACROEND_NOOP_STATEMENT
1149 
1150 
1151 #if defined(ITK_FUTURE_LEGACY_REMOVE)
1152 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1153 // flag. For now, this very advanced feature is only available
1154 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1155 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1156 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1157 # define itkGetObjectMacro(name, type) \
1158  virtual type * Get##name() \
1159  { \
1160  purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1161  }
1162 
1163 # define itkGetModifiableObjectMacro(name, type) \
1164  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1165  itkGetConstObjectMacro(name, type)
1166 
1167 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1168 
1170 # define itkGetObjectMacro(name, type) \
1171  virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1172  ITK_MACROEND_NOOP_STATEMENT
1173 # define itkGetModifiableObjectMacro(name, type) \
1174  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1175  itkGetConstObjectMacro(name, type); \
1176  itkGetObjectMacro(name, type)
1177 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1178 
1180 // For backwards compatibility define ITK_EXPORT to nothing
1181 #define ITK_EXPORT
1182 
1183 
1186 #define itkGetConstReferenceObjectMacro(name, type) \
1187  virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1188  ITK_MACROEND_NOOP_STATEMENT
1189 
1193 #define itkSetConstObjectMacro(name, type) \
1194  virtual void Set##name(const type * _arg) \
1195  { \
1196  itkDebugMacro("setting " << #name " to " << _arg); \
1197  if (this->m_##name != _arg) \
1198  { \
1199  this->m_##name = _arg; \
1200  this->Modified(); \
1201  } \
1202  } \
1203  ITK_MACROEND_NOOP_STATEMENT
1204 
1208 #define itkBooleanMacro(name) \
1209  virtual void name##On() { this->Set##name(true); } \
1210  virtual void name##Off() { this->Set##name(false); }
1211 
1213 // clang-format off
1217 #define itkSetVectorMacro(name, type, count) \
1218  virtual void Set##name(type data[]) \
1219  { \
1220  unsigned int i; \
1221  for (i = 0; i < count; ++i) \
1222  { \
1223  CLANG_PRAGMA_PUSH \
1224  CLANG_SUPPRESS_Wfloat_equal \
1225  if (data[i] != this->m_##name[i]) \
1226  { \
1227  break; \
1228  } \
1229  CLANG_PRAGMA_POP \
1230  } \
1231  if (i < count) \
1232  { \
1233  this->Modified(); \
1234  for (i = 0; i < count; ++i) \
1235  { \
1236  this->m_##name[i] = data[i]; \
1237  } \
1238  } \
1239  } \
1240  ITK_MACROEND_NOOP_STATEMENT
1241 // clang-format on
1246 #define itkGetVectorMacro(name, type, count) \
1247  virtual type * Get##name() const { return this->m_##name; } \
1248  ITK_MACROEND_NOOP_STATEMENT
1249 
1254 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1255 
1261 #define itkGPUKernelMacro(kernel) \
1262  kernel \
1263  { \
1264  public: \
1265  ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1266  kernel() = delete; \
1267  ~kernel() = delete; \
1268  static const char * GetOpenCLSource(); \
1269  }
1270 
1272 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1273  static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); }
1274 
1275 // A useful macro in the PrintSelf method for printing member variables
1276 // which are pointers to object based on the LightObject class.
1277 #define itkPrintSelfObjectMacro(name) \
1278  if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1279  { \
1280  os << indent << #name << ": (null)" << std::endl; \
1281  } \
1282  else \
1283  { \
1284  os << indent << #name << ": " << std::endl; \
1285  this->m_##name->Print(os, indent.GetNextIndent()); \
1286  } \
1287  ITK_MACROEND_NOOP_STATEMENT
1288 
1289 
1291 #define itkSetDecoratedOutputMacro(name, type) \
1292  virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1293  { \
1294  itkDebugMacro("setting output " #name " to " << _arg); \
1295  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1296  { \
1297  this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1298  this->Modified(); \
1299  } \
1300  } \
1301  virtual void Set##name(const type & _arg) \
1302  { \
1303  using DecoratorType = SimpleDataObjectDecorator<type>; \
1304  itkDebugMacro("setting output " #name " to " << _arg); \
1305  DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1306  if (output) \
1307  { \
1308  if (output->Get() == _arg) \
1309  { \
1310  return; \
1311  } \
1312  else \
1313  { \
1314  output->Set(_arg); \
1315  } \
1316  } \
1317  else \
1318  { \
1319  auto newOutput = DecoratorType::New(); \
1320  newOutput->Set(_arg); \
1321  this->Set##name##Output(newOutput); \
1322  } \
1323  } \
1324  ITK_MACROEND_NOOP_STATEMENT
1325 
1328 #define itkGetDecoratedOutputMacro(name, type) \
1329  virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1330  { \
1331  itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1332  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1333  } \
1334  virtual const type & Get##name() const \
1335  { \
1336  itkDebugMacro("Getting output " #name); \
1337  using DecoratorType = SimpleDataObjectDecorator<type>; \
1338  const DecoratorType * output = \
1339  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1340  if (output == nullptr) \
1341  { \
1342  itkExceptionMacro("output" #name " is not set"); \
1343  } \
1344  return output->Get(); \
1345  } \
1346  ITK_MACROEND_NOOP_STATEMENT
1347 
1359 #if defined(ITKV4_COMPATIBILITY)
1360 # define ITK_ITERATOR_VIRTUAL virtual
1361 # define ITK_ITERATOR_OVERRIDE override
1362 # define ITK_ITERATOR_FINAL
1363 #elif !defined(ITK_LEGACY_REMOVE)
1364 # define ITK_ITERATOR_VIRTUAL virtual
1365 # define ITK_ITERATOR_OVERRIDE override
1366 # define ITK_ITERATOR_FINAL final
1367 #else
1368 # define ITK_ITERATOR_VIRTUAL
1369 # define ITK_ITERATOR_OVERRIDE
1370 # define ITK_ITERATOR_FINAL
1371 #endif
1372 
1373 #if defined(ITKV4_COMPATIBILITY)
1374 // A macro for methods which are const in ITKv5, but not in ITKv4
1375 # define ITKv5_CONST
1376 #else
1377 // A macro for methods which are const in ITKv5, but not in ITKv4
1378 # define ITKv5_CONST const
1379 #endif
1380 
1381 #define itkExceptionObject_h
1382 #include "itkExceptionObject.h"
1383 #undef itkExceptionObject_h
1384 
1392 template <typename TTarget, typename TSource>
1393 TTarget
1394 itkDynamicCastInDebugMode(TSource x)
1395 {
1396 #ifndef NDEBUG
1397  if (x == nullptr)
1398  {
1399  return nullptr;
1400  }
1401  TTarget rval = dynamic_cast<TTarget>(x);
1402  if (rval == nullptr)
1403  {
1404  itkGenericExceptionMacro("Failed dynamic cast to " << typeid(TTarget).name()
1405  << " object type = " << x->GetNameOfClass());
1406  }
1407  return rval;
1408 #else
1409  return static_cast<TTarget>(x);
1410 #endif
1411 }
1414 #ifdef ITK_LEGACY_REMOVE
1415 # if __cplusplus >= 202002L
1416 # define ITK_NODISCARD(message) [[nodiscard(message)]]
1417 # else
1418 # define ITK_NODISCARD(message) [[nodiscard]]
1419 # endif
1420 #else
1421 # define ITK_NODISCARD(message)
1422 #endif
1423 
1424 // Defines which used to be in itk_compiler_detection.h
1425 #define ITK_ALIGNAS(X) alignas(X)
1426 #define ITK_ALIGNOF(X) alignof(X)
1427 #define ITK_DEPRECATED [[deprecated]]
1428 #define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1429 #define ITK_CONSTEXPR constexpr
1430 #define ITK_DELETED_FUNCTION = delete
1431 #define ITK_EXTERN_TEMPLATE extern
1432 #define ITK_FINAL final
1433 #define ITK_NOEXCEPT noexcept
1434 #define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1435 #define ITK_NULLPTR nullptr
1436 #define ITK_OVERRIDE override
1437 #define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1438 #define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1439 #define ITK_THREAD_LOCAL thread_local
1440 
1441 #endif // end of itkMacro.h
itkExceptionObject.h
itkWin32Header.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24