ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkMacro.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 
69 // Define ITK_PRAGMA macro.
70 //
71 // It sets "#pragma" preprocessor directives without expecting the arguments
72 // to be quoted.
73 #define ITK_PRAGMA(x) _Pragma (#x)
74 
75 // The clang compiler has many useful non-default compiler warnings
76 // that tend to have a high false positive rate.
77 // The following set of defines allows us to suppress false positives
78 // and still track down suspicious code
79 #if defined(__clang__) && defined(__has_warning)
80 #define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
81 #define CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
82 #if __has_warning("-Wfloat-equal")
83 #define CLANG_SUPPRESS_Wfloat_equal ITK_PRAGMA( clang diagnostic ignored "-Wfloat-equal" )
84 #else
85 #define CLANG_SUPPRESS_Wfloat_equal
86 #endif
87 #if __has_warning( "-Wc++14-extensions" )
88 #define CLANG_SUPPRESS_Wc__14_extensions ITK_PRAGMA( clang diagnostic ignored "-Wc++14-extensions" )
89 #else
90 #define CLANG_SUPPRESS_Wc__14_extensions
91 #endif
92 #else
93 #define CLANG_PRAGMA_PUSH
94 #define CLANG_PRAGMA_POP
95 #define CLANG_SUPPRESS_Wfloat_equal
96 #define CLANG_SUPPRESS_Wc__14_extensions
97 #endif
98 
99 // Intel compiler convenience macros
100 #if defined(__INTEL_COMPILER)
101 #define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
102 #define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
103 #define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
104 #else
105 #define INTEL_PRAGMA_WARN_PUSH
106 #define INTEL_PRAGMA_WARN_POP
107 #define INTEL_SUPPRESS_warning_1292
108 #endif
109 
110 // Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
111 //
112 // This macros sets a pragma diagnostic if it supported by the version
113 // of GCC being used otherwise it is a no-op.
114 //
115 // GCC diagnostics pragma supported only with GCC >= 4.2
116 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER )
117 # if ( __GNUC__ > 4 ) || (( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 2 ))
118 # define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
119 # else
120 # define ITK_GCC_PRAGMA_DIAG(x)
121 # endif
122 #else
123 # define ITK_GCC_PRAGMA_DIAG(x)
124 #endif
125 
126 // Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
127 //
128 // These macros respectively push and pop the diagnostic context
129 // if it is supported by the version of GCC being used
130 // otherwise it is a no-op.
131 //
132 // GCC push/pop diagnostics pragma are supported only with GCC >= 4.6
133 //
134 // Define macro ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP if it is supported.
135 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER )
136 # if ( __GNUC__ > 4 ) || (( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 6 ))
137 # define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
138 # define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
139 # define ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
140 # else
141 # define ITK_GCC_PRAGMA_DIAG_PUSH()
142 # define ITK_GCC_PRAGMA_DIAG_POP()
143 # endif
144 #else
145 # define ITK_GCC_PRAGMA_DIAG_PUSH()
146 # define ITK_GCC_PRAGMA_DIAG_POP()
147 #endif
148 
149 /*
150  * ITK only supports MSVC++ 7.1 and greater
151  * MSVC++ 11.0 _MSC_VER = 1700
152  * MSVC++ 10.0 _MSC_VER = 1600
153  * MSVC++ 9.0 _MSC_VER = 1500
154  * MSVC++ 8.0 _MSC_VER = 1400
155  * MSVC++ 7.1 _MSC_VER = 1310
156  * MSVC++ 7.0 _MSC_VER = 1300
157  * MSVC++ 6.0 _MSC_VER = 1200
158  * MSVC++ 5.0 _MSC_VER = 1100
159 */
160 #if defined( _MSC_VER ) && ( _MSC_VER < 1310 )
161 //#error "_MSC_VER < 1310 (MSVC++ 7.1) not supported under ITKv4"
162 #endif
163 #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC < 0x590 )
164 #error "__SUNPRO_CC < 0x590 not supported under ITKv4"
165 #endif
166 #if defined( __CYGWIN__ )
167 #error "The Cygwin compiler is not supported in ITKv4 and above"
168 #endif
169 #if defined( __BORLANDC__ )
170 #error "The Borland C compiler is not supported in ITKv4 and above"
171 #endif
172 #if defined( __MWERKS__ )
173 #error "The MetroWerks compiler is not supported in ITKv4 and above"
174 #endif
175 #if defined( __GNUC__ ) && ( __GNUC__ < 3 )
176 #error "The __GNUC__ version 2.95 compiler is not supprted under ITKv4 and above"
177 #if defined( __sgi )
178 //This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
179 //TODO: At some future point, it may be necessary to
180 //define a minimum __sgi version that will work.
181 #error "The __sgi compiler is not supprted under ITKv4 and above"
182 #endif
183 #endif
184 
185 // Setup symbol exports
186 #if defined( _WIN32 ) || defined ( WIN32 )
187  #define ITK_ABI_IMPORT __declspec(dllimport)
188  #define ITK_ABI_EXPORT __declspec(dllexport)
189  #define ITK_ABI_HIDDEN
190 #else
191  #if __GNUC__ >= 4
192  #define ITK_ABI_IMPORT __attribute__ ((visibility ("default")))
193  #define ITK_ABI_EXPORT __attribute__ ((visibility ("default")))
194  #define ITK_ABI_HIDDEN __attribute__ ((visibility ("hidden")))
195  #else
196  #define ITK_ABI_IMPORT
197  #define ITK_ABI_EXPORT
198  #define ITK_ABI_HIDDEN
199  #endif
200 #endif
201 
202 // Setup symbol exports
203 #ifndef ITK_TEMPLATE_EXPORT
204  #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
205  #define ITK_TEMPLATE_EXPORT __attribute__ ((visibility ("default")))
206  #else
207  #define ITK_TEMPLATE_EXPORT
208  #endif
209 #endif
210 
211 // Setup symbol exports
212 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
213  #define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__ ((visibility ("default")))
214 #else
215  #define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName ## _EXPORT
216 #endif
217 
218 #ifndef ITK_FORWARD_EXPORT
219  // If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
220  #if defined(__APPLE__)\
221  && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT)\
222  && defined(ITK_BUILD_SHARED_LIBS)\
223  && defined(USE_COMPILER_HIDDEN_VISIBILITY)
224  #define ITK_FORWARD_EXPORT __attribute__ ((visibility ("default")))
225  #else
226  #define ITK_FORWARD_EXPORT
227  #endif
228 #endif
229 
230 
231 //-*-*-*
232 //The following deprecations should be removed in ITKV6 and later
233 //NOTE DEPRECATED should be ITK_NOEXCEPT
234 #define ITK_NOEXCEPT_OR_THROW error "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT"
235 //NOTE DEPRECATED! should be ITK_COMPILER_CXX_STATIC_ASSERT
236 #if !defined( ITK_LEGACY_REMOVE )
237 #define ITK_DELETE_FUNCTION = delete
238 #else
239 #define ITK_DELETE_FUNCTION error "Replace ITK_DELETE_FUNCTION with = delete"
240 #endif
241 //-*-*-*
242 
243 // DEPRECATED: These macros are left here for compatibility with remote modules.
244 // Once they have been removed from all known remote modules, this code should
245 // be removed.
246 #if defined ( ITK_FUTURE_LEGACY_REMOVE )
247  #define ITK_CONSTEXPR_FUNC "Replace ITK_CONSTEXPR_FUNC with constexpr"
248  #define ITK_CONSTEXPR_VAR "Replace ITK_CONSTEXPR_VAR with constexpr"
249 #else
250  #define ITK_CONSTEXPR_FUNC constexpr
251  #define ITK_CONSTEXPR_VAR constexpr
252 #endif
253 
254 // Use "ITK_FALLTHROUGH;" to annotate deliberate fall-through in switches,
255 // use it analogously to "break;". The trailing semi-colon is required.
256 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER )
257 # if ( __GNUC__ >= 7 )
258 # define ITK_FALLTHROUGH __attribute__((fallthrough))
259 # endif
260 #elif defined(__has_warning)
261 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
262 # define ITK_FALLTHROUGH [[clang::fallthrough]]
263 # endif
264 #endif
265 
266 #ifndef ITK_FALLTHROUGH
267 # define ITK_FALLTHROUGH ((void)0)
268 #endif
269 
290 #define itkNewMacro(x) \
291  itkSimpleNewMacro(x) \
292  itkCreateAnotherMacro(x) \
293  itkCloneMacro(x)
294 
295 #define itkSimpleNewMacro(x) \
296  static Pointer New() \
297  { \
298  Pointer smartPtr = ::itk::ObjectFactory< x >::Create(); \
299  if ( smartPtr == nullptr ) \
300  { \
301  smartPtr = new x; \
302  } \
303  smartPtr->UnRegister(); \
304  return smartPtr; \
305  }
306 
307 #define itkCreateAnotherMacro(x) \
308  ::itk::LightObject::Pointer CreateAnother() const override \
309  { \
310  ::itk::LightObject::Pointer smartPtr; \
311  smartPtr = x::New().GetPointer(); \
312  return smartPtr; \
313  }
314 
315 #define itkCloneMacro(x) \
316  Pointer Clone() const \
317  { \
318  Pointer rval = \
319  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_ASSIGN(TypeName) \
362  TypeName(const TypeName&) = delete; \
363  TypeName& operator=(const TypeName&) = delete; \
364  TypeName(TypeName&&) = delete; \
365  TypeName& operator=(TypeName&&) = delete
366 
369 #define itkTypeMacro(thisClass, superclass) \
370  const char *GetNameOfClass() const override \
371  { \
372  return #thisClass; \
373  }
374 
375 #define itkTypeMacroNoParent(thisClass) \
376  virtual const char *GetNameOfClass() const \
377  { \
378  return #thisClass; \
379  }
380 
381 namespace itk
382 {
389 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char *);
391 
392 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char *);
393 
394 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char *);
395 
396 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char *);
397 
398 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char *);
399 } // end namespace itk
400 
404 #if defined( NDEBUG )
405 #define itkDebugMacro(x)
406 #define itkDebugStatement(x)
407 #else
408 #define itkDebugMacro(x) \
409  { \
410  if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
411  { \
412  std::ostringstream itkmsg; \
413  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
414  << this->GetNameOfClass() << " (" << this << "): " x \
415  << "\n\n"; \
416  ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() ); \
417  } \
418  }
419 
420 
421 //The itkDebugStatement is to be used to protect code that is only
422 //used in the itkDebugMacro
423 #define itkDebugStatement(x) x
424 #endif
425 
429 #define itkWarningMacro(x) \
430  { \
431  if ( ::itk::Object::GetGlobalWarningDisplay() ) \
432  { \
433  std::ostringstream itkmsg; \
434  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
435  << this->GetNameOfClass() << " (" << this << "): " x \
436  << "\n\n"; \
437  ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() ); \
438  } \
439  }
440 
441 
442 //The itkDebugStatement is to be used ot protect code that is only
443 //used in the itkDebugMacro
444 #define itkWarningStatement(x) x
445 
446 #if defined( ITK_CPP_FUNCTION )
447  #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( ITK_WRAPPING_PARSER )
448  #define ITK_LOCATION __FUNCSIG__
449  #elif defined( __GNUC__ )
450  #define ITK_LOCATION __PRETTY_FUNCTION__
451  #else
452  #define ITK_LOCATION __FUNCTION__
453  #endif
454 #else
455  #define ITK_LOCATION "unknown"
456 #endif
457 
461 #define itkExceptionMacro(x) \
462  { \
463  std::ostringstream message; \
464  message << "itk::ERROR: " << this->GetNameOfClass() \
465  << "(" << this << "): " x; \
466  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
467  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
468  }
469 
470 
471 #define itkGenericExceptionMacro(x) \
472  { \
473  std::ostringstream message; \
474  message << "itk::ERROR: " x; \
475  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
476  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
477  }
478 
479 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage) \
480 namespace itk { \
481 class newexcp : public parentexcp \
482 { \
483 public: \
484 newexcp( const char *file, unsigned int lineNumber ) : \
485 parentexcp( file, lineNumber ) \
486 { \
487  this->SetDescription( whatmessage ); \
488 } \
489 newexcp( const std::string & file, unsigned int lineNumber ) : \
490 parentexcp( file, lineNumber ) \
491 { \
492  this->SetDescription( whatmessage ); \
493 } \
494 itkTypeMacro(newexcp, parentexcp); \
495 }; \
496 }
497 
498 #define itkSpecializedExceptionMacro(exceptiontype) \
499  { \
500  ::itk::exceptiontype e_(__FILE__, __LINE__); \
501  e_.SetLocation(ITK_LOCATION); \
502  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
503  }
504 
505 #define itkSpecializedMessageExceptionMacro(exceptiontype,x) \
506  { \
507  ::itk::exceptiontype e_(__FILE__, __LINE__); \
508  std::ostringstream message; \
509  message << "itk::ERROR: " x; \
510  e_.SetDescription(message.str().c_str()); \
511  e_.SetLocation(ITK_LOCATION); \
512  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
513  }
514 
515 
516 #define itkGenericOutputMacro(x) \
517  { \
518  if ( ::itk::Object::GetGlobalWarningDisplay() ) \
519  { \
520  std::ostringstream itkmsg; \
521  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
522  x << "\n\n"; \
523  ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \
524  } \
525  }
526 
527 //----------------------------------------------------------------------------
528 // Macros for simplifying the use of logging
529 //
530 #define itkLogMacro(x, y) \
531  { \
532  if ( this->GetLogger() ) \
533  { \
534  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
535  } \
536  }
537 
538 #define itkLogMacroStatic(obj, x, y) \
539  { \
540  if ( obj->GetLogger() ) \
541  { \
542  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
543  } \
544  }
545 
546 //----------------------------------------------------------------------------
547 // Setup legacy code policy.
548 //
549 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted
550 // They may be used to completely remove legacy code or silence the
551 // warnings. The default is to warn about their use.
552 //
553 // Source files that test the legacy code may define ITK_LEGACY_TEST
554 // like this:
555 //
556 // #define ITK_LEGACY_TEST
557 // #include "itkClassWithDeprecatedMethod.h"
558 //
559 // in order to silence the warnings for calling deprecated methods.
560 // No other source files in ITK should call the methods since they are
561 // provided only for compatibility with older user code.
562 
563 // Define itkLegacyMacro to mark legacy methods where they are
564 // declared in their class. Example usage:
565 //
566 // // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
567 // itkLegacyMacro(void MyMethod());
568 //
569 // See below for what to do for the method definition.
570 #if defined( ITK_LEGACY_REMOVE )
571 #define itkLegacyMacro(method) /* no ';' */
572 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( ITK_WRAPPING_PARSER )
573 // Provide legacy methods with no warnings.
574 #define itkLegacyMacro(method) method
575 #else
576 // Setup compile-time warnings for uses of deprecated methods if
577 // possible on this compiler.
578 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) )
579 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) )
580 #elif defined( _MSC_VER )
581 #define itkLegacyMacro(method) __declspec(deprecated) method
582 #else
583 #define itkLegacyMacro(method) method
584 #endif
585 #endif
586 
587 // Macros to create runtime deprecation warning messages in function
588 // bodies. Example usage:
589 //
590 // #if !defined( ITK_LEGACY_REMOVE )
591 // void itkMyClass::MyOldMethod()
592 // {
593 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
594 // }
595 //
596 // void itkMyClass::MyMethod()
597 // {
598 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
599 // itkMyClass::MyOtherMethod);
600 // }
601 // #endif
602 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT )
603 #define itkLegacyBodyMacro(method, version)
604 #define itkLegacyReplaceBodyMacro(method, version, replace)
605 #define itkGenericLegacyBodyMacro(method, version)
606 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)
607 #else
608 #define itkLegacyBodyMacro(method, version) \
609  itkWarningMacro(#method " was deprecated for ITK " #version \
610  " and will be removed in a future version.")
611 #define itkLegacyReplaceBodyMacro(method, version, replace) \
612  itkWarningMacro( #method " was deprecated for ITK " #version \
613  " and will be removed in a future version. Use " #replace " instead.")
614 #define itkGenericLegacyBodyMacro(method, version) \
615  itkGenericOutputMacro(#method " was deprecated for ITK " #version \
616  " and will be removed in a future version.")
617 #define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
618  itkGenericOutputMacro( #method " was deprecated for ITK " #version \
619  " and will be removed in a future version. Use " #replace " instead.")
620 #endif
621 
622 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
623 // the cache lines. By aligning multi-threaded structures with the
624 // cache lines, false shared can be reduced, and performance
625 // increased.
626 #define ITK_CACHE_LINE_ALIGNMENT 64
627 
628 //
629 // itkPadStruct will add padding to a structure to ensure a minimum size
630 // for ensuring that adjacent structures do not share CACHE lines.
631 // Each struct will take up some multiple of cacheline sizes.
632 // This is particularly useful for arrays of thread private variables.
633 //
634 #define itkPadStruct( mincachesize, oldtype, newtype ) \
635  struct newtype: public oldtype \
636  { \
637  char _StructPadding[mincachesize - (sizeof(oldtype)%mincachesize) ]; \
638  };
639 
640 //
641 // itkAlignedTypedef is a macro which creates a new typedef to make a
642 // data structure aligned.
643 //
644 #if defined( ITK_HAS_GNU_ATTRIBUTE_ALIGNED )
645 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
646  typedef oldtype newtype __attribute__((aligned(alignment)))
647 #elif defined ( _MSC_VER )
648 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
649  typedef __declspec(align( alignment )) oldtype newtype
650 #else
651 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
652  typedef oldtype newtype
653 #endif
654 
655 #if defined ( ITK_FUTURE_LEGACY_REMOVE )
656 //=============================================================================
657 /*
658 NOTE: DEPRECATED - This macro is not longer needed to support modern
659 compilers.
660 
661  Define a common way of declaring a templated function as a friend inside a class.
662  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
663 
664  The following templated function
665 
666  template <T>
667  T add(const T & a, const T & b);
668 
669  is declared as friend with
670 
671  class A
672  {
673  public:
674  friend Self add<>( const Self & a, const Self & b );
675  }
676 
677 */
678 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
679 #else // LEGACY_REMOVE
680 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
681 #endif
682 
683 //--------------------------------------------------------------------------------
684 // Helper macros for Template Meta-Programming techniques of for-loops
685 // unrolling
686 //--------------------------------------------------------------------------------
687 
688 //--------------------------------------------------------------------------------
689 // Macro that generates an unrolled for loop for assigning elements of one array
690 // to elements of another array The array are assumed to be of same length
691 // (dimension), and this is also assumed to be the value of NumberOfIterations.
692 // No verification of size is performed. Casting is perfomed as part of the
693 // assignment, by using the DestinationElementType as the casting type.
694 // Source and destination array types must have defined opearator[] in their
695 // API.
696 #define itkForLoopAssignmentMacro(DestinationType, \
697  SourceType, \
698  DestinationElementType, \
699  DestinationArray, \
700  SourceArray, \
701  NumberOfIterations) \
702  for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
703  { \
704  DestinationArray[i] = \
705  static_cast< DestinationElementType >( SourceArray[i] ); \
706  }
707 
708 //--------------------------------------------------------------------------------
709 // Macro that generates an unrolled for loop for rounding and assigning
710 // elements of one array to elements of another array The array are assumed to
711 // be of same length (dimension), and this is also assumed to be the value of
712 // NumberOfIterations. No verification of size is performed. Casting is
713 // perfomed as part of the assignment, by using the DestinationElementType as
714 // the casting type.
715 // Source and destination array types must have defined opearator[] in their
716 // API.
717 #define itkForLoopRoundingAndAssignmentMacro(DestinationType, \
718  Sourcrnd_halfintup, \
719  DestinationElementType, \
720  DestinationArray, \
721  SourceArray, \
722  NumberOfIterations) \
723  for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
724  { \
725  DestinationArray[i] = \
726  itk::Math::Round< DestinationElementType >(SourceArray[i]); \
727  }
728 
729 // end of Template Meta Programming helper macros
730 
731 #ifndef NDEBUG
732 
733 #ifdef _POSIX_SOURCE
734 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
735 #else
736 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
737 #endif
738 
739 #else
740 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
741 #endif
742 
743 #define itkAssertOrThrowMacro(test, message) \
744  if ( !( test ) ) \
745  { \
746  std::ostringstream msgstr; \
747  msgstr << message; \
748  itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
749  }
750 
751 #ifndef NDEBUG
752 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
753 #else
754 #define itkAssertInDebugAndIgnoreInReleaseMacro(X)
755 #endif
756 
757 
758 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
759 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
760 // !! The ITK Get/Set Macros for various types !!
761 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
762 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
777 #if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__ ) < 405 && !defined( __clang__ ) && !defined( __INTEL_COMPILER )
778 # define itkStaticConstMacro(name,type,value) enum { name = value }
779 #else
780 # define itkStaticConstMacro(name,type,value) static constexpr type name = value
781 #endif
782 
783 #define itkGetStaticConstMacro(name) (Self::name)
784 
786 #define itkSetInputMacro(name, type) \
787  virtual void Set##name(const type *_arg) \
788  { \
789  itkDebugMacro("setting input " #name " to " << _arg); \
790  if ( _arg != itkDynamicCastInDebugMode< type * >( \
791  this->ProcessObject::GetInput(#name) ) ) \
792  { \
793  this->ProcessObject::SetInput( #name, const_cast< type * >( _arg ) ); \
794  this->Modified(); \
795  } \
796  }
797 
798 
800 #define itkGetInputMacro(name, type) \
801  virtual const type * Get##name() const \
802  { \
803  itkDebugMacro( "returning input " << #name " of " \
804  << this->ProcessObject::GetInput(#name) ); \
805  return itkDynamicCastInDebugMode< const type * >( \
806  this->ProcessObject::GetInput(#name) ); \
807  }
808 
809 
811 #define itkSetDecoratedInputMacro(name, type) \
812  virtual void Set##name##Input(const SimpleDataObjectDecorator< type > *_arg) \
813  { \
814  itkDebugMacro("setting input " #name " to " << _arg); \
815  if ( _arg != itkDynamicCastInDebugMode< SimpleDataObjectDecorator< type > * >( \
816  this->ProcessObject::GetInput(#name) ) ) \
817  { \
818  this->ProcessObject::SetInput( \
819  #name, const_cast< SimpleDataObjectDecorator< type > * >( _arg ) ); \
820  this->Modified(); \
821  } \
822  } \
823  virtual void Set##name(const SimpleDataObjectDecorator< type > *_arg) \
824  { \
825  this->Set##name##Input(_arg); \
826  } \
827  virtual void Set##name(const type &_arg) \
828  { \
829  using DecoratorType = SimpleDataObjectDecorator< type >; \
830  itkDebugMacro("setting input " #name " to " << _arg); \
831  const DecoratorType *oldInput = \
832  itkDynamicCastInDebugMode< const DecoratorType * >( \
833  this->ProcessObject::GetInput(#name) ); \
834 CLANG_PRAGMA_PUSH \
835 CLANG_SUPPRESS_Wfloat_equal \
836  if ( oldInput && oldInput->Get() == _arg ) \
837 CLANG_PRAGMA_POP \
838  { \
839  return; \
840  } \
841  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
842  newInput->Set(_arg); \
843  this->Set##name##Input(newInput); \
844  }
845 
846 
848 #define itkGetDecoratedInputMacro(name, type) \
849  virtual const SimpleDataObjectDecorator< type > * Get##name##Input() const \
850  { \
851  itkDebugMacro( "returning input " << #name " of " \
852  << this->ProcessObject::GetInput(#name) ); \
853  return itkDynamicCastInDebugMode< const SimpleDataObjectDecorator< type > * >( \
854  this->ProcessObject::GetInput(#name) ); \
855  } \
856  virtual const type & Get##name() const \
857  { \
858  itkDebugMacro("Getting input " #name); \
859  using DecoratorType = SimpleDataObjectDecorator< type >; \
860  const DecoratorType *input = \
861  itkDynamicCastInDebugMode< const DecoratorType * >( \
862  this->ProcessObject::GetInput(#name) ); \
863  if( input == nullptr ) \
864  { \
865  itkExceptionMacro(<<"input" #name " is not set"); \
866  } \
867  return input->Get(); \
868  }
869 
870 
873 #define itkSetGetDecoratedInputMacro(name, type) \
874  itkSetDecoratedInputMacro(name, type) \
875  itkGetDecoratedInputMacro(name, type)
876 
881 #define itkSetDecoratedObjectInputMacro(name, type) \
882  virtual void Set##name##Input(const DataObjectDecorator< type > *_arg) \
883  { \
884  itkDebugMacro("setting input " #name " to " << _arg); \
885  if ( _arg != itkDynamicCastInDebugMode< DataObjectDecorator< type > * >( \
886  this->ProcessObject::GetInput(#name) ) ) \
887  { \
888  this->ProcessObject::SetInput( #name, \
889  const_cast< DataObjectDecorator< type > * >( _arg ) ); \
890  this->Modified(); \
891  } \
892  } \
893  virtual void Set##name(const type * _arg) \
894  { \
895  using DecoratorType = DataObjectDecorator< type >; \
896  itkDebugMacro("setting input " #name " to " << _arg); \
897  const DecoratorType *oldInput = \
898  itkDynamicCastInDebugMode< const DecoratorType * >( \
899  this->ProcessObject::GetInput(#name) ); \
900  if ( oldInput && oldInput->Get() == _arg ) \
901  { \
902  return; \
903  } \
904  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
905  newInput->Set(_arg); \
906  this->Set##name##Input(newInput); \
907  }
908 
909 
914 #define itkGetDecoratedObjectInputMacro(name, type) \
915  virtual const DataObjectDecorator< type > * Get##name##Input() const \
916  { \
917  itkDebugMacro( "returning input " << #name " of " \
918  << this->ProcessObject::GetInput(#name) ); \
919  return itkDynamicCastInDebugMode< \
920  const DataObjectDecorator< type > * >( \
921  this->ProcessObject::GetInput(#name) ); \
922  } \
923  virtual const type * Get##name() const \
924  { \
925  itkDebugMacro("Getting input " #name); \
926  using DecoratorType = DataObjectDecorator< type >; \
927  const DecoratorType *input = \
928  itkDynamicCastInDebugMode< const DecoratorType * >( \
929  this->ProcessObject::GetInput(#name) ); \
930  if( input == nullptr ) \
931  { \
932  return nullptr; \
933  } \
934  return input->Get(); \
935  }
936 
937 
940 #define itkSetGetDecoratedObjectInputMacro(name, type) \
941  itkSetDecoratedObjectInputMacro(name, type) \
942  itkGetDecoratedObjectInputMacro(name, type)
943 
945 #define itkSetMacro(name, type) \
946  virtual void Set##name (const type _arg) \
947  { \
948  itkDebugMacro("setting " #name " to " << _arg); \
949 CLANG_PRAGMA_PUSH \
950 CLANG_SUPPRESS_Wfloat_equal \
951  if ( this->m_##name != _arg ) \
952  { \
953  this->m_##name = _arg; \
954  this->Modified(); \
955  } \
956 CLANG_PRAGMA_POP \
957  }
958 
959 
961 #define itkGetMacro(name, type) \
962  virtual type Get##name () \
963  { \
964  return this->m_##name; \
965  }
966 
967 
971 #define itkGetConstMacro(name, type) \
972  virtual type Get##name () const \
973  { \
974  return this->m_##name; \
975  }
976 
977 
982 #define itkGetConstReferenceMacro(name, type) \
983  virtual const type &Get##name () const \
984  { \
985  return this->m_##name; \
986  }
987 
988 
993 #define itkSetEnumMacro(name, type) \
994  virtual void Set##name (const type _arg) \
995  { \
996  itkDebugMacro( "setting " #name " to " \
997  << static_cast< long >( _arg ) ); \
998  if ( this->m_##name != _arg ) \
999  { \
1000  this->m_##name = _arg; \
1001  this->Modified(); \
1002  } \
1003  }
1004 
1005 
1010 #define itkGetEnumMacro(name, type) \
1011  virtual type Get##name () const \
1012  { \
1013  return this->m_##name; \
1014  }
1015 
1016 
1020 #define itkSetStringMacro(name) \
1021  virtual void Set##name (const char *_arg) \
1022  { \
1023  if ( _arg && ( _arg == this->m_##name ) ) { return; } \
1024  if ( _arg ) \
1025  { \
1026  this->m_##name = _arg; \
1027  } \
1028  else \
1029  { \
1030  this->m_##name = ""; \
1031  } \
1032  this->Modified(); \
1033  } \
1034  virtual void Set##name (const std::string & _arg) \
1035  { \
1036  this->Set##name( _arg.c_str() ); \
1037  } \
1038 
1039 
1040 
1044 #define itkGetStringMacro(name) \
1045  virtual const char *Get##name () const \
1046  { \
1047  return this->m_##name.c_str(); \
1048  }
1049 
1053 #define itkSetClampMacro(name, type, min, max) \
1054  virtual void Set##name (type _arg) \
1055  { \
1056  const type temp_extrema=( _arg < min ? min \
1057  : ( _arg > max ? max : _arg ) ); \
1058  itkDebugMacro("setting " << #name " to " << _arg); \
1059 CLANG_PRAGMA_PUSH \
1060 CLANG_SUPPRESS_Wfloat_equal \
1061  if ( this->m_##name != temp_extrema ) \
1062  { \
1063  this->m_##name = temp_extrema; \
1064  this->Modified(); \
1065  } \
1066 CLANG_PRAGMA_POP \
1067  }
1068 
1069 
1070 //NOTE: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
1075 #define itkSetObjectMacro(name, type) \
1076  virtual void Set##name (type * _arg) \
1077  { \
1078  itkDebugMacro("setting " << #name " to " << _arg); \
1079 CLANG_PRAGMA_PUSH \
1080 CLANG_SUPPRESS_Wfloat_equal \
1081  if ( this->m_##name != _arg ) \
1082  { \
1083  this->m_##name = _arg; \
1084  this->Modified(); \
1085  } \
1086 CLANG_PRAGMA_POP \
1087  }
1088 
1089 
1098 // NOTE: A class can use either itkGetModifiableObjectMacro
1099 // or itkGetObjectMacro, but not both.
1100 // A class can use either itkGetModifiableObjectMacro
1101 // or itkGetConstObjectMacro, but not both.
1102 // If the desired behavior is to only provide const
1103 // access to the itkObject ivar, then use itkGetConstObjectMacro,
1104 // else use itkGetModifiableObjectMacro for read/write access to
1105 // the ivar.
1106 // It is permissable to use both itkGetObjectMacro and itkGetConstObjectMacro
1107 // for backwards compatibility.
1108 // If the ITK_LEGACY_REMOVE=FALSE, then it is
1109 // permissable to use itkGetObjectMacro which
1110 // defines both signatures itk::GetXXX() and
1111 // itk::GetModifiableXXX()
1112 
1115 #define itkGetConstObjectMacro(name, type) \
1116  virtual const type * Get##name () const \
1117  { \
1118  return this->m_##name.GetPointer(); \
1119  }
1120 
1121 
1122 #if defined ( ITK_FUTURE_LEGACY_REMOVE )
1123 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1124 // flag. For now, this very advanced feature is only available
1125 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1126 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1127 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1128 # define itkGetObjectMacro(name, type) \
1129  virtual type * Get##name () \
1130  { \
1131  purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1132  }
1133 
1134 # define itkGetModifiableObjectMacro(name, type) \
1135  virtual type * GetModifiable##name () \
1136  { \
1137  return this->m_##name.GetPointer(); \
1138  } \
1139  itkGetConstObjectMacro(name, type)
1140 
1141 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1142 
1144 # define itkGetObjectMacro(name, type) \
1145  virtual type * Get##name () \
1146  { \
1147  return this->m_##name.GetPointer(); \
1148  }
1149 # define itkGetModifiableObjectMacro(name, type) \
1150  virtual type * GetModifiable##name () \
1151  { \
1152  return this->m_##name.GetPointer(); \
1153  } \
1154  itkGetConstObjectMacro(name, type) \
1155  itkGetObjectMacro(name, type)
1156 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1157 
1158 
1159 // For backwards compatibility define ITK_EXPORT to nothing
1160 #define ITK_EXPORT
1161 
1162 
1165 #define itkGetConstReferenceObjectMacro(name, type) \
1166  virtual const typename type::Pointer & Get##name () const \
1167  { \
1168  return this->m_##name; \
1169  }
1170 
1175 #define itkSetConstObjectMacro(name, type) \
1176  virtual void Set##name (const type * _arg) \
1177  { \
1178  itkDebugMacro("setting " << #name " to " << _arg); \
1179  if ( this->m_##name != _arg ) \
1180  { \
1181  this->m_##name = _arg; \
1182  this->Modified(); \
1183  } \
1184  }
1185 
1186 
1189 #define itkBooleanMacro(name) \
1190  virtual void name##On () \
1191  { \
1192  this->Set##name(true); \
1193  } \
1194  virtual void name##Off () \
1195  { \
1196  this->Set##name(false); \
1197  }
1198 
1199 
1203 #define itkSetVectorMacro(name, type, count) \
1204  virtual void Set##name(type data[]) \
1205  { \
1206  unsigned int i; \
1207  for ( i = 0; i < count; i++ ) \
1208  { \
1209 CLANG_PRAGMA_PUSH \
1210 CLANG_SUPPRESS_Wfloat_equal \
1211  if ( data[i] != this->m_##name[i] ) \
1212 CLANG_PRAGMA_POP \
1213  { \
1214  break; \
1215  } \
1216  } \
1217  if ( i < count ) \
1218  { \
1219  this->Modified(); \
1220  for ( i = 0; i < count; i++ ) \
1221  { \
1222  this->m_##name[i] = data[i]; \
1223  } \
1224  } \
1225  }
1226 
1227 
1230 #define itkGetVectorMacro(name, type, count) \
1231  virtual type * Get##name () const \
1232  { \
1233  return this->m_##name; \
1234  }
1235 
1240 #define itkGPUKernelClassMacro(kernel) \
1241 
1242 
1247 
1262 
1284 
1322 
1324 
1347 
1358 
1389