ITK  5.2.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 
72 // clang-format off
73 # define ITK_NOOP_STATEMENT do {} while(0)
74 // clang-format on
76 
77 // Define ITK_PRAGMA macro.
78 //
79 // It sets "#pragma" preprocessor directives without expecting the arguments
80 // to be quoted.
81 #define ITK_PRAGMA(x) _Pragma(#x)
82 
83 // The clang compiler has many useful non-default compiler warnings
84 // that tend to have a high false positive rate.
85 // The following set of defines allows us to suppress false positives
86 // and still track down suspicious code
87 #if defined(__clang__) && defined(__has_warning)
88 # define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
89 # define CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
90 # if __has_warning("-Wfloat-equal")
91 # define CLANG_SUPPRESS_Wfloat_equal ITK_PRAGMA(clang diagnostic ignored "-Wfloat-equal")
92 # else
93 # define CLANG_SUPPRESS_Wfloat_equal
94 # endif
95 # if __has_warning("-Wc++14-extensions")
96 # define CLANG_SUPPRESS_Wc__14_extensions ITK_PRAGMA(clang diagnostic ignored "-Wc++14-extensions")
97 # else
98 # define CLANG_SUPPRESS_Wc__14_extensions
99 # endif
100 #else
101 # define CLANG_PRAGMA_PUSH
102 # define CLANG_PRAGMA_POP
103 # define CLANG_SUPPRESS_Wfloat_equal
104 # define CLANG_SUPPRESS_Wc__14_extensions
105 #endif
106 
107 // Intel compiler convenience macros
108 #if defined(__INTEL_COMPILER)
109 # define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
110 # define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
111 # define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
112 #else
113 # define INTEL_PRAGMA_WARN_PUSH
114 # define INTEL_PRAGMA_WARN_POP
115 # define INTEL_SUPPRESS_warning_1292
116 #endif
117 
118 // Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
119 //
120 // This macro sets a pragma diagnostic
121 //
122 // Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
123 //
124 // These macros respectively push and pop the diagnostic context
125 //
126 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
127 # define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
128 # define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
129 # define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
130 #else
131 # define ITK_GCC_PRAGMA_DIAG(x)
132 # define ITK_GCC_PRAGMA_DIAG_PUSH()
133 # define ITK_GCC_PRAGMA_DIAG_POP()
134 #endif
135 
136 /*
137  * ITK only supports MSVC++ 14.0 and greater
138  * MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015 version 14.0)
139  * MSVC++ 14.1 _MSC_VER == 1910 (Visual Studio 2017 version 15.0)
140  * MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3)
141  * MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5)
142  * MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6)
143  * MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7)
144  * MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8)
145  * MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9)
146  * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
147  */
148 #if defined(_MSC_VER) && (_MSC_VER < 1900)
149 # error "Visual Studio < 2015 is not supported under ITKv5"
150 #endif
151 #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
152 # error "SUNPro C++ < 5.14.0 is not supported under ITKv5 and above"
153 #endif
154 #if defined(__CYGWIN__)
155 # error "The Cygwin compiler is not supported in ITKv4 and above"
156 #endif
157 #if defined(__BORLANDC__)
158 # error "The Borland C compiler is not supported in ITKv4 and above"
159 #endif
160 #if defined(__MWERKS__)
161 # error "The MetroWerks compiler is not supported in ITKv4 and above"
162 #endif
163 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && \
164  ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 8)))
165 # error "GCC < 4.8 is not supported under ITKv5"
166 #endif
167 #if defined(__sgi)
168 // This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
169 // TODO: At some future point, it may be necessary to
170 // define a minimum __sgi version that will work.
171 # error "The SGI compiler is not supported under ITKv4 and above"
172 #endif
173 #if defined(__APPLE__)
174 # if defined(__clang__) && (__cplusplus < 201103L)
175 # error "Apple LLVM < 5.0 (clang < 3.3) is not supported under ITKv5"
176 # endif
177 #elif defined(__clang__) && ((__clang_major__ < 3) || ((__clang_major__ == 3) && (__clang_minor__ < 3)))
178 # error "Clang < 3.3 is not supported under ITKv5"
179 #endif
180 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1504)
181 # error "Intel C++ < 15.0.4 is not supported under ITKv5"
182 #endif
183 
184 // Setup symbol exports
185 #if defined(_WIN32) || defined(WIN32)
186 # define ITK_ABI_IMPORT __declspec(dllimport)
187 # define ITK_ABI_EXPORT __declspec(dllexport)
188 # define ITK_ABI_HIDDEN
189 #else
190 # if __GNUC__ >= 4
191 # define ITK_ABI_IMPORT __attribute__((visibility("default")))
192 # define ITK_ABI_EXPORT __attribute__((visibility("default")))
193 # define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
194 # else
195 # define ITK_ABI_IMPORT
196 # define ITK_ABI_EXPORT
197 # define ITK_ABI_HIDDEN
198 # endif
199 #endif
200 
201 // Setup symbol exports
202 #ifndef ITK_TEMPLATE_EXPORT
203 # ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
204 # define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
205 # else
206 # define ITK_TEMPLATE_EXPORT
207 # endif
208 #endif
209 
210 // Setup symbol exports
211 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
212 # define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
213 #else
214 # define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
215 #endif
216 
217 #ifndef ITK_FORWARD_EXPORT
218 // If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
219 # if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
220  defined(USE_COMPILER_HIDDEN_VISIBILITY)
221 # define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
222 # else
223 # define ITK_FORWARD_EXPORT
224 # endif
225 #endif
226 
227 
228 //-*-*-*
229 // The following deprecations should be removed in ITKV6 and later
230 // NOTE DEPRECATED should be ITK_NOEXCEPT
231 #define ITK_NOEXCEPT_OR_THROW error "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT"
232 // NOTE DEPRECATED! should be ITK_COMPILER_CXX_STATIC_ASSERT
233 #if !defined(ITK_LEGACY_REMOVE)
234 # define ITK_DELETE_FUNCTION = delete
235 #else
236 # define ITK_DELETE_FUNCTION error "Replace ITK_DELETE_FUNCTION with = delete"
237 #endif
238 //-*-*-*
239 
240 // DEPRECATED: These macros are left here for compatibility with remote modules.
241 // Once they have been removed from all known remote modules, this code should
242 // be removed.
243 #if defined(ITK_FUTURE_LEGACY_REMOVE)
244 # define ITK_CONSTEXPR_FUNC "Replace ITK_CONSTEXPR_FUNC with constexpr"
245 # define ITK_CONSTEXPR_VAR "Replace ITK_CONSTEXPR_VAR with constexpr"
246 
247 # define itkExposeEnumValue(name) static_cast<int>(name)
248 // Future remove# define itkExposeEnumValue(name) "Replace type of " # name " with proper enumeration instead of
249 // integer."
250 #else
251 # define ITK_CONSTEXPR_FUNC constexpr
252 # define ITK_CONSTEXPR_VAR constexpr
253 
255 # define itkExposeEnumValue(name) static_cast<int>(name)
256 #endif
257 
258 // Use "ITK_FALLTHROUGH;" to annotate deliberate fall-through in switches,
259 // use it analogously to "break;". The trailing semi-colon is required.
260 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
261 # if (__GNUC__ >= 7)
262 # define ITK_FALLTHROUGH __attribute__((fallthrough))
263 # endif
264 #elif defined(__has_warning)
265 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
266 # define ITK_FALLTHROUGH [[clang::fallthrough]]
267 # endif
268 #endif
269 
270 #ifndef ITK_FALLTHROUGH
271 # define ITK_FALLTHROUGH ((void)0)
272 #endif
273 
294 #define itkNewMacro(x) itkSimpleNewMacro(x) itkCreateAnotherMacro(x) itkCloneMacro(x)
295 
296 #define itkSimpleNewMacro(x) \
297  static Pointer New() \
298  { \
299  Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
300  if (smartPtr == nullptr) \
301  { \
302  smartPtr = new x; \
303  } \
304  smartPtr->UnRegister(); \
305  return smartPtr; \
306  }
307 
308 #define itkCreateAnotherMacro(x) \
309  ::itk::LightObject::Pointer CreateAnother() const override \
310  { \
311  ::itk::LightObject::Pointer smartPtr; \
312  smartPtr = x::New().GetPointer(); \
313  return smartPtr; \
314  }
315 
316 #define itkCloneMacro(x) \
317  Pointer Clone() const \
318  { \
319  Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
320  return rval; \
321  }
322 
335 #define itkFactorylessNewMacro(x) \
336  static Pointer New() \
337  { \
338  Pointer smartPtr; \
339  x * rawPtr = new x; \
340  smartPtr = rawPtr; \
341  rawPtr->UnRegister(); \
342  return smartPtr; \
343  } \
344  ::itk::LightObject::Pointer CreateAnother() const override \
345  { \
346  ::itk::LightObject::Pointer smartPtr; \
347  smartPtr = x::New().GetPointer(); \
348  return smartPtr; \
349  }
350 
351 
352 //
353 // A macro to disallow the copy constructor, copy assignment,
354 // move constructor, and move assignment functions.
355 // This should be used in the public: declarations for a class
356 //
357 // ITK's paradigm for smart pointer and pipeline consistency
358 // prohibits the use of copy/move construction and copy/move assignment
359 // functions.
360 //
361 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
362  TypeName(const TypeName &) = delete; \
363  TypeName & operator=(const TypeName &) = delete; \
364  TypeName(TypeName &&) = delete; \
365  TypeName & operator=(TypeName &&) = delete
366 
367 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
368 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
369 #endif
370 
373 #define itkTypeMacro(thisClass, superclass) \
374  const char * GetNameOfClass() const override { return #thisClass; }
375 
376 #define itkTypeMacroNoParent(thisClass) \
377  virtual const char * GetNameOfClass() const { return #thisClass; }
378 
379 namespace itk
380 {
387 extern ITKCommon_EXPORT void
388 OutputWindowDisplayText(const char *);
390 
391 extern ITKCommon_EXPORT void
392 OutputWindowDisplayErrorText(const char *);
393 
394 extern ITKCommon_EXPORT void
395 OutputWindowDisplayWarningText(const char *);
396 
397 extern ITKCommon_EXPORT void
398 OutputWindowDisplayGenericOutputText(const char *);
399 
400 extern ITKCommon_EXPORT void
401 OutputWindowDisplayDebugText(const char *);
402 } // end namespace itk
403 
404 // The itkDebugStatement is to be used to protect code that is only used in the itkDebugMacro
408 #if defined(NDEBUG)
409 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
410 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
411 #else
412 # define itkDebugMacro(x) \
413  do \
414  { \
415  if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
416  { \
417  std::ostringstream itkmsg; \
418  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
419  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
420  ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
421  } \
422  } while (0)
423 
424 
425 // The itkDebugStatement is to be used to protect code that is only
426 // used in the itkDebugMacro
427 # define itkDebugStatement(x) x
428 #endif
429 
433 #define itkWarningMacro(x) \
434  do \
435  { \
436  if (::itk::Object::GetGlobalWarningDisplay()) \
437  { \
438  std::ostringstream itkmsg; \
439  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
440  << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
441  ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
442  } \
443  } while (0)
444 
445 
446 #define itkWarningStatement(x) x
447 
448 #if defined(ITK_CPP_FUNCTION)
449 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
450 # define ITK_LOCATION __FUNCSIG__
451 # elif defined(__GNUC__)
452 # define ITK_LOCATION __PRETTY_FUNCTION__
453 # else
454 # define ITK_LOCATION __FUNCTION__
455 # endif
456 #else
457 # define ITK_LOCATION "unknown"
458 #endif
459 
460 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
461  namespace itk \
462  { \
463  class newexcp : public parentexcp \
464  { \
465  public: \
466  /* default message provides backward compatibility for a given exception type */ \
467  static constexpr const char * const default_exception_message = whatmessage; \
468  explicit newexcp(const char * file, \
469  unsigned int lineNumber = 0, \
470  const char * desc = "None", \
471  const char * loc = "Unknown") \
472  : parentexcp(std::string{ file }, lineNumber, std::string{ desc }, std::string{ loc }) \
473  {} \
474  explicit newexcp(std::string file, \
475  unsigned int lineNumber = 0, \
476  std::string desc = std::string{ "None" }, \
477  std::string loc = std::string{ "Unknown" }) \
478  : parentexcp(std::move(file), lineNumber, std::move(desc), std::move(loc)) \
479  {} \
480  itkTypeMacro(newexcp, parentexcp); \
481  }; \
482  }
483 
484 
485 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
486  { \
487  std::ostringstream message; \
488  message << "itk::ERROR: " x; \
489  throw ::itk::ExceptionType( \
490  std::string{ __FILE__ }, __LINE__, std::string{ message.str() }, std::string{ ITK_LOCATION }); \
491  }
492 
493 #define itkSpecializedExceptionMacro(ExceptionType) \
494  { \
495  itkSpecializedMessageExceptionMacro(ExceptionType, \
496  "itk::ERROR: " << ::itk::ExceptionType::default_exception_message) \
497  }
498 
502 #define itkExceptionMacro(x) \
503  { \
504  itkSpecializedMessageExceptionMacro(ExceptionObject, \
505  "itk::ERROR: " << this->GetNameOfClass() << "(" << this << "): " x); \
506  }
507 
508 
509 #define itkGenericExceptionMacro(x) \
510  { \
511  itkSpecializedMessageExceptionMacro(ExceptionObject, x); \
512  }
513 
514 #define itkGenericOutputMacro(x) \
515  { \
516  if (::itk::Object::GetGlobalWarningDisplay()) \
517  { \
518  std::ostringstream itkmsg; \
519  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
520  ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
521  } \
522  }
523 
524 //----------------------------------------------------------------------------
525 // Macros for simplifying the use of logging
526 //
527 #define itkLogMacro(x, y) \
528  { \
529  if (this->GetLogger()) \
530  { \
531  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
532  } \
533  }
534 
535 #define itkLogMacroStatic(obj, x, y) \
536  { \
537  if (obj->GetLogger()) \
538  { \
539  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
540  } \
541  }
542 
543 //----------------------------------------------------------------------------
544 // Setup legacy code policy.
545 //
546 // CMake options:
547 // - When ITK_LEGACY_REMOVE:BOOL=ON, legacy code is hidden, thus causing compiler errors for code that depends on it
548 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=ON, use
549 // of legacy code will not produce compiler warnings.
550 // - When ITK_LEGACY_REMOVE:BOOL=OFF, and ITK_LEGACY_SILENT:BOOL=OFF, use
551 // of legacy code will produce compiler warnings
552 //
553 // ITK_LEGACY_SILENT silently use legacy code. The default is to warn about legacy code use.
554 //
555 // Source files that test the legacy code may define ITK_LEGACY_TEST
556 // like this:
557 //
558 // #define ITK_LEGACY_TEST
559 // #include "itkClassWithDeprecatedMethod.h"
560 //
561 // in order to silence the warnings for calling deprecated methods.
562 // No other source files in ITK should call the methods since they are
563 // provided only for compatibility with older user code.
564 
565 // Define itkLegacyMacro to mark legacy methods where they are
566 // declared in their class. Example usage:
567 //
568 // // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
569 // itkLegacyMacro(void MyMethod());
570 //
571 // See below for what to do for the method definition.
572 #if defined(ITK_LEGACY_REMOVE)
573 # define itkLegacyMacro(method) /* no ';' */
574 #else
575 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
576 // Provide legacy methods with no warnings.
577 # define itkLegacyMacro(method) method
578 # else
579 // Setup compile-time warnings for uses of deprecated methods if
580 // possible on this compiler.
581 # if defined(__GNUC__) && !defined(__INTEL_COMPILER)
582 # define itkLegacyMacro(method) method __attribute__((deprecated))
583 # elif defined(_MSC_VER)
584 # define itkLegacyMacro(method) __declspec(deprecated) method
585 # else
586 # define itkLegacyMacro(method) method
587 # endif
588 # endif
589 #endif
590 
591 // Macros to create runtime deprecation warning messages in function
592 // bodies. Example usage:
593 //
594 // #if !defined( ITK_LEGACY_REMOVE )
595 // void itkMyClass::MyOldMethod()
596 // {
597 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
598 // }
599 //
600 // void itkMyClass::MyMethod()
601 // {
602 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
603 // itkMyClass::MyOtherMethod);
604 // }
605 // #endif
606 //
607 // NOTE: These 4 macros itkLegacyBodyMacro, itkLegacyReplaceBodyMacro,
608 // itkGenericLegacyBodyMacro, and itkGenericLegacyReplaceBodyMacro
609 // are purposefully not defined when ITK_LEGACY_REMOVE is on,
610 // because these macros are only relevant inside code segments
611 // that are conditionally compiled only when ITK_LEGACY_REMOVE
612 // is off.
613 #if defined(ITK_LEGACY_SILENT)
614 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
615 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
616 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
617 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
618 #else
619 # define itkLegacyBodyMacro(method, version) \
620  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
621 # define itkLegacyReplaceBodyMacro(method, version, replace) \
622  itkWarningMacro(#method " was deprecated for ITK " #version \
623  " and will be removed in a future version. Use " #replace " instead.")
624 # define itkGenericLegacyBodyMacro(method, version) \
625  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
626 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
627  itkGenericOutputMacro(#method " was deprecated for ITK " #version \
628  " and will be removed in a future version. Use " #replace " instead.")
629 #endif
630 
631 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
632 // the cache lines. By aligning multi-threaded structures with the
633 // cache lines, false shared can be reduced, and performance
634 // increased.
635 #define ITK_CACHE_LINE_ALIGNMENT 64
636 
637 //
638 // itkPadStruct will add padding to a structure to ensure a minimum size
639 // for ensuring that adjacent structures do not share CACHE lines.
640 // Each struct will take up some multiple of cacheline sizes.
641 // This is particularly useful for arrays of thread private variables.
642 //
643 #define itkPadStruct(mincachesize, oldtype, newtype) \
644  struct newtype : public oldtype \
645  { \
646  char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
647  };
648 
649 //
650 // itkAlignedTypedef is a macro which creates a new type to make a
651 // data structure aligned.
652 //
653 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
654 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
655 #elif defined(_MSC_VER)
656 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
657 #else
658 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
659 #endif
660 
661 #if defined(ITK_FUTURE_LEGACY_REMOVE)
662 //=============================================================================
663 /*
664 NOTE: DEPRECATED - This macro is not longer needed to support modern
665 compilers.
666 
667  Define a common way of declaring a templated function as a friend inside a class.
668  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
669 
670  The following templated function
671 
672  template <T>
673  T add(const T & a, const T & b);
674 
675  is declared as friend with
676 
677  class A
678  {
679  public:
680  friend Self add<>( const Self & a, const Self & b );
681  }
682 
683 */
684 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
685 #else // LEGACY_REMOVE
686 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
687 #endif
688 
689 //--------------------------------------------------------------------------------
690 // Helper macros for Template Meta-Programming techniques of for-loops
691 // unrolling
692 //--------------------------------------------------------------------------------
693 
694 //--------------------------------------------------------------------------------
695 // Macro that generates an unrolled for loop for assigning elements of one array
696 // to elements of another array The array are assumed to be of same length
697 // (dimension), and this is also assumed to be the value of NumberOfIterations.
698 // No verification of size is performed. Casting is performed as part of the
699 // assignment, by using the DestinationElementType as the casting type.
700 // Source and destination array types must have defined operator[] in their
701 // API.
702 #define itkForLoopAssignmentMacro( \
703  DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
704  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
705  { \
706  DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
707  }
708 
709 //--------------------------------------------------------------------------------
710 // Macro that generates an unrolled for loop for rounding and assigning
711 // elements of one array to elements of another array The array are assumed to
712 // be of same length (dimension), and this is also assumed to be the value of
713 // NumberOfIterations. No verification of size is performed. Casting is
714 // performed as part of the assignment, by using the DestinationElementType as
715 // the casting type.
716 // Source and destination array types must have defined operator[] in their
717 // API.
718 #define itkForLoopRoundingAndAssignmentMacro( \
719  DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
720  for (unsigned int i = 0; i < NumberOfIterations; ++i) \
721  { \
722  DestinationArray[i] = itk::Math::Round<DestinationElementType>(SourceArray[i]); \
723  }
724 
725 // end of Template Meta Programming helper macros
726 
727 #ifndef NDEBUG
728 
729 # ifdef _POSIX_SOURCE
730 # define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
731 # else
732 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
733 # endif
734 
735 #else
736 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
737 #endif
738 
739 #define itkAssertOrThrowMacro(test, message) \
740  if (!(test)) \
741  { \
742  std::ostringstream msgstr; \
743  msgstr << message; \
744  itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
745  }
746 
747 #ifndef NDEBUG
748 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
749 #else
750 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
751 #endif
752 
753 
754 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
755 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
756 // !! The ITK Get/Set Macros for various types !!
757 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
758 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
773 #define itkStaticConstMacro(name, type, value) static constexpr type name = value
774 
775 #define itkGetStaticConstMacro(name) (Self::name)
776 
778 #define itkSetInputMacro(name, type) \
779  virtual void Set##name(const type * _arg) \
780  { \
781  itkDebugMacro("setting input " #name " to " << _arg); \
782  if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
783  { \
784  this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
785  this->Modified(); \
786  } \
787  }
788 
789 
791 #define itkGetInputMacro(name, type) \
792  virtual const type * Get##name() const \
793  { \
794  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
795  return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
796  }
797 
798 
799 // clang-format off
801 #define itkSetDecoratedInputMacro(name, type) \
802  virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
803  { \
804  itkDebugMacro("setting input " #name " to " << _arg); \
805  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
806  { \
807  this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
808  this->Modified(); \
809  } \
810  } \
811  virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
812  virtual void Set##name(const type & _arg) \
813  { \
814  using DecoratorType = SimpleDataObjectDecorator<type>; \
815  itkDebugMacro("setting input " #name " to " << _arg); \
816  const DecoratorType * oldInput = \
817  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
818  CLANG_PRAGMA_PUSH \
819  CLANG_SUPPRESS_Wfloat_equal \
820  if (oldInput && oldInput->Get() == _arg) \
821  { \
822  return; \
823  } \
824  CLANG_PRAGMA_POP \
825  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
826  newInput->Set(_arg); \
827  this->Set##name##Input(newInput); \
828  }
829 // clang-format on
831 
833 #define itkGetDecoratedInputMacro(name, type) \
834  virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
835  { \
836  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
837  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
838  } \
839  virtual const type & Get##name() const \
840  { \
841  itkDebugMacro("Getting input " #name); \
842  using DecoratorType = SimpleDataObjectDecorator<type>; \
843  const DecoratorType * input = \
844  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
845  if (input == nullptr) \
846  { \
847  itkExceptionMacro(<< "input" #name " is not set"); \
848  } \
849  return input->Get(); \
850  }
851 
852 
855 #define itkSetGetDecoratedInputMacro(name, type) \
856  itkSetDecoratedInputMacro(name, type) itkGetDecoratedInputMacro(name, type)
857 
862 #define itkSetDecoratedObjectInputMacro(name, type) \
863  virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
864  { \
865  itkDebugMacro("setting input " #name " to " << _arg); \
866  if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
867  { \
868  this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
869  this->Modified(); \
870  } \
871  } \
872  virtual void Set##name(const type * _arg) \
873  { \
874  using DecoratorType = DataObjectDecorator<type>; \
875  itkDebugMacro("setting input " #name " to " << _arg); \
876  const DecoratorType * oldInput = \
877  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
878  if (oldInput && oldInput->Get() == _arg) \
879  { \
880  return; \
881  } \
882  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
883  newInput->Set(_arg); \
884  this->Set##name##Input(newInput); \
885  }
886 
887 
892 #define itkGetDecoratedObjectInputMacro(name, type) \
893  virtual const DataObjectDecorator<type> * Get##name##Input() const \
894  { \
895  itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
896  return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
897  } \
898  virtual const type * Get##name() const \
899  { \
900  itkDebugMacro("Getting input " #name); \
901  using DecoratorType = DataObjectDecorator<type>; \
902  const DecoratorType * input = \
903  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
904  if (input == nullptr) \
905  { \
906  return nullptr; \
907  } \
908  return input->Get(); \
909  }
910 
911 
914 #define itkSetGetDecoratedObjectInputMacro(name, type) \
915  itkSetDecoratedObjectInputMacro(name, type) itkGetDecoratedObjectInputMacro(name, type)
916 
918 // clang-format off
919 #define itkSetMacro(name, type) \
920  virtual void Set##name(const type _arg) \
921  { \
922  itkDebugMacro("setting " #name " to " << _arg); \
923  CLANG_PRAGMA_PUSH \
924  CLANG_SUPPRESS_Wfloat_equal \
925  if (this->m_##name != _arg) \
926  { \
927  this->m_##name = _arg; \
928  this->Modified(); \
929  } \
930  CLANG_PRAGMA_POP \
931  }
932 // clang-format on
933 
935 #define itkGetMacro(name, type) \
936  virtual type Get##name() { return this->m_##name; }
937 
938 
942 #define itkGetConstMacro(name, type) \
943  virtual type Get##name() const { return this->m_##name; }
944 
945 
950 #define itkGetConstReferenceMacro(name, type) \
951  virtual const type & Get##name() const { return this->m_##name; }
952 
953 
958 #define itkSetEnumMacro(name, type) \
959  virtual void Set##name(const type _arg) \
960  { \
961  itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
962  if (this->m_##name != _arg) \
963  { \
964  this->m_##name = _arg; \
965  this->Modified(); \
966  } \
967  }
968 
969 
974 #define itkGetEnumMacro(name, type) \
975  virtual type Get##name() const { return this->m_##name; }
976 
977 
981 #define itkSetStringMacro(name) \
982  virtual void Set##name(const char * _arg) \
983  { \
984  if (_arg && (_arg == this->m_##name)) \
985  { \
986  return; \
987  } \
988  if (_arg) \
989  { \
990  this->m_##name = _arg; \
991  } \
992  else \
993  { \
994  this->m_##name = ""; \
995  } \
996  this->Modified(); \
997  } \
998  virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); }
999 
1000 
1001 
1005 #define itkGetStringMacro(name) \
1006  virtual const char * Get##name() const { return this->m_##name.c_str(); }
1007 
1008 // clang-format off
1012 #define itkSetClampMacro(name, type, min, max) \
1013  virtual void Set##name(type _arg) \
1014  { \
1015  const type temp_extrema = (_arg < min ? min : (_arg > max ? max : _arg)); \
1016  itkDebugMacro("setting " << #name " to " << _arg); \
1017  CLANG_PRAGMA_PUSH \
1018  CLANG_SUPPRESS_Wfloat_equal \
1019  if (this->m_##name != temp_extrema) \
1020  { \
1021  this->m_##name = temp_extrema; \
1022  this->Modified(); \
1023  } \
1024  CLANG_PRAGMA_POP \
1025  }
1026 // clang-format on
1028 
1029 // clang-format off
1030 // NOTE: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
1035 #define itkSetObjectMacro(name, type) \
1036  virtual void Set##name(type * _arg) \
1037  { \
1038  itkDebugMacro("setting " << #name " to " << _arg); \
1039  CLANG_PRAGMA_PUSH \
1040  CLANG_SUPPRESS_Wfloat_equal \
1041  if (this->m_##name != _arg) \
1042  { \
1043  this->m_##name = _arg; \
1044  this->Modified(); \
1045  } \
1046  CLANG_PRAGMA_POP \
1047  }
1048 // clang-format on
1050 
1059 // NOTE: A class can use either itkGetModifiableObjectMacro
1060 // or itkGetObjectMacro, but not both.
1061 // A class can use either itkGetModifiableObjectMacro
1062 // or itkGetConstObjectMacro, but not both.
1063 // If the desired behavior is to only provide const
1064 // access to the itkObject ivar, then use itkGetConstObjectMacro,
1065 // else use itkGetModifiableObjectMacro for read/write access to
1066 // the ivar.
1067 // It is permissible to use both itkGetObjectMacro and itkGetConstObjectMacro
1068 // for backwards compatibility.
1069 // If the ITK_LEGACY_REMOVE=FALSE, then it is
1070 // permissible to use itkGetObjectMacro which
1071 // defines both signatures itk::GetXXX() and
1072 // itk::GetModifiableXXX()
1073 
1076 #define itkGetConstObjectMacro(name, type) \
1077  virtual const type * Get##name() const { return this->m_##name.GetPointer(); }
1078 
1079 
1080 #if defined(ITK_FUTURE_LEGACY_REMOVE)
1081 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1082 // flag. For now, this very advanced feature is only available
1083 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1084 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1085 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1086 # define itkGetObjectMacro(name, type) \
1087  virtual type * Get##name() \
1088  { \
1089  purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1090  }
1091 
1092 # define itkGetModifiableObjectMacro(name, type) \
1093  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1094  itkGetConstObjectMacro(name, type)
1095 
1096 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1097 
1099 # define itkGetObjectMacro(name, type) \
1100  virtual type * Get##name() { return this->m_##name.GetPointer(); }
1101 # define itkGetModifiableObjectMacro(name, type) \
1102  virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1103  itkGetConstObjectMacro(name, type) itkGetObjectMacro(name, type)
1104 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1105 
1106 
1107 // For backwards compatibility define ITK_EXPORT to nothing
1108 #define ITK_EXPORT
1109 
1110 
1113 #define itkGetConstReferenceObjectMacro(name, type) \
1114  virtual const typename type::Pointer & Get##name() const { return this->m_##name; }
1115 
1120 #define itkSetConstObjectMacro(name, type) \
1121  virtual void Set##name(const type * _arg) \
1122  { \
1123  itkDebugMacro("setting " << #name " to " << _arg); \
1124  if (this->m_##name != _arg) \
1125  { \
1126  this->m_##name = _arg; \
1127  this->Modified(); \
1128  } \
1129  }
1130 
1131 
1134 #define itkBooleanMacro(name) \
1135  virtual void name##On() { this->Set##name(true); } \
1136  virtual void name##Off() { this->Set##name(false); }
1137 
1138 
1139 // clang-format off
1143 #define itkSetVectorMacro(name, type, count) \
1144  virtual void Set##name(type data[]) \
1145  { \
1146  unsigned int i; \
1147  for (i = 0; i < count; i++) \
1148  { \
1149  CLANG_PRAGMA_PUSH \
1150  CLANG_SUPPRESS_Wfloat_equal \
1151  if (data[i] != this->m_##name[i]) \
1152  { \
1153  break; \
1154  } \
1155  CLANG_PRAGMA_POP \
1156  } \
1157  if (i < count) \
1158  { \
1159  this->Modified(); \
1160  for (i = 0; i < count; i++) \
1161  { \
1162  this->m_##name[i] = data[i]; \
1163  } \
1164  } \
1165  }
1166 // clang-format on
1168 
1171 #define itkGetVectorMacro(name, type, count) \
1172  virtual type * Get##name() const { return this->m_##name; }
1173 
1178 #define itkGPUKernelClassMacro(kernel) \
1179  kernel \
1180  { \
1181  public: \
1182  static const char * GetOpenCLSource(); \
1183  \
1184  private: \
1185  kernel(); \
1186  virtual ~kernel(); \
1187  kernel(const kernel &); \
1188  void operator=(const kernel &); \
1189  };
1190 
1191 
1192 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1193  static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); }
1194 
1195 // A useful macro in the PrintSelf method for printing member variables
1196 // which are pointers to object based on the LightObject class.
1197 #define itkPrintSelfObjectMacro(name) \
1198  if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1199  { \
1200  os << indent << #name << ": (null)" << std::endl; \
1201  } \
1202  else \
1203  { \
1204  os << indent << #name << ": " << std::endl; \
1205  this->m_##name->Print(os, indent.GetNextIndent()); \
1206  }
1207 
1208 
1210 #define itkSetDecoratedOutputMacro(name, type) \
1211  virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1212  { \
1213  itkDebugMacro("setting output " #name " to " << _arg); \
1214  if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1215  { \
1216  this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1217  this->Modified(); \
1218  } \
1219  } \
1220  virtual void Set##name(const type & _arg) \
1221  { \
1222  using DecoratorType = SimpleDataObjectDecorator<type>; \
1223  itkDebugMacro("setting output " #name " to " << _arg); \
1224  DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1225  if (output) \
1226  { \
1227  if (output->Get() == _arg) \
1228  { \
1229  return; \
1230  } \
1231  else \
1232  { \
1233  output->Set(_arg); \
1234  } \
1235  } \
1236  else \
1237  { \
1238  typename DecoratorType::Pointer newOutput = DecoratorType::New(); \
1239  newOutput->Set(_arg); \
1240  this->Set##name##Output(newOutput); \
1241  } \
1242  }
1243 
1244 
1246 #define itkGetDecoratedOutputMacro(name, type) \
1247  virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1248  { \
1249  itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1250  return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1251  } \
1252  virtual const type & Get##name() const \
1253  { \
1254  itkDebugMacro("Getting output " #name); \
1255  using DecoratorType = SimpleDataObjectDecorator<type>; \
1256  const DecoratorType * output = \
1257  itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1258  if (output == nullptr) \
1259  { \
1260  itkExceptionMacro(<< "output" #name " is not set"); \
1261  } \
1262  return output->Get(); \
1263  }
1264 
1265 
1266 
1276 #if defined(ITKV4_COMPATIBILITY)
1277 # define ITK_ITERATOR_VIRTUAL virtual
1278 # define ITK_ITERATOR_OVERRIDE override
1279 # define ITK_ITERATOR_FINAL
1280 #elif !defined(ITK_LEGACY_REMOVE)
1281 # define ITK_ITERATOR_VIRTUAL virtual
1282 # define ITK_ITERATOR_OVERRIDE override
1283 # define ITK_ITERATOR_FINAL final
1284 #else
1285 # define ITK_ITERATOR_VIRTUAL
1286 # define ITK_ITERATOR_OVERRIDE
1287 # define ITK_ITERATOR_FINAL
1288 #endif
1289 
1290 #if defined(ITKV4_COMPATIBILITY)
1291 // A macro for methods which are const in ITKv5, but not in ITKv4
1292 # define ITKv5_CONST
1293 #else
1294 // A macro for methods which are const in ITKv5, but not in ITKv4
1295 # define ITKv5_CONST const
1296 #endif
1297 
1298 #define itkExceptionObject_h
1299 #include "itkExceptionObject.h"
1300 #undef itkExceptionObject_h
1301 
itkExceptionObject.h
itkWin32Header.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24