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 // Use "ITK_FALLTHROUGH;" to annotate deliberate fall-through in switches,
269 // use it analogously to "break;". The trailing semi-colon is required.
270 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
271 # if (__GNUC__ >= 7)
272 # define ITK_FALLTHROUGH __attribute__((fallthrough))
273 # endif
274 #elif defined(__has_warning)
275 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
276 # define ITK_FALLTHROUGH [[clang::fallthrough]]
277 # endif
278 #endif
279 
280 #ifndef ITK_FALLTHROUGH
281 # define ITK_FALLTHROUGH ((void)0)
282 #endif
283 
304 #define itkNewMacro(x) \
305  itkSimpleNewMacro(x); \
306  itkCreateAnotherMacro(x); \
307  itkCloneMacro(x); \
308  ITK_MACROEND_NOOP_STATEMENT
309 
311 #define itkSimpleNewMacro(x) \
312  static Pointer New() \
313  { \
314  Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
315  if (smartPtr == nullptr) \
316  { \
317  smartPtr = new x(); \
318  } \
319  smartPtr->UnRegister(); \
320  return smartPtr; \
321  } \
322  ITK_MACROEND_NOOP_STATEMENT
323 
324 #define itkCreateAnotherMacro(x) \
325  ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
326  ITK_MACROEND_NOOP_STATEMENT
327 
328 #define itkCloneMacro(x) \
329  Pointer Clone() const \
330  { \
331  Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
332  return rval; \
333  } \
334  ITK_MACROEND_NOOP_STATEMENT
335 
339 #define itkFactoryOnlyNewMacro(x) \
340  itkSimpleFactoryOnlyNewMacro(x); \
341  itkCreateAnotherMacro(x); \
342  itkCloneMacro(x); \
343  ITK_MACROEND_NOOP_STATEMENT
344 
346 #define itkSimpleFactoryOnlyNewMacro(x) \
347  static auto New()->Pointer \
348  { \
349  Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
350  if (smartPtr == nullptr) \
351  { \
352  itkSpecializedMessageExceptionMacro(ExceptionObject, \
353  "Object factory failed to instantiate " << typeid(x).name()); \
354  } \
355  smartPtr->UnRegister(); \
356  return smartPtr; \
357  } \
358  ITK_MACROEND_NOOP_STATEMENT
359 
372 #define itkFactorylessNewMacro(x) \
373  static Pointer New() \
374  { \
375  x * rawPtr = new x(); \
376  Pointer smartPtr = rawPtr; \
377  rawPtr->UnRegister(); \
378  return smartPtr; \
379  } \
380  itkCreateAnotherMacro(x); \
381  ITK_MACROEND_NOOP_STATEMENT
382 
384 //
385 // A macro to disallow the copy constructor, copy assignment,
386 // move constructor, and move assignment functions.
387 // This should be used in the public: declarations for a class
388 //
389 // ITK's paradigm for smart pointer and pipeline consistency
390 // prohibits the use of copy/move construction and copy/move assignment
391 // functions.
392 //
393 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
394  TypeName(const TypeName &) = delete; \
395  TypeName & operator=(const TypeName &) = delete; \
396  TypeName(TypeName &&) = delete; \
397  TypeName & operator=(TypeName &&) = delete
398 
399 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
400 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
401 #else
402 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
403  static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
404 #endif
405 
406 
407 // When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
408 // the ability for operator!= to be rewritten automatically in terms of
409 // operator==, as introduced with C++20. This macro is experimental. It may be
410 // modified, renamed, or removed without backward compatibility support.
411 #if __cplusplus >= 202002L
412 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
413 #endif
414 
415 // Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
416 // is only for internal use within the implementation of ITK. It may be
417 // modified, renamed, or removed without backward compatibility support.
418 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
419 // With C++20, operator!= is automatically rewritten in terms of the
420 // corresponding operator==.
421 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
422 #else
423 // For C++14 and C++17, this macro defines an operator!= member function that
424 // just calls the corresponding operator== member function.
425 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
426  bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
427  ITK_MACROEND_NOOP_STATEMENT
428 #endif
429 
430 
431 // Internal macro (not part of the public ITK API), used to implement `GetNameOfClass()` member functions.
432 #define itkInternalGetNameOfClassImplementationMacro(thisClass) \
433  { \
434  static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
435  "The macro argument `" #thisClass \
436  "` appears incorrect! It should correspond with the name of this class!"); \
437  return #thisClass; \
438  } \
439  ITK_MACROEND_NOOP_STATEMENT
440 
441 
445 #define itkVirtualGetNameOfClassMacro(thisClass) \
446  virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
447 
448 #define itkOverrideGetNameOfClassMacro(thisClass) \
449  const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
450 
451 #ifdef ITK_FUTURE_LEGACY_REMOVE
452 # define itkTypeMacro(thisClass, superclass) \
453  static_assert(false, \
454  "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
455  "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
456 # define itkTypeMacroNoParent(thisClass) \
457  static_assert(false, \
458  "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
459  "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
460 #else
461 
465 # define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
466 # define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
467 #endif
468 
469 
470 namespace itk
471 {
478 extern ITKCommon_EXPORT void
479 OutputWindowDisplayText(const char *);
482 extern ITKCommon_EXPORT void
483 OutputWindowDisplayErrorText(const char *);
484 
485 extern ITKCommon_EXPORT void
486 OutputWindowDisplayWarningText(const char *);
487 
488 extern ITKCommon_EXPORT void
489 OutputWindowDisplayGenericOutputText(const char *);
490 
491 extern ITKCommon_EXPORT void
492 OutputWindowDisplayDebugText(const char *);
493 
494 } // end namespace itk
495 
496 // The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
501 #if defined(NDEBUG)
502 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
503 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
504 #else
505 # define itkDebugMacro(x) \
506  do \
507  { \
508  using namespace ::itk::print_helper; /* for ostream << std::vector<T> */ \
509  if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
510  { \
511  std::ostringstream itkmsg; \
512  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
513  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
514  ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
515  } \
516  } while (0)
517 
519 // The itkDebugStatement is to be used to protect code that is only
520 // used in the itkDebugMacro
521 # define itkDebugStatement(x) x
522 #endif
523 
527 #define itkWarningMacro(x) \
528  do \
529  { \
530  if (::itk::Object::GetGlobalWarningDisplay()) \
531  { \
532  std::ostringstream itkmsg; \
533  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << '\n' \
534  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
535  ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
536  } \
537  } while (0)
538 
540 #define itkWarningStatement(x) x
541 
542 #if defined(ITK_CPP_FUNCTION)
543 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
544 # define ITK_LOCATION __FUNCSIG__
545 # elif defined(__GNUC__)
546 # define ITK_LOCATION __PRETTY_FUNCTION__
547 # else
548 # define ITK_LOCATION __FUNCTION__
549 # endif
550 #else
551 # define ITK_LOCATION "unknown"
552 #endif
553 
554 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
555  namespace itk \
556  { \
557  class newexcp : public parentexcp \
558  { \
559  public: \
560  /* default message provides backward compatibility for a given exception type */ \
561  static constexpr const char * const default_exception_message = whatmessage; \
562  /* Inherit the constructors from its base class. */ \
563  using parentexcp::parentexcp; \
564  itkOverrideGetNameOfClassMacro(newexcp); \
565  }; \
566  } \
567  ITK_MACROEND_NOOP_STATEMENT
568 
569 
570 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
571  { \
572  std::ostringstream exceptionDescriptionOutputStringStream; \
573  exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
574  throw ::itk::ExceptionType( \
575  std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
576  } \
577  ITK_MACROEND_NOOP_STATEMENT
578 
579 #define itkSpecializedExceptionMacro(ExceptionType) \
580  itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
581 
585 #define itkExceptionMacro(x) \
586  itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
587 
588 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
589 
590 #define itkGenericOutputMacro(x) \
591  { \
592  if (::itk::Object::GetGlobalWarningDisplay()) \
593  { \
594  std::ostringstream itkmsg; \
595  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
596  ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
597  } \
598  } \
599  ITK_MACROEND_NOOP_STATEMENT
600 
601 //----------------------------------------------------------------------------
602 // Macros for simplifying the use of logging
603 //
604 #define itkLogMacro(x, y) \
605  { \
606  if (this->GetLogger()) \
607  { \
608  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
609  } \
610  } \
611  ITK_MACROEND_NOOP_STATEMENT
612 
613 #define itkLogMacroStatic(obj, x, y) \
614  { \
615  if (obj->GetLogger()) \
616  { \
617  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
618  } \
619  } \
620  ITK_MACROEND_NOOP_STATEMENT
621 
622 //----------------------------------------------------------------------------
623 // Setup legacy code policy.
624 //
625 // CMake options:
626 // - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
627 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
628 // of legacy code will not produce compiler warnings.
629 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
630 // of legacy code will produce compiler warnings
631 //
632 // ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
633 //
634 // Source files that test the legacy code may define ITK_LEGACY_TEST
635 // like this:
636 //
637 // #define ITK_LEGACY_TEST
638 // #include "itkClassWithDeprecatedMethod.h"
639 //
640 // in order to silence the warnings for calling deprecated methods.
641 // No other source files in ITK should call the methods since they are
642 // provided only for compatibility with older user code.
643 
644 // Define itkLegacyMacro to mark legacy methods where they are
645 // declared in their class. Example usage:
646 //
647 // // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
648 // itkLegacyMacro(void MyMethod());
649 //
650 // See below for what to do for the method definition.
651 #if defined(ITK_LEGACY_REMOVE)
652 # define itkLegacyMacro(method) /* no ';' */
653 #else
654 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
655 // Provide legacy methods with no warnings.
656 # define itkLegacyMacro(method) method
657 # else
658 // Request compile-time warnings for uses of deprecated methods.
659 # define itkLegacyMacro(method) [[deprecated]] method
660 # endif
661 #endif
662 
663 // Macros to create runtime deprecation warning messages in function
664 // bodies. Example usage:
665 //
666 // #if !defined( ITK_LEGACY_REMOVE )
667 // void itkMyClass::MyOldMethod()
668 // {
669 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
670 // }
671 //
672 // void itkMyClass::MyMethod()
673 // {
674 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
675 // itkMyClass::MyOtherMethod);
676 // }
677 // #endif
678 //
679 // NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
680 // itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
681 // are purposefully not defined when ITK_LEGACY_REMOVE is on,
682 // because these macros are only relevant inside code segments
683 // that are conditionally compiled only when ITK_LEGACY_REMOVE
684 // is off.
685 #if defined(ITK_LEGACY_SILENT)
686 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
687 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
688 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
689 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
690 #else
691 # define itkLegacyBodyMacro(method, version) \
692  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
693 # define itkLegacyReplaceBodyMacro(method, version, replace) \
694  itkWarningMacro(#method " was deprecated for ITK " #version \
695  " and will be removed in a future version. Use " #replace " instead.")
696 # define itkGenericLegacyBodyMacro(method, version) \
697  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
698 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
699  itkGenericOutputMacro(#method " was deprecated for ITK " #version \
700  " and will be removed in a future version. Use " #replace " instead.")
701 #endif
702 
703 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
704 // the cache lines. By aligning multi-threaded structures with the
705 // cache lines, false shared can be reduced, and performance
706 // increased.
707 #define ITK_CACHE_LINE_ALIGNMENT 64
708 
709 //
710 // itkPadStruct will add padding to a structure to ensure a minimum size
711 // for ensuring that adjacent structures do not share CACHE lines.
712 // Each struct will take up some multiple of cacheline sizes.
713 // This is particularly useful for arrays of thread private variables.
714 //
715 #define itkPadStruct(mincachesize, oldtype, newtype) \
716  struct newtype : public oldtype \
717  { \
718  char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
719  };
720 
721 //
722 // itkAlignedTypedef is a macro which creates a new type to make a
723 // data structure aligned.
724 //
725 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
726 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
727 #elif defined(_MSC_VER)
728 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
729 #else
730 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
731 #endif
732 
733 #if defined(ITK_FUTURE_LEGACY_REMOVE)
734 //=============================================================================
735 /*
736 NOTE: DEPRECATED - This macro is not longer needed to support modern
737 compilers.
738 
739  Define a common way of declaring a templated function as a friend inside a class.
740  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
741 
742  The following templated function
743 
744  template <T>
745  T add(const T & a, const T & b);
746 
747  is declared as friend with
748 
749  class A
750  {
751  public:
752  friend Self add<>( const Self & a, const Self & b );
753  }
754 
755 */
756 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
757 #else // LEGACY_REMOVE
758 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
759 #endif
760 
761 //--------------------------------------------------------------------------------
762 // Helper macros for Template Meta-Programming techniques of for-loops
763 // unrolling
764 //--------------------------------------------------------------------------------
765 
766 //--------------------------------------------------------------------------------
767 // Macro that generates an unrolled for loop for assigning elements of one array
768 // to elements of another array The array are assumed to be of same length
769 // (dimension), and this is also assumed to be the value of NumberOfIterations.
770 // No verification of size is performed. Casting is performed as part of the
771 // assignment, by using the DestinationElementType as the casting type.
772 // Source and destination array types must have defined operator[] in their
773 // API.
774 #define itkForLoopAssignmentMacro( \
775  DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
776  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
777  { \
778  DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
779  }
780 
781 //--------------------------------------------------------------------------------
782 // Macro that generates an unrolled for loop for rounding and assigning
783 // elements of one array to elements of another array The array are assumed to
784 // be of same length (dimension), and this is also assumed to be the value of
785 // NumberOfIterations. No verification of size is performed. Casting is
786 // performed as part of the assignment, by using the DestinationElementType as
787 // the casting type.
788 // Source and destination array types must have defined operator[] in their
789 // API.
790 #define itkForLoopRoundingAndAssignmentMacro( \
791  DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
792  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
793  { \
794  DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
795  }
796 
797 // end of Template Meta Programming helper macros
798 
799 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
800 
801 # ifdef __GLIBC__
802 # define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
803 # else
804 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
805 # endif
806 
807 #else
808 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
809 #endif
810 
811 #define itkAssertOrThrowMacro(test, message) \
812  if (!(test)) \
813  { \
814  std::ostringstream msgstr; \
815  msgstr << message; \
816  itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
817  } \
818  ITK_MACROEND_NOOP_STATEMENT
819 
820 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
821 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
822 #else
823 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
824 #endif
825 
826 
827 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
828 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
829 // !! The ITK Get/Set Macros for various types !!
830 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
831 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
832 
833 #ifdef ITK_FUTURE_LEGACY_REMOVE
834 # define itkStaticConstMacro(name, type, value) \
835  "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
836 # define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
837 #else
838 
852 # define itkStaticConstMacro(name, type, value) static constexpr type name = value
853 
854 # define itkGetStaticConstMacro(name) (Self::name)
855 #endif
856 
858 #define itkSetInputMacro(name, type) \
859  virtual void Set##name(const type * _arg) \
860  { \
861  itkDebugMacro("setting input " #name " to " << _arg); \
862  if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
863  { \
864  this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
865  this->Modified(); \
866  } \
867  } \
868  ITK_MACROEND_NOOP_STATEMENT
869 
872 #define itkGetInputMacro(name, type) \
873  virtual const type * Get##name() const \
874  { \
875  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
876  return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
877  } \
878  ITK_MACROEND_NOOP_STATEMENT
879 
881 // clang-format off
883 #define itkSetDecoratedInputMacro(name, type) \
884  virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
885  { \
886  itkDebugMacro("setting input " #name " to " << _arg); \
887  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
888  { \
889  this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
890  this->Modified(); \
891  } \
892  } \
893  virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
894  virtual void Set##name(const type & _arg) \
895  { \
896  using DecoratorType = SimpleDataObjectDecorator<type>; \
897  itkDebugMacro("setting input " #name " to " << _arg); \
898  const DecoratorType * oldInput = \
899  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
900  CLANG_PRAGMA_PUSH \
901  CLANG_SUPPRESS_Wfloat_equal \
902  if (oldInput && oldInput->Get() == _arg) \
903  { \
904  return; \
905  } \
906  CLANG_PRAGMA_POP \
907  auto newInput = DecoratorType::New(); \
908  newInput->Set(_arg); \
909  this->Set##name##Input(newInput); \
910  } \
911  ITK_MACROEND_NOOP_STATEMENT
912 // clang-format on
916 #define itkGetDecoratedInputMacro(name, type) \
917  virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
918  { \
919  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
920  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
921  } \
922  virtual const type & Get##name() const \
923  { \
924  itkDebugMacro("Getting input " #name); \
925  using DecoratorType = SimpleDataObjectDecorator<type>; \
926  const DecoratorType * input = \
927  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
928  if (input == nullptr) \
929  { \
930  itkExceptionMacro("input" #name " is not set"); \
931  } \
932  return input->Get(); \
933  } \
934  ITK_MACROEND_NOOP_STATEMENT
935 
939 #define itkSetGetDecoratedInputMacro(name, type) \
940  itkSetDecoratedInputMacro(name, type); \
941  itkGetDecoratedInputMacro(name, type)
942 
947 #define itkSetDecoratedObjectInputMacro(name, type) \
948  virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
949  { \
950  itkDebugMacro("setting input " #name " to " << _arg); \
951  if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
952  { \
953  this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
954  this->Modified(); \
955  } \
956  } \
957  virtual void Set##name(const type * _arg) \
958  { \
959  using DecoratorType = DataObjectDecorator<type>; \
960  itkDebugMacro("setting input " #name " to " << _arg); \
961  const DecoratorType * oldInput = \
962  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
963  if (oldInput && oldInput->Get() == _arg) \
964  { \
965  return; \
966  } \
967  auto newInput = DecoratorType::New(); \
968  newInput->Set(_arg); \
969  this->Set##name##Input(newInput); \
970  } \
971  ITK_MACROEND_NOOP_STATEMENT
972 
978 #define itkGetDecoratedObjectInputMacro(name, type) \
979  virtual const DataObjectDecorator<type> * Get##name##Input() const \
980  { \
981  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
982  return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
983  } \
984  virtual const type * Get##name() const \
985  { \
986  itkDebugMacro("Getting input " #name); \
987  using DecoratorType = DataObjectDecorator<type>; \
988  const DecoratorType * input = \
989  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
990  if (input == nullptr) \
991  { \
992  return nullptr; \
993  } \
994  return input->Get(); \
995  } \
996  ITK_MACROEND_NOOP_STATEMENT
997 
1001 #define itkSetGetDecoratedObjectInputMacro(name, type) \
1002  itkSetDecoratedObjectInputMacro(name, type); \
1003  itkGetDecoratedObjectInputMacro(name, type)
1004 
1006 // clang-format off
1007 #define itkSetMacro(name, type) \
1008  virtual void Set##name(type _arg) \
1009  { \
1010  itkDebugMacro("setting " #name " to " << _arg); \
1011  CLANG_PRAGMA_PUSH \
1012  CLANG_SUPPRESS_Wfloat_equal \
1013  if (this->m_##name != _arg) \
1014  { \
1015  this->m_##name = std::move(_arg); \
1016  this->Modified(); \
1017  } \
1018  CLANG_PRAGMA_POP \
1019  } \
1020  ITK_MACROEND_NOOP_STATEMENT
1021 // clang-format on
1022 
1024 #define itkGetMacro(name, type) \
1025  virtual type Get##name() { return this->m_##name; } \
1026  ITK_MACROEND_NOOP_STATEMENT
1027 
1032 #define itkGetConstMacro(name, type) \
1033  virtual type Get##name() const { return this->m_##name; } \
1034  ITK_MACROEND_NOOP_STATEMENT
1035 
1041 #define itkGetConstReferenceMacro(name, type) \
1042  virtual const type & Get##name() const { return this->m_##name; } \
1043  ITK_MACROEND_NOOP_STATEMENT
1044 
1050 #define itkSetEnumMacro(name, type) \
1051  virtual void Set##name(const type _arg) \
1052  { \
1053  itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1054  if (this->m_##name != _arg) \
1055  { \
1056  this->m_##name = _arg; \
1057  this->Modified(); \
1058  } \
1059  } \
1060  ITK_MACROEND_NOOP_STATEMENT
1061 
1067 #define itkGetEnumMacro(name, type) \
1068  virtual type Get##name() const { return this->m_##name; } \
1069  ITK_MACROEND_NOOP_STATEMENT
1070 
1075 #define itkSetStringMacro(name) \
1076  virtual void Set##name(const char * _arg) \
1077  { \
1078  if (_arg && (_arg == this->m_##name)) \
1079  { \
1080  return; \
1081  } \
1082  if (_arg) \
1083  { \
1084  this->m_##name = _arg; \
1085  } \
1086  else \
1087  { \
1088  this->m_##name = ""; \
1089  } \
1090  this->Modified(); \
1091  } \
1092  virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1093  ITK_MACROEND_NOOP_STATEMENT
1094 
1100 #define itkGetStringMacro(name) \
1101  virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1102  ITK_MACROEND_NOOP_STATEMENT
1103 
1104 // clang-format off
1108 #define itkSetClampMacro(name, type, min, max) \
1109  virtual void Set##name(type _arg) \
1110  { \
1111  const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1112  itkDebugMacro("setting " << #name " to " << _arg); \
1113  CLANG_PRAGMA_PUSH \
1114  CLANG_SUPPRESS_Wfloat_equal \
1115  if (this->m_##name != temp_extrema) \
1116  { \
1117  this->m_##name = temp_extrema; \
1118  this->Modified(); \
1119  } \
1120  CLANG_PRAGMA_POP \
1121  } \
1122  ITK_MACROEND_NOOP_STATEMENT
1123 // clang-format on
1126 // clang-format off
1130 #define itkSetObjectMacro(name, type) \
1131  virtual void Set##name(type * _arg) \
1132  { \
1133  itkDebugMacro("setting " << #name " to " << _arg); \
1134  if (this->m_##name != _arg) \
1135  { \
1136  this->m_##name = _arg; \
1137  this->Modified(); \
1138  } \
1139  } \
1140  ITK_MACROEND_NOOP_STATEMENT
1141 // clang-format on
1152 // NOTE: A class can use either itkGetModifiableObjectMacro
1153 // or itkGetObjectMacro, but not both.
1154 // A class can use either itkGetModifiableObjectMacro
1155 // or itkGetConstObjectMacro, but not both.
1156 // If the desired behavior is to only provide const
1157 // access to the itkObject ivar, then use itkGetConstObjectMacro,
1158 // else use itkGetModifiableObjectMacro for read/write access to
1159 // the ivar.
1160 // It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1161 // for backwards compatibility.
1162 // If the ITK_LEGACY_REMOVE=FALSE, then it is
1163 // permissible to use itkGetObjectMacro which
1164 // defines both signatures itk::GetXXX() and
1165 // itk::GetModifiableXXX()
1166 
1169 #define itkGetConstObjectMacro(name, type) \
1170  virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1171  ITK_MACROEND_NOOP_STATEMENT
1172 
1173 
1174 #if defined(ITK_FUTURE_LEGACY_REMOVE)
1175 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1176 // flag. For now, this very advanced feature is only available
1177 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1178 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1179 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1180 # define itkGetObjectMacro(name, type) \
1181  virtual type * Get##name() \
1182  { \
1183  purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1184  }
1185 
1186 # define itkGetModifiableObjectMacro(name, type) \
1187  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1188  itkGetConstObjectMacro(name, type)
1189 
1190 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1191 
1193 # define itkGetObjectMacro(name, type) \
1194  virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1195  ITK_MACROEND_NOOP_STATEMENT
1196 # define itkGetModifiableObjectMacro(name, type) \
1197  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1198  itkGetConstObjectMacro(name, type); \
1199  itkGetObjectMacro(name, type)
1200 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1201 
1203 // For backwards compatibility define ITK_EXPORT to nothing
1204 #define ITK_EXPORT
1205 
1206 
1209 #define itkGetConstReferenceObjectMacro(name, type) \
1210  virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1211  ITK_MACROEND_NOOP_STATEMENT
1212 
1216 #define itkSetConstObjectMacro(name, type) \
1217  virtual void Set##name(const type * _arg) \
1218  { \
1219  itkDebugMacro("setting " << #name " to " << _arg); \
1220  if (this->m_##name != _arg) \
1221  { \
1222  this->m_##name = _arg; \
1223  this->Modified(); \
1224  } \
1225  } \
1226  ITK_MACROEND_NOOP_STATEMENT
1227 
1231 #define itkBooleanMacro(name) \
1232  virtual void name##On() { this->Set##name(true); } \
1233  virtual void name##Off() { this->Set##name(false); }
1234 
1236 // clang-format off
1240 #define itkSetVectorMacro(name, type, count) \
1241  virtual void Set##name(type data[]) \
1242  { \
1243  unsigned int i; \
1244  for (i = 0; i < count; ++i) \
1245  { \
1246  CLANG_PRAGMA_PUSH \
1247  CLANG_SUPPRESS_Wfloat_equal \
1248  if (data[i] != this->m_##name[i]) \
1249  { \
1250  break; \
1251  } \
1252  CLANG_PRAGMA_POP \
1253  } \
1254  if (i < count) \
1255  { \
1256  this->Modified(); \
1257  for (i = 0; i < count; ++i) \
1258  { \
1259  this->m_##name[i] = data[i]; \
1260  } \
1261  } \
1262  } \
1263  ITK_MACROEND_NOOP_STATEMENT
1264 // clang-format on
1269 #define itkGetVectorMacro(name, type, count) \
1270  virtual type * Get##name() const { return this->m_##name; } \
1271  ITK_MACROEND_NOOP_STATEMENT
1272 
1277 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1278 
1284 #define itkGPUKernelMacro(kernel) \
1285  kernel \
1286  { \
1287  public: \
1288  ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1289  kernel() = delete; \
1290  ~kernel() = delete; \
1291  static const char * GetOpenCLSource(); \
1292  }
1293 
1295 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1296  static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); }
1297 
1298 // A useful macro in the PrintSelf method for printing member variables
1299 // which are pointers to object based on the LightObject class.
1300 #define itkPrintSelfObjectMacro(name) \
1301  if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1302  { \
1303  os << indent << #name << ": (null)" << std::endl; \
1304  } \
1305  else \
1306  { \
1307  os << indent << #name << ": " << std::endl; \
1308  this->m_##name->Print(os, indent.GetNextIndent()); \
1309  } \
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 
1382 #if defined(ITKV4_COMPATIBILITY)
1383 # define ITK_ITERATOR_VIRTUAL virtual
1384 # define ITK_ITERATOR_OVERRIDE override
1385 # define ITK_ITERATOR_FINAL
1386 #elif !defined(ITK_LEGACY_REMOVE)
1387 # define ITK_ITERATOR_VIRTUAL virtual
1388 # define ITK_ITERATOR_OVERRIDE override
1389 # define ITK_ITERATOR_FINAL final
1390 #else
1391 # define ITK_ITERATOR_VIRTUAL
1392 # define ITK_ITERATOR_OVERRIDE
1393 # define ITK_ITERATOR_FINAL
1394 #endif
1395 
1396 #if defined(ITKV4_COMPATIBILITY)
1397 // A macro for methods which are const in ITKv5, but not in ITKv4
1398 # define ITKv5_CONST
1399 #else
1400 // A macro for methods which are const in ITKv5, but not in ITKv4
1401 # define ITKv5_CONST const
1402 #endif
1403 
1404 #define itkExceptionObject_h
1405 #include "itkExceptionObject.h"
1406 #undef itkExceptionObject_h
1407 
1415 template <typename TTarget, typename TSource>
1416 TTarget
1417 itkDynamicCastInDebugMode(TSource x)
1418 {
1419 #ifndef NDEBUG
1420  if (x == nullptr)
1421  {
1422  return nullptr;
1423  }
1424  TTarget rval = dynamic_cast<TTarget>(x);
1425  if (rval == nullptr)
1426  {
1427  itkGenericExceptionMacro("Failed dynamic cast to " << typeid(TTarget).name()
1428  << " object type = " << x->GetNameOfClass());
1429  }
1430  return rval;
1431 #else
1432  return static_cast<TTarget>(x);
1433 #endif
1434 }
1437 #ifdef ITK_LEGACY_REMOVE
1438 # if __cplusplus >= 202002L
1439 # define ITK_NODISCARD(message) [[nodiscard(message)]]
1440 # else
1441 # define ITK_NODISCARD(message) [[nodiscard]]
1442 # endif
1443 #else
1444 # define ITK_NODISCARD(message)
1445 #endif
1446 
1447 // Defines which used to be in itk_compiler_detection.h
1448 #define ITK_ALIGNAS(X) alignas(X)
1449 #define ITK_ALIGNOF(X) alignof(X)
1450 #define ITK_DEPRECATED [[deprecated]]
1451 #define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1452 #define ITK_CONSTEXPR constexpr
1453 #define ITK_DELETED_FUNCTION = delete
1454 #define ITK_EXTERN_TEMPLATE extern
1455 #define ITK_FINAL final
1456 #define ITK_NOEXCEPT noexcept
1457 #define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1458 #define ITK_NULLPTR nullptr
1459 #define ITK_OVERRIDE override
1460 #define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1461 #define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1462 #define ITK_THREAD_LOCAL thread_local
1463 
1464 #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