ITK  5.3.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.0 and greater
155  * MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015 version 14.0)
156  * MSVC++ 14.1 _MSC_VER == 1910 (Visual Studio 2017 version 15.0)
157  * MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3)
158  * MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5)
159  * MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6)
160  * MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7)
161  * MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8)
162  * MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9)
163  * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
164  */
165 #if defined(_MSC_VER) && (_MSC_VER < 1910)
166 # error "Visual Studio < 2017 is not supported under ITKv5.3"
167 #endif
168 #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
169 # error "SUNPro C++ < 5.14.0 is not supported under ITKv5 and above"
170 #endif
171 #if defined(__CYGWIN__)
172 # error "The Cygwin compiler is not supported in ITKv4 and above"
173 #endif
174 #if defined(__BORLANDC__)
175 # error "The Borland C compiler is not supported in ITKv4 and above"
176 #endif
177 #if defined(__MWERKS__)
178 # error "The MetroWerks compiler is not supported in ITKv4 and above"
179 #endif
180 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && \
181  ((__GNUC__ < 5) || ((__GNUC__ == 5) && (__GNUC_MINOR__ < 1)))
182 # error "GCC < 5.1 is not supported under ITKv5.3"
183 #endif
184 #if defined(__sgi)
185 // This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
186 // TODO: At some future point, it may be necessary to
187 // define a minimum __sgi version that will work.
188 # error "The SGI compiler is not supported under ITKv4 and above"
189 #endif
190 #if defined(__APPLE__)
191 # if defined(__clang__) && (__cplusplus < 201402L)
192 # error "Apple LLVM < 5.1 (clang < 3.4) or compiling with a standard less than C++14 is not supported under ITKv5.3"
193 # endif
194 #elif defined(__clang__) && ((__clang_major__ < 3) || ((__clang_major__ == 3) && (__clang_minor__ < 4)))
195 # error "Clang < 3.4 is not supported under ITKv5.3"
196 #endif
197 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1700)
198 # error "Intel C++ < 17.0 is not supported under ITKv5.3"
199 #endif
200 
201 // Setup symbol exports
202 #if defined(_WIN32) || defined(WIN32)
203 # define ITK_ABI_IMPORT __declspec(dllimport)
204 # define ITK_ABI_EXPORT __declspec(dllexport)
205 # define ITK_ABI_HIDDEN
206 #else
207 # ifdef __GNUC__
208 # define ITK_ABI_IMPORT __attribute__((visibility("default")))
209 # define ITK_ABI_EXPORT __attribute__((visibility("default")))
210 # define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
211 # else
212 # define ITK_ABI_IMPORT
213 # define ITK_ABI_EXPORT
214 # define ITK_ABI_HIDDEN
215 # endif
216 #endif
217 
218 // Setup symbol exports
219 #ifndef ITK_TEMPLATE_EXPORT
220 # ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
221 # define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
222 # else
223 # define ITK_TEMPLATE_EXPORT
224 # endif
225 #endif
226 
227 // Setup symbol exports
228 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
229 # define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
230 #else
231 # define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
232 #endif
233 
234 #ifndef ITK_FORWARD_EXPORT
235 // If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
236 # if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
237  defined(USE_COMPILER_HIDDEN_VISIBILITY)
238 # define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
239 # else
240 # define ITK_FORWARD_EXPORT
241 # endif
242 #endif
243 
244 
245 //-*-*-*
246 // The following deprecations should be removed in ITKV6 and later
247 // NOTE DEPRECATED should be ITK_NOEXCEPT
248 #define ITK_NOEXCEPT_OR_THROW error "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT"
249 // NOTE DEPRECATED! should be ITK_COMPILER_CXX_STATIC_ASSERT
250 #if !defined(ITK_LEGACY_REMOVE)
251 # define ITK_DELETE_FUNCTION = delete
252 #else
253 # define ITK_DELETE_FUNCTION error "Replace ITK_DELETE_FUNCTION with = delete"
254 #endif
255 //-*-*-*
256 
257 // DEPRECATED: These macros are left here for compatibility with remote modules.
258 // Once they have been removed from all known remote modules, this code should
259 // be removed.
260 #if defined(ITK_FUTURE_LEGACY_REMOVE)
261 # define ITK_CONSTEXPR_FUNC "Replace ITK_CONSTEXPR_FUNC with constexpr"
262 # define ITK_CONSTEXPR_VAR "Replace ITK_CONSTEXPR_VAR with constexpr"
263 
264 # define itkExposeEnumValue(name) static_cast<int>(name)
265 // Future remove# define itkExposeEnumValue(name) "Replace type of " # name " with proper enumeration instead of
266 // integer."
267 #else
268 # define ITK_CONSTEXPR_FUNC constexpr
269 # define ITK_CONSTEXPR_VAR constexpr
270 
272 # define itkExposeEnumValue(name) static_cast<int>(name)
273 #endif
274 
275 // Use "ITK_FALLTHROUGH;" to annotate deliberate fall-through in switches,
276 // use it analogously to "break;". The trailing semi-colon is required.
277 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
278 # if (__GNUC__ >= 7)
279 # define ITK_FALLTHROUGH __attribute__((fallthrough))
280 # endif
281 #elif defined(__has_warning)
282 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
283 # define ITK_FALLTHROUGH [[clang::fallthrough]]
284 # endif
285 #endif
286 
287 #ifndef ITK_FALLTHROUGH
288 # define ITK_FALLTHROUGH ((void)0)
289 #endif
290 
311 #define itkNewMacro(x) \
312  itkSimpleNewMacro(x); \
313  itkCreateAnotherMacro(x); \
314  itkCloneMacro(x); \
315  ITK_MACROEND_NOOP_STATEMENT
316 
318 #define itkSimpleNewMacro(x) \
319  static Pointer New() \
320  { \
321  Pointer smartPtr = itk::ObjectFactory<x>::Create(); \
322  if (smartPtr == nullptr) \
323  { \
324  smartPtr = new x; \
325  } \
326  smartPtr->UnRegister(); \
327  return smartPtr; \
328  } \
329  ITK_MACROEND_NOOP_STATEMENT
330 
331 #define itkCreateAnotherMacro(x) \
332  itk::LightObject::Pointer CreateAnother() const override \
333  { \
334  itk::LightObject::Pointer smartPtr; \
335  smartPtr = x::New().GetPointer(); \
336  return smartPtr; \
337  } \
338  ITK_MACROEND_NOOP_STATEMENT
339 
340 #define itkCloneMacro(x) \
341  Pointer Clone() const \
342  { \
343  Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
344  return rval; \
345  } \
346  ITK_MACROEND_NOOP_STATEMENT
347 
351 #define itkFactoryOnlyNewMacro(x) \
352  itkSimpleFactoryOnlyNewMacro(x); \
353  itkCreateAnotherMacro(x); \
354  itkCloneMacro(x); \
355  ITK_MACROEND_NOOP_STATEMENT
356 
358 #define itkSimpleFactoryOnlyNewMacro(x) \
359  static auto New()->Pointer \
360  { \
361  Pointer smartPtr = itk::ObjectFactory<x>::Create(); \
362  if (smartPtr == nullptr) \
363  { \
364  itkSpecializedMessageExceptionMacro(ExceptionObject, \
365  "Object factory failed to instantiate " << typeid(x).name()); \
366  } \
367  smartPtr->UnRegister(); \
368  return smartPtr; \
369  } \
370  ITK_MACROEND_NOOP_STATEMENT
371 
384 #define itkFactorylessNewMacro(x) \
385  static Pointer New() \
386  { \
387  Pointer smartPtr; \
388  x * rawPtr = new x; \
389  smartPtr = rawPtr; \
390  rawPtr->UnRegister(); \
391  return smartPtr; \
392  } \
393  itk::LightObject::Pointer CreateAnother() const override \
394  { \
395  itk::LightObject::Pointer smartPtr; \
396  smartPtr = x::New().GetPointer(); \
397  return smartPtr; \
398  } \
399  ITK_MACROEND_NOOP_STATEMENT
400 
402 //
403 // A macro to disallow the copy constructor, copy assignment,
404 // move constructor, and move assignment functions.
405 // This should be used in the public: declarations for a class
406 //
407 // ITK's paradigm for smart pointer and pipeline consistency
408 // prohibits the use of copy/move construction and copy/move assignment
409 // functions.
410 //
411 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
412  TypeName(const TypeName &) = delete; \
413  TypeName & operator=(const TypeName &) = delete; \
414  TypeName(TypeName &&) = delete; \
415  TypeName & operator=(TypeName &&) = delete
416 
417 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
418 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
419 #else
420 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
421  static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
422 #endif
423 
424 
425 // When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
426 // the ability for operator!= to be rewritten automatically in terms of
427 // operator==, as introduced with C++20. This macro is experimental. It may be
428 // modified, renamed, or removed without backward compatibility support.
429 #if __cplusplus >= 202002L
430 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
431 #endif
432 
433 // Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
434 // is only for internal use within the implementation of ITK. It may be
435 // modified, renamed, or removed without backward compatibility support.
436 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
437 // With C++20, operator!= is automatically rewritten in terms of the
438 // corresponding operator==.
439 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
440 #else
441 // For C++14 and C++17, this macro defines an operator!= member function that
442 // just calls the corresponding operator== member function.
443 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
444  bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
445  ITK_MACROEND_NOOP_STATEMENT
446 #endif
447 
450 #define itkTypeMacro(thisClass, superclass) \
451  const char * GetNameOfClass() const override { return #thisClass; } \
452  ITK_MACROEND_NOOP_STATEMENT
453 
454 #define itkTypeMacroNoParent(thisClass) \
455  virtual const char * GetNameOfClass() const { return #thisClass; } \
456  ITK_MACROEND_NOOP_STATEMENT
457 
458 namespace itk
459 {
466 extern ITKCommon_EXPORT void
467 OutputWindowDisplayText(const char *);
470 extern ITKCommon_EXPORT void
471 OutputWindowDisplayErrorText(const char *);
472 
473 extern ITKCommon_EXPORT void
474 OutputWindowDisplayWarningText(const char *);
475 
476 extern ITKCommon_EXPORT void
477 OutputWindowDisplayGenericOutputText(const char *);
478 
479 extern ITKCommon_EXPORT void
480 OutputWindowDisplayDebugText(const char *);
481 } // end namespace itk
482 
483 // The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
488 #if defined(NDEBUG)
489 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
490 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
491 #else
492 # define itkDebugMacro(x) \
493  do \
494  { \
495  if (this->GetDebug() && itk::Object::GetGlobalWarningDisplay()) \
496  { \
497  std::ostringstream itkmsg; \
498  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
499  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
500  itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
501  } \
502  } while (0)
503 
505 // The itkDebugStatement is to be used to protect code that is only
506 // used in the itkDebugMacro
507 # define itkDebugStatement(x) x
508 #endif
509 
513 #define itkWarningMacro(x) \
514  do \
515  { \
516  if (itk::Object::GetGlobalWarningDisplay()) \
517  { \
518  std::ostringstream itkmsg; \
519  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
520  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
521  itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
522  } \
523  } while (0)
524 
526 #define itkWarningStatement(x) x
527 
528 #if defined(ITK_CPP_FUNCTION)
529 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
530 # define ITK_LOCATION __FUNCSIG__
531 # elif defined(__GNUC__)
532 # define ITK_LOCATION __PRETTY_FUNCTION__
533 # else
534 # define ITK_LOCATION __FUNCTION__
535 # endif
536 #else
537 # define ITK_LOCATION "unknown"
538 #endif
539 
540 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
541  namespace itk \
542  { \
543  class newexcp : public parentexcp \
544  { \
545  public: \
546  /* default message provides backward compatibility for a given exception type */ \
547  static constexpr const char * const default_exception_message = whatmessage; \
548  /* Inherit the constructors from its base class. */ \
549  using parentexcp::parentexcp; \
550  itkTypeMacro(newexcp, parentexcp); \
551  }; \
552  } \
553  ITK_MACROEND_NOOP_STATEMENT
554 
555 
556 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
557  { \
558  std::ostringstream exceptionDescriptionOutputStringStream; \
559  exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
560  throw itk::ExceptionType( \
561  std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
562  } \
563  ITK_MACROEND_NOOP_STATEMENT
564 
565 #define itkSpecializedExceptionMacro(ExceptionType) \
566  itkSpecializedMessageExceptionMacro(ExceptionType, << itk::ExceptionType::default_exception_message)
567 
571 #define itkExceptionMacro(x) \
572  itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << "(" << this << "): " x)
573 
574 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
575 
576 #define itkGenericOutputMacro(x) \
577  { \
578  if (itk::Object::GetGlobalWarningDisplay()) \
579  { \
580  std::ostringstream itkmsg; \
581  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
582  itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
583  } \
584  } \
585  ITK_MACROEND_NOOP_STATEMENT
586 
587 //----------------------------------------------------------------------------
588 // Macros for simplifying the use of logging
589 //
590 #define itkLogMacro(x, y) \
591  { \
592  if (this->GetLogger()) \
593  { \
594  this->GetLogger()->Write(itk::LoggerBase::x, y); \
595  } \
596  } \
597  ITK_MACROEND_NOOP_STATEMENT
598 
599 #define itkLogMacroStatic(obj, x, y) \
600  { \
601  if (obj->GetLogger()) \
602  { \
603  obj->GetLogger()->Write(itk::LoggerBase::x, y); \
604  } \
605  } \
606  ITK_MACROEND_NOOP_STATEMENT
607 
608 //----------------------------------------------------------------------------
609 // Setup legacy code policy.
610 //
611 // CMake options:
612 // - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
613 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
614 // of legacy code will not produce compiler warnings.
615 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
616 // of legacy code will produce compiler warnings
617 //
618 // ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
619 //
620 // Source files that test the legacy code may define ITK_LEGACY_TEST
621 // like this:
622 //
623 // #define ITK_LEGACY_TEST
624 // #include "itkClassWithDeprecatedMethod.h"
625 //
626 // in order to silence the warnings for calling deprecated methods.
627 // No other source files in ITK should call the methods since they are
628 // provided only for compatibility with older user code.
629 
630 // Define itkLegacyMacro to mark legacy methods where they are
631 // declared in their class. Example usage:
632 //
633 // // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
634 // itkLegacyMacro(void MyMethod());
635 //
636 // See below for what to do for the method definition.
637 #if defined(ITK_LEGACY_REMOVE)
638 # define itkLegacyMacro(method) /* no ';' */
639 #else
640 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
641 // Provide legacy methods with no warnings.
642 # define itkLegacyMacro(method) method
643 # else
644 // Request compile-time warnings for uses of deprecated methods.
645 # define itkLegacyMacro(method) [[deprecated]] method
646 # endif
647 #endif
648 
649 // Macros to create runtime deprecation warning messages in function
650 // bodies. Example usage:
651 //
652 // #if !defined( ITK_LEGACY_REMOVE )
653 // void itkMyClass::MyOldMethod()
654 // {
655 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
656 // }
657 //
658 // void itkMyClass::MyMethod()
659 // {
660 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
661 // itkMyClass::MyOtherMethod);
662 // }
663 // #endif
664 //
665 // NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
666 // itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
667 // are purposefully not defined when ITK_LEGACY_REMOVE is on,
668 // because these macros are only relevant inside code segments
669 // that are conditionally compiled only when ITK_LEGACY_REMOVE
670 // is off.
671 #if defined(ITK_LEGACY_SILENT)
672 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
673 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
674 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
675 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
676 #else
677 # define itkLegacyBodyMacro(method, version) \
678  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
679 # define itkLegacyReplaceBodyMacro(method, version, replace) \
680  itkWarningMacro(#method " was deprecated for ITK " #version \
681  " and will be removed in a future version. Use " #replace " instead.")
682 # define itkGenericLegacyBodyMacro(method, version) \
683  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
684 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
685  itkGenericOutputMacro(#method " was deprecated for ITK " #version \
686  " and will be removed in a future version. Use " #replace " instead.")
687 #endif
688 
689 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
690 // the cache lines. By aligning multi-threaded structures with the
691 // cache lines, false shared can be reduced, and performance
692 // increased.
693 #define ITK_CACHE_LINE_ALIGNMENT 64
694 
695 //
696 // itkPadStruct will add padding to a structure to ensure a minimum size
697 // for ensuring that adjacent structures do not share CACHE lines.
698 // Each struct will take up some multiple of cacheline sizes.
699 // This is particularly useful for arrays of thread private variables.
700 //
701 #define itkPadStruct(mincachesize, oldtype, newtype) \
702  struct newtype : public oldtype \
703  { \
704  char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
705  };
706 
707 //
708 // itkAlignedTypedef is a macro which creates a new type to make a
709 // data structure aligned.
710 //
711 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
712 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
713 #elif defined(_MSC_VER)
714 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
715 #else
716 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
717 #endif
718 
719 #if defined(ITK_FUTURE_LEGACY_REMOVE)
720 //=============================================================================
721 /*
722 NOTE: DEPRECATED - This macro is not longer needed to support modern
723 compilers.
724 
725  Define a common way of declaring a templated function as a friend inside a class.
726  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
727 
728  The following templated function
729 
730  template <T>
731  T add(const T & a, const T & b);
732 
733  is declared as friend with
734 
735  class A
736  {
737  public:
738  friend Self add<>( const Self & a, const Self & b );
739  }
740 
741 */
742 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
743 #else // LEGACY_REMOVE
744 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
745 #endif
746 
747 //--------------------------------------------------------------------------------
748 // Helper macros for Template Meta-Programming techniques of for-loops
749 // unrolling
750 //--------------------------------------------------------------------------------
751 
752 //--------------------------------------------------------------------------------
753 // Macro that generates an unrolled for loop for assigning elements of one array
754 // to elements of another array The array are assumed to be of same length
755 // (dimension), and this is also assumed to be the value of NumberOfIterations.
756 // No verification of size is performed. Casting is performed as part of the
757 // assignment, by using the DestinationElementType as the casting type.
758 // Source and destination array types must have defined operator[] in their
759 // API.
760 #define itkForLoopAssignmentMacro( \
761  DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
762  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
763  { \
764  DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
765  }
766 
767 //--------------------------------------------------------------------------------
768 // Macro that generates an unrolled for loop for rounding and assigning
769 // elements of one array to elements of another array The array are assumed to
770 // be of same length (dimension), and this is also assumed to be the value of
771 // NumberOfIterations. No verification of size is performed. Casting is
772 // performed as part of the assignment, by using the DestinationElementType as
773 // the casting type.
774 // Source and destination array types must have defined operator[] in their
775 // API.
776 #define itkForLoopRoundingAndAssignmentMacro( \
777  DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
778  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
779  { \
780  DestinationArray[i] = itk::Math::Round<DestinationElementType>(SourceArray[i]); \
781  }
782 
783 // end of Template Meta Programming helper macros
784 
785 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
786 
787 # ifdef __GLIBC__
788 # define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
789 # else
790 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
791 # endif
792 
793 #else
794 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
795 #endif
796 
797 #define itkAssertOrThrowMacro(test, message) \
798  if (!(test)) \
799  { \
800  std::ostringstream msgstr; \
801  msgstr << message; \
802  itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
803  } \
804  ITK_MACROEND_NOOP_STATEMENT
805 
806 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
807 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
808 #else
809 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
810 #endif
811 
812 
813 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
814 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
815 // !! The ITK Get/Set Macros for various types !!
816 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
817 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
818 
819 #ifdef ITK_FUTURE_LEGACY_REMOVE
820 # define itkStaticConstMacro(name, type, value) \
821  "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
822 # define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
823 #else
824 
838 # define itkStaticConstMacro(name, type, value) static constexpr type name = value
839 
840 # define itkGetStaticConstMacro(name) (Self::name)
841 #endif
842 
844 #define itkSetInputMacro(name, type) \
845  virtual void Set##name(const type * _arg) \
846  { \
847  itkDebugMacro("setting input " #name " to " << _arg); \
848  if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
849  { \
850  this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
851  this->Modified(); \
852  } \
853  } \
854  ITK_MACROEND_NOOP_STATEMENT
855 
858 #define itkGetInputMacro(name, type) \
859  virtual const type * Get##name() const \
860  { \
861  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
862  return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
863  } \
864  ITK_MACROEND_NOOP_STATEMENT
865 
867 // clang-format off
869 #define itkSetDecoratedInputMacro(name, type) \
870  virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
871  { \
872  itkDebugMacro("setting input " #name " to " << _arg); \
873  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
874  { \
875  this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
876  this->Modified(); \
877  } \
878  } \
879  virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
880  virtual void Set##name(const type & _arg) \
881  { \
882  using DecoratorType = SimpleDataObjectDecorator<type>; \
883  itkDebugMacro("setting input " #name " to " << _arg); \
884  const DecoratorType * oldInput = \
885  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
886  CLANG_PRAGMA_PUSH \
887  CLANG_SUPPRESS_Wfloat_equal \
888  if (oldInput && oldInput->Get() == _arg) \
889  { \
890  return; \
891  } \
892  CLANG_PRAGMA_POP \
893  auto newInput = DecoratorType::New(); \
894  newInput->Set(_arg); \
895  this->Set##name##Input(newInput); \
896  } \
897  ITK_MACROEND_NOOP_STATEMENT
898 // clang-format on
902 #define itkGetDecoratedInputMacro(name, type) \
903  virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
904  { \
905  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
906  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
907  } \
908  virtual const type & Get##name() const \
909  { \
910  itkDebugMacro("Getting input " #name); \
911  using DecoratorType = SimpleDataObjectDecorator<type>; \
912  const DecoratorType * input = \
913  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
914  if (input == nullptr) \
915  { \
916  itkExceptionMacro(<< "input" #name " is not set"); \
917  } \
918  return input->Get(); \
919  } \
920  ITK_MACROEND_NOOP_STATEMENT
921 
925 #define itkSetGetDecoratedInputMacro(name, type) \
926  itkSetDecoratedInputMacro(name, type); \
927  itkGetDecoratedInputMacro(name, type)
928 
933 #define itkSetDecoratedObjectInputMacro(name, type) \
934  virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
935  { \
936  itkDebugMacro("setting input " #name " to " << _arg); \
937  if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
938  { \
939  this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
940  this->Modified(); \
941  } \
942  } \
943  virtual void Set##name(const type * _arg) \
944  { \
945  using DecoratorType = DataObjectDecorator<type>; \
946  itkDebugMacro("setting input " #name " to " << _arg); \
947  const DecoratorType * oldInput = \
948  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
949  if (oldInput && oldInput->Get() == _arg) \
950  { \
951  return; \
952  } \
953  auto newInput = DecoratorType::New(); \
954  newInput->Set(_arg); \
955  this->Set##name##Input(newInput); \
956  } \
957  ITK_MACROEND_NOOP_STATEMENT
958 
964 #define itkGetDecoratedObjectInputMacro(name, type) \
965  virtual const DataObjectDecorator<type> * Get##name##Input() const \
966  { \
967  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
968  return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
969  } \
970  virtual const type * Get##name() const \
971  { \
972  itkDebugMacro("Getting input " #name); \
973  using DecoratorType = DataObjectDecorator<type>; \
974  const DecoratorType * input = \
975  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
976  if (input == nullptr) \
977  { \
978  return nullptr; \
979  } \
980  return input->Get(); \
981  } \
982  ITK_MACROEND_NOOP_STATEMENT
983 
987 #define itkSetGetDecoratedObjectInputMacro(name, type) \
988  itkSetDecoratedObjectInputMacro(name, type); \
989  itkGetDecoratedObjectInputMacro(name, type)
990 
992 // clang-format off
993 #define itkSetMacro(name, type) \
994  virtual void Set##name(const type _arg) \
995  { \
996  itkDebugMacro("setting " #name " to " << _arg); \
997  CLANG_PRAGMA_PUSH \
998  CLANG_SUPPRESS_Wfloat_equal \
999  if (this->m_##name != _arg) \
1000  { \
1001  this->m_##name = _arg; \
1002  this->Modified(); \
1003  } \
1004  CLANG_PRAGMA_POP \
1005  } \
1006  ITK_MACROEND_NOOP_STATEMENT
1007 // clang-format on
1008 
1010 #define itkGetMacro(name, type) \
1011  virtual type Get##name() { return this->m_##name; } \
1012  ITK_MACROEND_NOOP_STATEMENT
1013 
1018 #define itkGetConstMacro(name, type) \
1019  virtual type Get##name() const { return this->m_##name; } \
1020  ITK_MACROEND_NOOP_STATEMENT
1021 
1027 #define itkGetConstReferenceMacro(name, type) \
1028  virtual const type & Get##name() const { return this->m_##name; } \
1029  ITK_MACROEND_NOOP_STATEMENT
1030 
1036 #define itkSetEnumMacro(name, type) \
1037  virtual void Set##name(const type _arg) \
1038  { \
1039  itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1040  if (this->m_##name != _arg) \
1041  { \
1042  this->m_##name = _arg; \
1043  this->Modified(); \
1044  } \
1045  } \
1046  ITK_MACROEND_NOOP_STATEMENT
1047 
1053 #define itkGetEnumMacro(name, type) \
1054  virtual type Get##name() const { return this->m_##name; } \
1055  ITK_MACROEND_NOOP_STATEMENT
1056 
1061 #define itkSetStringMacro(name) \
1062  virtual void Set##name(const char * _arg) \
1063  { \
1064  if (_arg && (_arg == this->m_##name)) \
1065  { \
1066  return; \
1067  } \
1068  if (_arg) \
1069  { \
1070  this->m_##name = _arg; \
1071  } \
1072  else \
1073  { \
1074  this->m_##name = ""; \
1075  } \
1076  this->Modified(); \
1077  } \
1078  virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1079  ITK_MACROEND_NOOP_STATEMENT
1080 
1086 #define itkGetStringMacro(name) \
1087  virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1088  ITK_MACROEND_NOOP_STATEMENT
1089 
1090 // clang-format off
1094 #define itkSetClampMacro(name, type, min, max) \
1095  virtual void Set##name(type _arg) \
1096  { \
1097  const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1098  itkDebugMacro("setting " << #name " to " << _arg); \
1099  CLANG_PRAGMA_PUSH \
1100  CLANG_SUPPRESS_Wfloat_equal \
1101  if (this->m_##name != temp_extrema) \
1102  { \
1103  this->m_##name = temp_extrema; \
1104  this->Modified(); \
1105  } \
1106  CLANG_PRAGMA_POP \
1107  } \
1108  ITK_MACROEND_NOOP_STATEMENT
1109 // clang-format on
1112 // clang-format off
1113 // NOTE: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
1118 #define itkSetObjectMacro(name, type) \
1119  virtual void Set##name(type * _arg) \
1120  { \
1121  itkDebugMacro("setting " << #name " to " << _arg); \
1122  CLANG_PRAGMA_PUSH \
1123  CLANG_SUPPRESS_Wfloat_equal \
1124  if (this->m_##name != _arg) \
1125  { \
1126  this->m_##name = _arg; \
1127  this->Modified(); \
1128  } \
1129  CLANG_PRAGMA_POP \
1130  } \
1131  ITK_MACROEND_NOOP_STATEMENT
1132 // clang-format on
1143 // NOTE: A class can use either itkGetModifiableObjectMacro
1144 // or itkGetObjectMacro, but not both.
1145 // A class can use either itkGetModifiableObjectMacro
1146 // or itkGetConstObjectMacro, but not both.
1147 // If the desired behavior is to only provide const
1148 // access to the itkObject ivar, then use itkGetConstObjectMacro,
1149 // else use itkGetModifiableObjectMacro for read/write access to
1150 // the ivar.
1151 // It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1152 // for backwards compatibility.
1153 // If the ITK_LEGACY_REMOVE=FALSE, then it is
1154 // permissible to use itkGetObjectMacro which
1155 // defines both signatures itk::GetXXX() and
1156 // itk::GetModifiableXXX()
1157 
1160 #define itkGetConstObjectMacro(name, type) \
1161  virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1162  ITK_MACROEND_NOOP_STATEMENT
1163 
1164 
1165 #if defined(ITK_FUTURE_LEGACY_REMOVE)
1166 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1167 // flag. For now, this very advanced feature is only available
1168 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1169 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1170 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1171 # define itkGetObjectMacro(name, type) \
1172  virtual type * Get##name() \
1173  { \
1174  purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1175  }
1176 
1177 # define itkGetModifiableObjectMacro(name, type) \
1178  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1179  itkGetConstObjectMacro(name, type)
1180 
1181 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1182 
1184 # define itkGetObjectMacro(name, type) \
1185  virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1186  ITK_MACROEND_NOOP_STATEMENT
1187 # define itkGetModifiableObjectMacro(name, type) \
1188  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1189  itkGetConstObjectMacro(name, type); \
1190  itkGetObjectMacro(name, type)
1191 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1192 
1194 // For backwards compatibility define ITK_EXPORT to nothing
1195 #define ITK_EXPORT
1196 
1197 
1200 #define itkGetConstReferenceObjectMacro(name, type) \
1201  virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1202  ITK_MACROEND_NOOP_STATEMENT
1203 
1208 #define itkSetConstObjectMacro(name, type) \
1209  virtual void Set##name(const type * _arg) \
1210  { \
1211  itkDebugMacro("setting " << #name " to " << _arg); \
1212  if (this->m_##name != _arg) \
1213  { \
1214  this->m_##name = _arg; \
1215  this->Modified(); \
1216  } \
1217  } \
1218  ITK_MACROEND_NOOP_STATEMENT
1219 
1223 #define itkBooleanMacro(name) \
1224  virtual void name##On() { this->Set##name(true); } \
1225  virtual void name##Off() { this->Set##name(false); }
1226 
1228 // clang-format off
1232 #define itkSetVectorMacro(name, type, count) \
1233  virtual void Set##name(type data[]) \
1234  { \
1235  unsigned int i; \
1236  for (i = 0; i < count; ++i) \
1237  { \
1238  CLANG_PRAGMA_PUSH \
1239  CLANG_SUPPRESS_Wfloat_equal \
1240  if (data[i] != this->m_##name[i]) \
1241  { \
1242  break; \
1243  } \
1244  CLANG_PRAGMA_POP \
1245  } \
1246  if (i < count) \
1247  { \
1248  this->Modified(); \
1249  for (i = 0; i < count; ++i) \
1250  { \
1251  this->m_##name[i] = data[i]; \
1252  } \
1253  } \
1254  } \
1255  ITK_MACROEND_NOOP_STATEMENT
1256 // clang-format on
1261 #define itkGetVectorMacro(name, type, count) \
1262  virtual type * Get##name() const { return this->m_##name; } \
1263  ITK_MACROEND_NOOP_STATEMENT
1264 
1269 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1270 
1276 #define itkGPUKernelMacro(kernel) \
1277  kernel \
1278  { \
1279  public: \
1280  ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1281  kernel() = delete; \
1282  ~kernel() = delete; \
1283  static const char * GetOpenCLSource(); \
1284  }
1285 
1287 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1288  static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); }
1289 
1290 // A useful macro in the PrintSelf method for printing member variables
1291 // which are pointers to object based on the LightObject class.
1292 #define itkPrintSelfObjectMacro(name) \
1293  if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1294  { \
1295  os << indent << #name << ": (null)" << std::endl; \
1296  } \
1297  else \
1298  { \
1299  os << indent << #name << ": " << std::endl; \
1300  this->m_##name->Print(os, indent.GetNextIndent()); \
1301  } \
1302  ITK_MACROEND_NOOP_STATEMENT
1303 
1304 
1306 #define itkSetDecoratedOutputMacro(name, type) \
1307  virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1308  { \
1309  itkDebugMacro("setting output " #name " to " << _arg); \
1310  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1311  { \
1312  this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1313  this->Modified(); \
1314  } \
1315  } \
1316  virtual void Set##name(const type & _arg) \
1317  { \
1318  using DecoratorType = SimpleDataObjectDecorator<type>; \
1319  itkDebugMacro("setting output " #name " to " << _arg); \
1320  DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1321  if (output) \
1322  { \
1323  if (output->Get() == _arg) \
1324  { \
1325  return; \
1326  } \
1327  else \
1328  { \
1329  output->Set(_arg); \
1330  } \
1331  } \
1332  else \
1333  { \
1334  auto newOutput = DecoratorType::New(); \
1335  newOutput->Set(_arg); \
1336  this->Set##name##Output(newOutput); \
1337  } \
1338  } \
1339  ITK_MACROEND_NOOP_STATEMENT
1340 
1343 #define itkGetDecoratedOutputMacro(name, type) \
1344  virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1345  { \
1346  itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1347  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1348  } \
1349  virtual const type & Get##name() const \
1350  { \
1351  itkDebugMacro("Getting output " #name); \
1352  using DecoratorType = SimpleDataObjectDecorator<type>; \
1353  const DecoratorType * output = \
1354  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1355  if (output == nullptr) \
1356  { \
1357  itkExceptionMacro(<< "output" #name " is not set"); \
1358  } \
1359  return output->Get(); \
1360  } \
1361  ITK_MACROEND_NOOP_STATEMENT
1362 
1374 #if defined(ITKV4_COMPATIBILITY)
1375 # define ITK_ITERATOR_VIRTUAL virtual
1376 # define ITK_ITERATOR_OVERRIDE override
1377 # define ITK_ITERATOR_FINAL
1378 #elif !defined(ITK_LEGACY_REMOVE)
1379 # define ITK_ITERATOR_VIRTUAL virtual
1380 # define ITK_ITERATOR_OVERRIDE override
1381 # define ITK_ITERATOR_FINAL final
1382 #else
1383 # define ITK_ITERATOR_VIRTUAL
1384 # define ITK_ITERATOR_OVERRIDE
1385 # define ITK_ITERATOR_FINAL
1386 #endif
1387 
1388 #if defined(ITKV4_COMPATIBILITY)
1389 // A macro for methods which are const in ITKv5, but not in ITKv4
1390 # define ITKv5_CONST
1391 #else
1392 // A macro for methods which are const in ITKv5, but not in ITKv4
1393 # define ITKv5_CONST const
1394 #endif
1395 
1396 #define itkExceptionObject_h
1397 #include "itkExceptionObject.h"
1398 #undef itkExceptionObject_h
1399 
1407 template <typename TTarget, typename TSource>
1408 TTarget
1409 itkDynamicCastInDebugMode(TSource x)
1410 {
1411 #ifndef NDEBUG
1412  if (x == nullptr)
1413  {
1414  return nullptr;
1415  }
1416  TTarget rval = dynamic_cast<TTarget>(x);
1417  if (rval == nullptr)
1418  {
1419  itkGenericExceptionMacro(<< "Failed dynamic cast to " << typeid(TTarget).name()
1420  << " object type = " << x->GetNameOfClass());
1421  }
1422  return rval;
1423 #else
1424  return static_cast<TTarget>(x);
1425 #endif
1426 }
1429 // Defines which used to be in itk_compiler_detection.h
1430 #define ITK_ALIGNAS(X) alignas(X)
1431 #define ITK_ALIGNOF(X) alignof(X)
1432 #define ITK_DEPRECATED [[deprecated]]
1433 #define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1434 #define ITK_CONSTEXPR constexpr
1435 #define ITK_DELETED_FUNCTION = delete
1436 #define ITK_EXTERN_TEMPLATE extern
1437 #define ITK_FINAL final
1438 #define ITK_NOEXCEPT noexcept
1439 #define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1440 #define ITK_NULLPTR nullptr
1441 #define ITK_OVERRIDE override
1442 #define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1443 #define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1444 #define ITK_THREAD_LOCAL thread_local
1445 
1446 #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