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  * http://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_Wc__14_extensions ITK_PRAGMA(clang diagnostic ignored "-Wc++14-extensions")
114 # else
115 # define CLANG_SUPPRESS_Wc__14_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_Wc__14_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 # if __GNUC__ >= 4
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 
317 
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 
360 #define itkFactorylessNewMacro(x) \
361  static Pointer New() \
362  { \
363  Pointer smartPtr; \
364  x * rawPtr = new x; \
365  smartPtr = rawPtr; \
366  rawPtr->UnRegister(); \
367  return smartPtr; \
368  } \
369  ::itk::LightObject::Pointer CreateAnother() const override \
370  { \
371  ::itk::LightObject::Pointer smartPtr; \
372  smartPtr = x::New().GetPointer(); \
373  return smartPtr; \
374  } \
375  ITK_MACROEND_NOOP_STATEMENT
376 
377 
378 //
379 // A macro to disallow the copy constructor, copy assignment,
380 // move constructor, and move assignment functions.
381 // This should be used in the public: declarations for a class
382 //
383 // ITK's paradigm for smart pointer and pipeline consistency
384 // prohibits the use of copy/move construction and copy/move assignment
385 // functions.
386 //
387 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
388  TypeName(const TypeName &) = delete; \
389  TypeName & operator=(const TypeName &) = delete; \
390  TypeName(TypeName &&) = delete; \
391  TypeName & operator=(TypeName &&) = delete
392 
393 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
394 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
395 #else
396 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
397  static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
398 #endif
399 
400 
401 // When ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR is defined, ITK uses
402 // the ability for operator!= to be rewritten automatically in terms of
403 // operator==, as introduced with C++20. This macro is experimental. It may be
404 // modified, renamed, or removed without backward compatibility support.
405 #if __cplusplus >= 202002L
406 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
407 #endif
408 
409 // Note: The following macro, ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName),
410 // is only for internal use within the implementation of ITK. It may be
411 // modified, renamed, or removed without backward compatibility support.
412 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
413 // With C++20, operator!= is automatically rewritten in terms of the
414 // corresponding operator==.
415 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
416 #else
417 // For C++14 and C++17, this macro defines an operator!= member function that
418 // just calls the corresponding operator== member function.
419 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
420  bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
421  ITK_MACROEND_NOOP_STATEMENT
422 #endif
423 
426 #define itkTypeMacro(thisClass, superclass) \
427  const char * GetNameOfClass() const override { return #thisClass; } \
428  ITK_MACROEND_NOOP_STATEMENT
429 
430 #define itkTypeMacroNoParent(thisClass) \
431  virtual const char * GetNameOfClass() const { return #thisClass; } \
432  ITK_MACROEND_NOOP_STATEMENT
433 
434 namespace itk
435 {
442 extern ITKCommon_EXPORT void
443 OutputWindowDisplayText(const char *);
445 
446 extern ITKCommon_EXPORT void
447 OutputWindowDisplayErrorText(const char *);
448 
449 extern ITKCommon_EXPORT void
450 OutputWindowDisplayWarningText(const char *);
451 
452 extern ITKCommon_EXPORT void
453 OutputWindowDisplayGenericOutputText(const char *);
454 
455 extern ITKCommon_EXPORT void
456 OutputWindowDisplayDebugText(const char *);
457 } // end namespace itk
458 
459 // The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
463 #if defined(NDEBUG)
464 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
465 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
466 #else
467 # define itkDebugMacro(x) \
468  do \
469  { \
470  if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
471  { \
472  std::ostringstream itkmsg; \
473  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
474  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
475  ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
476  } \
477  } while (0)
478 
479 
480 // The itkDebugStatement is to be used to protect code that is only
481 // used in the itkDebugMacro
482 # define itkDebugStatement(x) x
483 #endif
484 
488 #define itkWarningMacro(x) \
489  do \
490  { \
491  if (::itk::Object::GetGlobalWarningDisplay()) \
492  { \
493  std::ostringstream itkmsg; \
494  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
495  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
496  ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
497  } \
498  } while (0)
499 
500 
501 #define itkWarningStatement(x) x
502 
503 #if defined(ITK_CPP_FUNCTION)
504 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
505 # define ITK_LOCATION __FUNCSIG__
506 # elif defined(__GNUC__)
507 # define ITK_LOCATION __PRETTY_FUNCTION__
508 # else
509 # define ITK_LOCATION __FUNCTION__
510 # endif
511 #else
512 # define ITK_LOCATION "unknown"
513 #endif
514 
515 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
516  namespace itk \
517  { \
518  class newexcp : public parentexcp \
519  { \
520  public: \
521  /* default message provides backward compatibility for a given exception type */ \
522  static constexpr const char * const default_exception_message = whatmessage; \
523  /* Inherit the constructors from its base class. */ \
524  using parentexcp::parentexcp; \
525  itkTypeMacro(newexcp, parentexcp); \
526  }; \
527  } \
528  ITK_MACROEND_NOOP_STATEMENT
529 
530 
531 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
532  { \
533  std::ostringstream exceptionDescriptionOutputStringStream; \
534  exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
535  throw ::itk::ExceptionType( \
536  std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
537  } \
538  ITK_MACROEND_NOOP_STATEMENT
539 
540 #define itkSpecializedExceptionMacro(ExceptionType) \
541  itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
542 
546 #define itkExceptionMacro(x) \
547  itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << "(" << this << "): " x)
548 
549 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
550 
551 #define itkGenericOutputMacro(x) \
552  { \
553  if (::itk::Object::GetGlobalWarningDisplay()) \
554  { \
555  std::ostringstream itkmsg; \
556  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
557  ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
558  } \
559  } \
560  ITK_MACROEND_NOOP_STATEMENT
561 
562 //----------------------------------------------------------------------------
563 // Macros for simplifying the use of logging
564 //
565 #define itkLogMacro(x, y) \
566  { \
567  if (this->GetLogger()) \
568  { \
569  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
570  } \
571  } \
572  ITK_MACROEND_NOOP_STATEMENT
573 
574 #define itkLogMacroStatic(obj, x, y) \
575  { \
576  if (obj->GetLogger()) \
577  { \
578  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
579  } \
580  } \
581  ITK_MACROEND_NOOP_STATEMENT
582 
583 //----------------------------------------------------------------------------
584 // Setup legacy code policy.
585 //
586 // CMake options:
587 // - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
588 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
589 // of legacy code will not produce compiler warnings.
590 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
591 // of legacy code will produce compiler warnings
592 //
593 // ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
594 //
595 // Source files that test the legacy code may define ITK_LEGACY_TEST
596 // like this:
597 //
598 // #define ITK_LEGACY_TEST
599 // #include "itkClassWithDeprecatedMethod.h"
600 //
601 // in order to silence the warnings for calling deprecated methods.
602 // No other source files in ITK should call the methods since they are
603 // provided only for compatibility with older user code.
604 
605 // Define itkLegacyMacro to mark legacy methods where they are
606 // declared in their class. Example usage:
607 //
608 // // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
609 // itkLegacyMacro(void MyMethod());
610 //
611 // See below for what to do for the method definition.
612 #if defined(ITK_LEGACY_REMOVE)
613 # define itkLegacyMacro(method) /* no ';' */
614 #else
615 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
616 // Provide legacy methods with no warnings.
617 # define itkLegacyMacro(method) method
618 # else
619 // Request compile-time warnings for uses of deprecated methods.
620 # define itkLegacyMacro(method) [[deprecated]] method
621 # endif
622 #endif
623 
624 // Macros to create runtime deprecation warning messages in function
625 // bodies. Example usage:
626 //
627 // #if !defined( ITK_LEGACY_REMOVE )
628 // void itkMyClass::MyOldMethod()
629 // {
630 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
631 // }
632 //
633 // void itkMyClass::MyMethod()
634 // {
635 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
636 // itkMyClass::MyOtherMethod);
637 // }
638 // #endif
639 //
640 // NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
641 // itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
642 // are purposefully not defined when ITK_LEGACY_REMOVE is on,
643 // because these macros are only relevant inside code segments
644 // that are conditionally compiled only when ITK_LEGACY_REMOVE
645 // is off.
646 #if defined(ITK_LEGACY_SILENT)
647 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
648 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
649 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
650 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
651 #else
652 # define itkLegacyBodyMacro(method, version) \
653  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
654 # define itkLegacyReplaceBodyMacro(method, version, replace) \
655  itkWarningMacro(#method " was deprecated for ITK " #version \
656  " and will be removed in a future version. Use " #replace " instead.")
657 # define itkGenericLegacyBodyMacro(method, version) \
658  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
659 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
660  itkGenericOutputMacro(#method " was deprecated for ITK " #version \
661  " and will be removed in a future version. Use " #replace " instead.")
662 #endif
663 
664 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
665 // the cache lines. By aligning multi-threaded structures with the
666 // cache lines, false shared can be reduced, and performance
667 // increased.
668 #define ITK_CACHE_LINE_ALIGNMENT 64
669 
670 //
671 // itkPadStruct will add padding to a structure to ensure a minimum size
672 // for ensuring that adjacent structures do not share CACHE lines.
673 // Each struct will take up some multiple of cacheline sizes.
674 // This is particularly useful for arrays of thread private variables.
675 //
676 #define itkPadStruct(mincachesize, oldtype, newtype) \
677  struct newtype : public oldtype \
678  { \
679  char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
680  };
681 
682 //
683 // itkAlignedTypedef is a macro which creates a new type to make a
684 // data structure aligned.
685 //
686 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
687 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
688 #elif defined(_MSC_VER)
689 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
690 #else
691 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
692 #endif
693 
694 #if defined(ITK_FUTURE_LEGACY_REMOVE)
695 //=============================================================================
696 /*
697 NOTE: DEPRECATED - This macro is not longer needed to support modern
698 compilers.
699 
700  Define a common way of declaring a templated function as a friend inside a class.
701  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
702 
703  The following templated function
704 
705  template <T>
706  T add(const T & a, const T & b);
707 
708  is declared as friend with
709 
710  class A
711  {
712  public:
713  friend Self add<>( const Self & a, const Self & b );
714  }
715 
716 */
717 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
718 #else // LEGACY_REMOVE
719 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
720 #endif
721 
722 //--------------------------------------------------------------------------------
723 // Helper macros for Template Meta-Programming techniques of for-loops
724 // unrolling
725 //--------------------------------------------------------------------------------
726 
727 //--------------------------------------------------------------------------------
728 // Macro that generates an unrolled for loop for assigning elements of one array
729 // to elements of another array The array are assumed to be of same length
730 // (dimension), and this is also assumed to be the value of NumberOfIterations.
731 // No verification of size is performed. Casting is performed as part of the
732 // assignment, by using the DestinationElementType as the casting type.
733 // Source and destination array types must have defined operator[] in their
734 // API.
735 #define itkForLoopAssignmentMacro( \
736  DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
737  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
738  { \
739  DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
740  }
741 
742 //--------------------------------------------------------------------------------
743 // Macro that generates an unrolled for loop for rounding and assigning
744 // elements of one array to elements of another array The array are assumed to
745 // be of same length (dimension), and this is also assumed to be the value of
746 // NumberOfIterations. No verification of size is performed. Casting is
747 // performed as part of the assignment, by using the DestinationElementType as
748 // the casting type.
749 // Source and destination array types must have defined operator[] in their
750 // API.
751 #define itkForLoopRoundingAndAssignmentMacro( \
752  DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
753  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
754  { \
755  DestinationArray[i] = itk::Math::Round<DestinationElementType>(SourceArray[i]); \
756  }
757 
758 // end of Template Meta Programming helper macros
759 
760 #ifndef NDEBUG
761 
762 # ifdef _POSIX_SOURCE
763 # define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
764 # else
765 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
766 # endif
767 
768 #else
769 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
770 #endif
771 
772 #define itkAssertOrThrowMacro(test, message) \
773  if (!(test)) \
774  { \
775  std::ostringstream msgstr; \
776  msgstr << message; \
777  itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
778  } \
779  ITK_MACROEND_NOOP_STATEMENT
780 
781 #ifndef NDEBUG
782 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
783 #else
784 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
785 #endif
786 
787 
788 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
789 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
790 // !! The ITK Get/Set Macros for various types !!
791 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
792 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
807 #define itkStaticConstMacro(name, type, value) static constexpr type name = value
808 
809 #define itkGetStaticConstMacro(name) (Self::name)
810 
812 #define itkSetInputMacro(name, type) \
813  virtual void Set##name(const type * _arg) \
814  { \
815  itkDebugMacro("setting input " #name " to " << _arg); \
816  if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
817  { \
818  this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
819  this->Modified(); \
820  } \
821  } \
822  ITK_MACROEND_NOOP_STATEMENT
823 
824 
826 #define itkGetInputMacro(name, type) \
827  virtual const type * Get##name() const \
828  { \
829  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
830  return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
831  } \
832  ITK_MACROEND_NOOP_STATEMENT
833 
834 
835 // clang-format off
837 #define itkSetDecoratedInputMacro(name, type) \
838  virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
839  { \
840  itkDebugMacro("setting input " #name " to " << _arg); \
841  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
842  { \
843  this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
844  this->Modified(); \
845  } \
846  } \
847  virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
848  virtual void Set##name(const type & _arg) \
849  { \
850  using DecoratorType = SimpleDataObjectDecorator<type>; \
851  itkDebugMacro("setting input " #name " to " << _arg); \
852  const DecoratorType * oldInput = \
853  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
854  CLANG_PRAGMA_PUSH \
855  CLANG_SUPPRESS_Wfloat_equal \
856  if (oldInput && oldInput->Get() == _arg) \
857  { \
858  return; \
859  } \
860  CLANG_PRAGMA_POP \
861  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
862  newInput->Set(_arg); \
863  this->Set##name##Input(newInput); \
864  } \
865  ITK_MACROEND_NOOP_STATEMENT
866 // clang-format on
868 
870 #define itkGetDecoratedInputMacro(name, type) \
871  virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
872  { \
873  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
874  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
875  } \
876  virtual const type & Get##name() const \
877  { \
878  itkDebugMacro("Getting input " #name); \
879  using DecoratorType = SimpleDataObjectDecorator<type>; \
880  const DecoratorType * input = \
881  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
882  if (input == nullptr) \
883  { \
884  itkExceptionMacro(<< "input" #name " is not set"); \
885  } \
886  return input->Get(); \
887  } \
888  ITK_MACROEND_NOOP_STATEMENT
889 
890 
893 #define itkSetGetDecoratedInputMacro(name, type) \
894  itkSetDecoratedInputMacro(name, type); \
895  itkGetDecoratedInputMacro(name, type)
896 
901 #define itkSetDecoratedObjectInputMacro(name, type) \
902  virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
903  { \
904  itkDebugMacro("setting input " #name " to " << _arg); \
905  if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
906  { \
907  this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
908  this->Modified(); \
909  } \
910  } \
911  virtual void Set##name(const type * _arg) \
912  { \
913  using DecoratorType = DataObjectDecorator<type>; \
914  itkDebugMacro("setting input " #name " to " << _arg); \
915  const DecoratorType * oldInput = \
916  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
917  if (oldInput && oldInput->Get() == _arg) \
918  { \
919  return; \
920  } \
921  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
922  newInput->Set(_arg); \
923  this->Set##name##Input(newInput); \
924  } \
925  ITK_MACROEND_NOOP_STATEMENT
926 
927 
932 #define itkGetDecoratedObjectInputMacro(name, type) \
933  virtual const DataObjectDecorator<type> * Get##name##Input() const \
934  { \
935  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
936  return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
937  } \
938  virtual const type * Get##name() const \
939  { \
940  itkDebugMacro("Getting input " #name); \
941  using DecoratorType = DataObjectDecorator<type>; \
942  const DecoratorType * input = \
943  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
944  if (input == nullptr) \
945  { \
946  return nullptr; \
947  } \
948  return input->Get(); \
949  } \
950  ITK_MACROEND_NOOP_STATEMENT
951 
952 
955 #define itkSetGetDecoratedObjectInputMacro(name, type) \
956  itkSetDecoratedObjectInputMacro(name, type); \
957  itkGetDecoratedObjectInputMacro(name, type)
958 
960 // clang-format off
961 #define itkSetMacro(name, type) \
962  virtual void Set##name(const type _arg) \
963  { \
964  itkDebugMacro("setting " #name " to " << _arg); \
965  CLANG_PRAGMA_PUSH \
966  CLANG_SUPPRESS_Wfloat_equal \
967  if (this->m_##name != _arg) \
968  { \
969  this->m_##name = _arg; \
970  this->Modified(); \
971  } \
972  CLANG_PRAGMA_POP \
973  } \
974  ITK_MACROEND_NOOP_STATEMENT
975 // clang-format on
976 
978 #define itkGetMacro(name, type) \
979  virtual type Get##name() { return this->m_##name; } \
980  ITK_MACROEND_NOOP_STATEMENT
981 
982 
986 #define itkGetConstMacro(name, type) \
987  virtual type Get##name() const { return this->m_##name; } \
988  ITK_MACROEND_NOOP_STATEMENT
989 
990 
995 #define itkGetConstReferenceMacro(name, type) \
996  virtual const type & Get##name() const { return this->m_##name; } \
997  ITK_MACROEND_NOOP_STATEMENT
998 
999 
1004 #define itkSetEnumMacro(name, type) \
1005  virtual void Set##name(const type _arg) \
1006  { \
1007  itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1008  if (this->m_##name != _arg) \
1009  { \
1010  this->m_##name = _arg; \
1011  this->Modified(); \
1012  } \
1013  } \
1014  ITK_MACROEND_NOOP_STATEMENT
1015 
1016 
1021 #define itkGetEnumMacro(name, type) \
1022  virtual type Get##name() const { return this->m_##name; } \
1023  ITK_MACROEND_NOOP_STATEMENT
1024 
1025 
1029 #define itkSetStringMacro(name) \
1030  virtual void Set##name(const char * _arg) \
1031  { \
1032  if (_arg && (_arg == this->m_##name)) \
1033  { \
1034  return; \
1035  } \
1036  if (_arg) \
1037  { \
1038  this->m_##name = _arg; \
1039  } \
1040  else \
1041  { \
1042  this->m_##name = ""; \
1043  } \
1044  this->Modified(); \
1045  } \
1046  virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1047  ITK_MACROEND_NOOP_STATEMENT
1048 
1049 
1050 
1054 #define itkGetStringMacro(name) \
1055  virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1056  ITK_MACROEND_NOOP_STATEMENT
1057 
1058 // clang-format off
1062 #define itkSetClampMacro(name, type, min, max) \
1063  virtual void Set##name(type _arg) \
1064  { \
1065  const type temp_extrema = (_arg < min ? min : (_arg > max ? max : _arg)); \
1066  itkDebugMacro("setting " << #name " to " << _arg); \
1067  CLANG_PRAGMA_PUSH \
1068  CLANG_SUPPRESS_Wfloat_equal \
1069  if (this->m_##name != temp_extrema) \
1070  { \
1071  this->m_##name = temp_extrema; \
1072  this->Modified(); \
1073  } \
1074  CLANG_PRAGMA_POP \
1075  } \
1076  ITK_MACROEND_NOOP_STATEMENT
1077 // clang-format on
1079 
1080 // clang-format off
1081 // NOTE: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
1086 #define itkSetObjectMacro(name, type) \
1087  virtual void Set##name(type * _arg) \
1088  { \
1089  itkDebugMacro("setting " << #name " to " << _arg); \
1090  CLANG_PRAGMA_PUSH \
1091  CLANG_SUPPRESS_Wfloat_equal \
1092  if (this->m_##name != _arg) \
1093  { \
1094  this->m_##name = _arg; \
1095  this->Modified(); \
1096  } \
1097  CLANG_PRAGMA_POP \
1098  } \
1099  ITK_MACROEND_NOOP_STATEMENT
1100 // clang-format on
1102 
1111 // NOTE: A class can use either itkGetModifiableObjectMacro
1112 // or itkGetObjectMacro, but not both.
1113 // A class can use either itkGetModifiableObjectMacro
1114 // or itkGetConstObjectMacro, but not both.
1115 // If the desired behavior is to only provide const
1116 // access to the itkObject ivar, then use itkGetConstObjectMacro,
1117 // else use itkGetModifiableObjectMacro for read/write access to
1118 // the ivar.
1119 // It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1120 // for backwards compatibility.
1121 // If the ITK_LEGACY_REMOVE=FALSE, then it is
1122 // permissible to use itkGetObjectMacro which
1123 // defines both signatures itk::GetXXX() and
1124 // itk::GetModifiableXXX()
1125 
1128 #define itkGetConstObjectMacro(name, type) \
1129  virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1130  ITK_MACROEND_NOOP_STATEMENT
1131 
1132 
1133 #if defined(ITK_FUTURE_LEGACY_REMOVE)
1134 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1135 // flag. For now, this very advanced feature is only available
1136 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1137 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1138 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1139 # define itkGetObjectMacro(name, type) \
1140  virtual type * Get##name() \
1141  { \
1142  purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1143  }
1144 
1145 # define itkGetModifiableObjectMacro(name, type) \
1146  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1147  itkGetConstObjectMacro(name, type)
1148 
1149 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1150 
1152 # define itkGetObjectMacro(name, type) \
1153  virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1154  ITK_MACROEND_NOOP_STATEMENT
1155 # define itkGetModifiableObjectMacro(name, type) \
1156  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1157  itkGetConstObjectMacro(name, type); \
1158  itkGetObjectMacro(name, type)
1159 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1160 
1161 
1162 // For backwards compatibility define ITK_EXPORT to nothing
1163 #define ITK_EXPORT
1164 
1165 
1168 #define itkGetConstReferenceObjectMacro(name, type) \
1169  virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1170  ITK_MACROEND_NOOP_STATEMENT
1171 
1176 #define itkSetConstObjectMacro(name, type) \
1177  virtual void Set##name(const type * _arg) \
1178  { \
1179  itkDebugMacro("setting " << #name " to " << _arg); \
1180  if (this->m_##name != _arg) \
1181  { \
1182  this->m_##name = _arg; \
1183  this->Modified(); \
1184  } \
1185  } \
1186  ITK_MACROEND_NOOP_STATEMENT
1187 
1188 
1191 #define itkBooleanMacro(name) \
1192  virtual void name##On() { this->Set##name(true); } \
1193  virtual void name##Off() { this->Set##name(false); }
1194 
1195 
1196 // clang-format off
1200 #define itkSetVectorMacro(name, type, count) \
1201  virtual void Set##name(type data[]) \
1202  { \
1203  unsigned int i; \
1204  for (i = 0; i < count; ++i) \
1205  { \
1206  CLANG_PRAGMA_PUSH \
1207  CLANG_SUPPRESS_Wfloat_equal \
1208  if (data[i] != this->m_##name[i]) \
1209  { \
1210  break; \
1211  } \
1212  CLANG_PRAGMA_POP \
1213  } \
1214  if (i < count) \
1215  { \
1216  this->Modified(); \
1217  for (i = 0; i < count; ++i) \
1218  { \
1219  this->m_##name[i] = data[i]; \
1220  } \
1221  } \
1222  } \
1223  ITK_MACROEND_NOOP_STATEMENT
1224 // clang-format on
1226 
1229 #define itkGetVectorMacro(name, type, count) \
1230  virtual type * Get##name() const { return this->m_##name; } \
1231  ITK_MACROEND_NOOP_STATEMENT
1232 
1237 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1238 
1244 #define itkGPUKernelMacro(kernel) \
1245  kernel \
1246  { \
1247  public: \
1248  ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1249  kernel() = delete; \
1250  ~kernel() = delete; \
1251  static const char * GetOpenCLSource(); \
1252  }
1253 
1254 
1255 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1256  static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); }
1257 
1258 // A useful macro in the PrintSelf method for printing member variables
1259 // which are pointers to object based on the LightObject class.
1260 #define itkPrintSelfObjectMacro(name) \
1261  if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1262  { \
1263  os << indent << #name << ": (null)" << std::endl; \
1264  } \
1265  else \
1266  { \
1267  os << indent << #name << ": " << std::endl; \
1268  this->m_##name->Print(os, indent.GetNextIndent()); \
1269  } \
1270  ITK_MACROEND_NOOP_STATEMENT
1271 
1272 
1274 #define itkSetDecoratedOutputMacro(name, type) \
1275  virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1276  { \
1277  itkDebugMacro("setting output " #name " to " << _arg); \
1278  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1279  { \
1280  this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1281  this->Modified(); \
1282  } \
1283  } \
1284  virtual void Set##name(const type & _arg) \
1285  { \
1286  using DecoratorType = SimpleDataObjectDecorator<type>; \
1287  itkDebugMacro("setting output " #name " to " << _arg); \
1288  DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1289  if (output) \
1290  { \
1291  if (output->Get() == _arg) \
1292  { \
1293  return; \
1294  } \
1295  else \
1296  { \
1297  output->Set(_arg); \
1298  } \
1299  } \
1300  else \
1301  { \
1302  typename DecoratorType::Pointer newOutput = DecoratorType::New(); \
1303  newOutput->Set(_arg); \
1304  this->Set##name##Output(newOutput); \
1305  } \
1306  } \
1307  ITK_MACROEND_NOOP_STATEMENT
1308 
1309 
1311 #define itkGetDecoratedOutputMacro(name, type) \
1312  virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1313  { \
1314  itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1315  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1316  } \
1317  virtual const type & Get##name() const \
1318  { \
1319  itkDebugMacro("Getting output " #name); \
1320  using DecoratorType = SimpleDataObjectDecorator<type>; \
1321  const DecoratorType * output = \
1322  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1323  if (output == nullptr) \
1324  { \
1325  itkExceptionMacro(<< "output" #name " is not set"); \
1326  } \
1327  return output->Get(); \
1328  } \
1329  ITK_MACROEND_NOOP_STATEMENT
1330 
1331 
1332 
1342 #if defined(ITKV4_COMPATIBILITY)
1343 # define ITK_ITERATOR_VIRTUAL virtual
1344 # define ITK_ITERATOR_OVERRIDE override
1345 # define ITK_ITERATOR_FINAL
1346 #elif !defined(ITK_LEGACY_REMOVE)
1347 # define ITK_ITERATOR_VIRTUAL virtual
1348 # define ITK_ITERATOR_OVERRIDE override
1349 # define ITK_ITERATOR_FINAL final
1350 #else
1351 # define ITK_ITERATOR_VIRTUAL
1352 # define ITK_ITERATOR_OVERRIDE
1353 # define ITK_ITERATOR_FINAL
1354 #endif
1355 
1356 #if defined(ITKV4_COMPATIBILITY)
1357 // A macro for methods which are const in ITKv5, but not in ITKv4
1358 # define ITKv5_CONST
1359 #else
1360 // A macro for methods which are const in ITKv5, but not in ITKv4
1361 # define ITKv5_CONST const
1362 #endif
1363 
1364 #define itkExceptionObject_h
1365 #include "itkExceptionObject.h"
1366 #undef itkExceptionObject_h
1367 
1375 template <typename TTarget, typename TSource>
1376 TTarget
1377 itkDynamicCastInDebugMode(TSource x)
1378 {
1379 #ifndef NDEBUG
1380  if (x == nullptr)
1381  {
1382  return nullptr;
1383  }
1384  TTarget rval = dynamic_cast<TTarget>(x);
1385  if (rval == nullptr)
1386  {
1387  itkGenericExceptionMacro(<< "Failed dynamic cast to " << typeid(TTarget).name()
1388  << " object type = " << x->GetNameOfClass());
1389  }
1390  return rval;
1391 #else
1392  return static_cast<TTarget>(x);
1393 #endif
1394 }
1396 
1397 // Defines which used to be in itk_compiler_detection.h
1398 #define ITK_ALIGNAS(X) alignas(X)
1399 #define ITK_ALIGNOF(X) alignof(X)
1400 #define ITK_DEPRECATED [[deprecated]]
1401 #define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1402 #define ITK_CONSTEXPR constexpr
1403 #define ITK_DELETED_FUNCTION = delete
1404 #define ITK_EXTERN_TEMPLATE extern
1405 #define ITK_FINAL final
1406 #define ITK_NOEXCEPT noexcept
1407 #define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1408 #define ITK_NULLPTR nullptr
1409 #define ITK_OVERRIDE override
1410 #define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1411 #define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1412 #define ITK_THREAD_LOCAL thread_local
1413 
1414 #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