ITK  4.13.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 // Define ITK_PRAGMA macro.
69 //
70 // It sets "#pragma" preprocessor directives without expecting the arguments
71 // to be quoted.
72 #define ITK_PRAGMA(x) _Pragma (#x)
73 
74 // The clang compiler has many useful non-default compiler warnings
75 // that tend to have a high false positive rate.
76 // The following set of defines allows us to suppress false positives
77 // and still track down suspicious code
78 #if defined(__clang__) && defined(__has_warning)
79 #define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
80 #define CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
81 # if __has_warning("-Wfloat-equal")
82 #define CLANG_SUPPRESS_Wfloat_equal ITK_PRAGMA( clang diagnostic ignored "-Wfloat-equal" )
83 # endif
84 #else
85 #define CLANG_PRAGMA_PUSH
86 #define CLANG_PRAGMA_POP
87 #define CLANG_SUPPRESS_Wfloat_equal
88 #endif
89 
90 // Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
91 //
92 // This macros sets a pragma diagnostic if it supported by the version
93 // of GCC being used otherwise it is a no-op.
94 //
95 // GCC diagnostics pragma supported only with GCC >= 4.2
96 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER )
97 # if ( __GNUC__ > 4 ) || (( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 2 ))
98 # define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
99 # else
100 # define ITK_GCC_PRAGMA_DIAG(x)
101 # endif
102 #else
103 # define ITK_GCC_PRAGMA_DIAG(x)
104 #endif
105 
106 // Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
107 //
108 // These macros respectively push and pop the diagnostic context
109 // if it is supported by the version of GCC being used
110 // otherwise it is a no-op.
111 //
112 // GCC push/pop diagnostics pragma are supported only with GCC >= 4.6
113 //
114 // Define macro ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP if it is supported.
115 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER )
116 # if ( __GNUC__ > 4 ) || (( __GNUC__ >= 4 ) && ( __GNUC_MINOR__ >= 6 ))
117 # define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
118 # define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
119 # define ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP
120 # else
121 # define ITK_GCC_PRAGMA_DIAG_PUSH()
122 # define ITK_GCC_PRAGMA_DIAG_POP()
123 # endif
124 #else
125 # define ITK_GCC_PRAGMA_DIAG_PUSH()
126 # define ITK_GCC_PRAGMA_DIAG_POP()
127 #endif
128 
129 /*
130  * ITK only supports MSVC++ 7.1 and greater
131  * MSVC++ 11.0 _MSC_VER = 1700
132  * MSVC++ 10.0 _MSC_VER = 1600
133  * MSVC++ 9.0 _MSC_VER = 1500
134  * MSVC++ 8.0 _MSC_VER = 1400
135  * MSVC++ 7.1 _MSC_VER = 1310
136  * MSVC++ 7.0 _MSC_VER = 1300
137  * MSVC++ 6.0 _MSC_VER = 1200
138  * MSVC++ 5.0 _MSC_VER = 1100
139 */
140 #if defined( _MSC_VER ) && ( _MSC_VER < 1310 )
141 //#error "_MSC_VER < 1310 (MSVC++ 7.1) not supported under ITKv4"
142 #endif
143 #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC < 0x590 )
144 #error "__SUNPRO_CC < 0x590 not supported under ITKv4"
145 #endif
146 #if defined( __CYGWIN__ )
147 #error "The Cygwin compiler is not supported in ITKv4 and above"
148 #endif
149 #if defined( __BORLANDC__ )
150 #error "The Borland C compiler is not supported in ITKv4 and above"
151 #endif
152 #if defined( __MWERKS__ )
153 #error "The MetroWerks compiler is not supported in ITKv4 and above"
154 #endif
155 #if defined( __GNUC__ ) && ( __GNUC__ < 3 )
156 #error "The __GNUC__ version 2.95 compiler is not supprted under ITKv4 and above"
157 #if defined( __sgi )
158 //This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
159 //TODO: At some future point, it may be necessary to
160 //define a minimum __sgi version that will work.
161 #error "The __sgi compiler is not supprted under ITKv4 and above"
162 #endif
163 #endif
164 
165 // Setup symbol exports
166 #if defined( _WIN32 ) || defined ( WIN32 )
167  #define ITK_ABI_IMPORT __declspec(dllimport)
168  #define ITK_ABI_EXPORT __declspec(dllexport)
169  #define ITK_ABI_HIDDEN
170 #else
171  #if __GNUC__ >= 4
172  #define ITK_ABI_IMPORT __attribute__ ((visibility ("default")))
173  #define ITK_ABI_EXPORT __attribute__ ((visibility ("default")))
174  #define ITK_ABI_HIDDEN __attribute__ ((visibility ("hidden")))
175  #else
176  #define ITK_ABI_IMPORT
177  #define ITK_ABI_EXPORT
178  #define ITK_ABI_HIDDEN
179  #endif
180 #endif
181 
182 // Setup symbol exports
183 #ifndef ITK_TEMPLATE_EXPORT
184  #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
185  #define ITK_TEMPLATE_EXPORT __attribute__ ((visibility ("default")))
186  #else
187  #define ITK_TEMPLATE_EXPORT
188  #endif
189 #endif
190 
191 // Setup symbol exports
192 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
193  #define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__ ((visibility ("default")))
194 #else
195  #define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName ## _EXPORT
196 #endif
197 
198 #ifndef ITK_FORWARD_EXPORT
199  // If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
200  #if defined(__APPLE__)\
201  && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT)\
202  && defined(ITK_BUILD_SHARED_LIBS)\
203  && defined(USE_COMPILER_HIDDEN_VISIBILITY)
204  #define ITK_FORWARD_EXPORT __attribute__ ((visibility ("default")))
205  #else
206  #define ITK_FORWARD_EXPORT
207  #endif
208 #endif
209 
210 #if ITK_COMPILED_CXX_STANDARD_VERSION >= 201103L
211  #define ITK_HAS_CXX11_RVREF
212 #endif
213 
214 #if ! defined( ITK_FUTURE_LEGACY_REMOVE )
215  #if ITK_COMPILER_CXX_STATIC_ASSERT
216  #define ITK_HAS_CXX11_STATIC_ASSERT //NOTE DEPRECATED! should be ITK_COMPILER_CXX_STATIC_ASSERT
217  #endif
218 
219  #if ITK_COMPILER_CXX_DELETED_FUNCTIONS
220  #define ITK_DELETE_FUNCTION =delete //NOTE DEPRECATED! should be ITK_DELETED_FUNCTION
221  #else
222  #define ITK_DELETE_FUNCTION
223  #endif
224  //NOTE DEPRECATED! should use ITK_COMPILER_CXX_ALIGNAS
225  #if ITK_COMPILER_CXX_ALIGNAS
226  // defined if the compiler supports C++11 alignas type specifier
227  #define ITK_HAS_CPP11_ALIGNAS
228  #else
229  #ifdef ITK_HAS_CPP11_ALIGNAS
230  #undef ITK_HAS_CPP11_ALIGNAS
231  #endif
232  #endif
233  #if ITK_COMPILER_CXX_NOEXCEPT // NOTE DEPRECATED! Kept for backwards compatibility.
234  // Should use ITK_NOEXCEPT defined in: itk_compiler_detection.h.
235  // Following comments apply to ITK_NOEXCEPT as well.
236  // Use only for low-level functions. Swap, UnRegister, etc, involved in move semantics.
237  // Avoid using it elsewhere.
238  // Unnecesary in destructors when c++11 becomes a requirement.
239  // Used right now to avoid c++03 errors in destructors of child classes of std::exception.
240  #define ITK_NOEXCEPT_OR_THROW() noexcept
241  #else
242  #define ITK_NOEXCEPT_OR_THROW() throw()
243  #endif
244 #else
245  //NOTE DEPRECATED should be ITK_NOEXCEPT
246  #define ITK_NOEXCEPT_OR_THROW error "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT"
247  //NOTE DEPRECATED! should be ITK_COMPILER_CXX_STATIC_ASSERT
248  #define ITK_HAS_CXX11_STATIC_ASSERT error "Replace ITK_HAS_CXX11_STATIC_ASSERT with ITK_COMPILER_CXX_STATIC_ASSERT"
249  //NOTE DEPRECATED! should be ITK_DELETED_FUNCTION
250  #define ITK_DELETE_FUNCTION error "Replace ITK_DELETE_FUNCTION with ITK_DELETED_FUNCTION"
251  //NOTE DEPRECATED! should use ITK_COMPILER_CXX_ALIGNAS
252  #define ITK_HAS_CPP11_ALIGNAS error "Replace ITK_HAS_CPP11_ALIGNAS with ITK_COMPILER_CXX_ALIGNAS"
253 #endif
254 
255 
256 #if ITK_COMPILER_CXX_CONSTEXPR
257  #define ITK_CONSTEXPR_FUNC constexpr
258  #define ITK_CONSTEXPR_VAR constexpr
259 #else
260  #define ITK_CONSTEXPR_FUNC inline
261  #define ITK_CONSTEXPR_VAR const
262 #endif
263 
264 // Use "ITK_FALLTHROUGH;" to annotate deliberate fall-through in switches,
265 // use it analogously to "break;". The trailing semi-colon is required.
266 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER )
267 # if ( __GNUC__ >= 7 )
268 # define ITK_FALLTHROUGH __attribute__((fallthrough))
269 # endif
270 #elif ITK_COMPILED_CXX_STANDARD_VERSION >= 201103L && defined(__has_warning)
271 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
272 # define ITK_FALLTHROUGH [[clang::fallthrough]]
273 # endif
274 #endif
275 
276 #ifndef ITK_FALLTHROUGH
277 # define ITK_FALLTHROUGH ((void)0)
278 #endif
279 
300 #define itkNewMacro(x) \
301  itkSimpleNewMacro(x) \
302  itkCreateAnotherMacro(x) \
303  itkCloneMacro(x)
304 
305 #define itkSimpleNewMacro(x) \
306  static Pointer New(void) \
307  { \
308  Pointer smartPtr = ::itk::ObjectFactory< x >::Create(); \
309  if ( smartPtr.GetPointer() == ITK_NULLPTR ) \
310  { \
311  smartPtr = new x; \
312  } \
313  smartPtr->UnRegister(); \
314  return smartPtr; \
315  }
316 
317 #define itkCreateAnotherMacro(x) \
318  virtual ::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE \
319  { \
320  ::itk::LightObject::Pointer smartPtr; \
321  smartPtr = x::New().GetPointer(); \
322  return smartPtr; \
323  }
324 
325 #define itkCloneMacro(x) \
326  Pointer Clone() const \
327  { \
328  Pointer rval = \
329  dynamic_cast<x *>(this->InternalClone().GetPointer()); \
330  return rval; \
331  }
332 
345 #define itkFactorylessNewMacro(x) \
346  static Pointer New(void) \
347  { \
348  Pointer smartPtr; \
349  x * rawPtr = new x; \
350  smartPtr = rawPtr; \
351  rawPtr->UnRegister(); \
352  return smartPtr; \
353  } \
354  virtual ::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE \
355  { \
356  ::itk::LightObject::Pointer smartPtr; \
357  smartPtr = x::New().GetPointer(); \
358  return smartPtr; \
359  }
360 
361 
362 //
363 // A macro to disallow the copy constructor and operator= functions
364 // This should be used in the private: declarations for a class
365 //
366 // ITK's paradigm for smart pointer and pipeline consistency
367 // prohibits the use of copy construction and operator= functions.
368 //
369 #define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
370  TypeName(const TypeName&) ITK_DELETED_FUNCTION; \
371  void operator=(const TypeName&) ITK_DELETED_FUNCTION
372 
375 #define itkTypeMacro(thisClass, superclass) \
376  virtual const char *GetNameOfClass() const ITK_OVERRIDE \
377  { \
378  return #thisClass; \
379  }
380 
381 #define itkTypeMacroNoParent(thisClass) \
382  virtual const char *GetNameOfClass() const \
383  { \
384  return #thisClass; \
385  }
386 
387 namespace itk
388 {
395 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char *);
397 
398 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char *);
399 
400 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char *);
401 
402 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char *);
403 
404 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char *);
405 } // end namespace itk
406 
410 #if defined( NDEBUG )
411 #define itkDebugMacro(x)
412 #define itkDebugStatement(x)
413 #else
414 #define itkDebugMacro(x) \
415  { \
416  if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
417  { \
418  std::ostringstream itkmsg; \
419  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
420  << this->GetNameOfClass() << " (" << this << "): " x \
421  << "\n\n"; \
422  ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() ); \
423  } \
424  }
425 
426 
427 //The itkDebugStatement is to be used to protect code that is only
428 //used in the itkDebugMacro
429 #define itkDebugStatement(x) x
430 #endif
431 
435 #define itkWarningMacro(x) \
436  { \
437  if ( ::itk::Object::GetGlobalWarningDisplay() ) \
438  { \
439  std::ostringstream itkmsg; \
440  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
441  << this->GetNameOfClass() << " (" << this << "): " x \
442  << "\n\n"; \
443  ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() ); \
444  } \
445  }
446 
447 
448 //The itkDebugStatement is to be used ot protect code that is only
449 //used in the itkDebugMacro
450 #define itkWarningStatement(x) x
451 
452 #if defined( ITK_CPP_FUNCTION )
453  #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( ITK_WRAPPING_PARSER )
454  #define ITK_LOCATION __FUNCSIG__
455  #elif defined( __GNUC__ )
456  #define ITK_LOCATION __PRETTY_FUNCTION__
457  #else
458  #define ITK_LOCATION __FUNCTION__
459  #endif
460 #else
461  #define ITK_LOCATION "unknown"
462 #endif
463 
464 #include "itkExceptionObject.h"
465 
469 #define itkExceptionMacro(x) \
470  { \
471  std::ostringstream message; \
472  message << "itk::ERROR: " << this->GetNameOfClass() \
473  << "(" << this << "): " x; \
474  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
475  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
476  }
477 
478 
479 #define itkGenericExceptionMacro(x) \
480  { \
481  std::ostringstream message; \
482  message << "itk::ERROR: " x; \
483  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
484  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
485  }
486 
487 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage) \
488 namespace itk { \
489 class newexcp : public parentexcp \
490 { \
491 public: \
492 newexcp( const char *file, unsigned int lineNumber ) : \
493 parentexcp( file, lineNumber ) \
494 { \
495  this->SetDescription( whatmessage ); \
496 } \
497 newexcp( const std::string & file, unsigned int lineNumber ) : \
498 parentexcp( file, lineNumber ) \
499 { \
500  this->SetDescription( whatmessage ); \
501 } \
502 itkTypeMacro(newexcp, parentexcp); \
503 }; \
504 }
505 
506 #define itkSpecializedExceptionMacro(exceptiontype) \
507  { \
508  ::itk::exceptiontype e_(__FILE__, __LINE__); \
509  e_.SetLocation(ITK_LOCATION); \
510  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
511  }
512 
513 #define itkSpecializedMessageExceptionMacro(exceptiontype,x) \
514  { \
515  ::itk::exceptiontype e_(__FILE__, __LINE__); \
516  std::ostringstream message; \
517  message << "itk::ERROR: " x; \
518  e_.SetDescription(message.str().c_str()); \
519  e_.SetLocation(ITK_LOCATION); \
520  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
521  }
522 
523 
524 #define itkGenericOutputMacro(x) \
525  { \
526  if ( ::itk::Object::GetGlobalWarningDisplay() ) \
527  { \
528  std::ostringstream itkmsg; \
529  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
530  x << "\n\n"; \
531  ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \
532  } \
533  }
534 
535 //----------------------------------------------------------------------------
536 // Macros for simplifying the use of logging
537 //
538 #define itkLogMacro(x, y) \
539  { \
540  if ( this->GetLogger() ) \
541  { \
542  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
543  } \
544  }
545 
546 #define itkLogMacroStatic(obj, x, y) \
547  { \
548  if ( obj->GetLogger() ) \
549  { \
550  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
551  } \
552  }
553 
554 //----------------------------------------------------------------------------
555 // Setup legacy code policy.
556 //
557 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted
558 // They may be used to completely remove legacy code or silence the
559 // warnings. The default is to warn about their use.
560 //
561 // Source files that test the legacy code may define ITK_LEGACY_TEST
562 // like this:
563 //
564 // #define ITK_LEGACY_TEST
565 // #include "itkClassWithDeprecatedMethod.h"
566 //
567 // in order to silence the warnings for calling deprecated methods.
568 // No other source files in ITK should call the methods since they are
569 // provided only for compatibility with older user code.
570 
571 // Define itkLegacyMacro to mark legacy methods where they are
572 // declared in their class. Example usage:
573 //
574 // // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
575 // itkLegacyMacro(void MyMethod());
576 //
577 // See below for what to do for the method definition.
578 #if defined( ITK_LEGACY_REMOVE )
579 #define itkLegacyMacro(method) /* no ';' */
580 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( ITK_WRAPPING_PARSER )
581 // Provide legacy methods with no warnings.
582 #define itkLegacyMacro(method) method
583 #else
584 // Setup compile-time warnings for uses of deprecated methods if
585 // possible on this compiler.
586 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) )
587 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) )
588 #elif defined( _MSC_VER )
589 #define itkLegacyMacro(method) __declspec(deprecated) method
590 #else
591 #define itkLegacyMacro(method) method
592 #endif
593 #endif
594 
595 // Macros to create runtime deprecation warning messages in function
596 // bodies. Example usage:
597 //
598 // #if !defined( ITK_LEGACY_REMOVE )
599 // void itkMyClass::MyOldMethod()
600 // {
601 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
602 // }
603 //
604 // void itkMyClass::MyMethod()
605 // {
606 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
607 // itkMyClass::MyOtherMethod);
608 // }
609 // #endif
610 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT )
611 #define itkLegacyBodyMacro(method, version)
612 #define itkLegacyReplaceBodyMacro(method, version, replace)
613 #define itkGenericLegacyBodyMacro(method, version)
614 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)
615 #else
616 #define itkLegacyBodyMacro(method, version) \
617  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
618 #define itkLegacyReplaceBodyMacro(method, version, replace) \
619  itkWarningMacro( \
620  #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
621  " instead.")
622 #define itkGenericLegacyBodyMacro(method, version) \
623  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
624 #define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
625  itkGenericOutputMacro( \
626  #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
627  " instead.")
628 #endif
629 
630 #if defined ( ITK_LEGACY_REMOVE )
631 #define ITK_TEMPLATE_TXX "error ITK_TEMPLATE_TXX is no longer a supported identifier, you should replace with ITK_MANUAL_INSTANTIATION as a replacement"
632 #else
633 #define ITK_TEMPLATE_TXX 1
634 #endif
635 
636 
637 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
638 // the cache lines. By aligning multi-threaded structures with the
639 // cache lines, false shared can be reduced, and performance
640 // increased.
641 #define ITK_CACHE_LINE_ALIGNMENT 64
642 
643 //
644 // itkPadStruct will add padding to a structure to ensure a minimum size
645 // for ensuring that adjacent structures do not share CACHE lines.
646 // Each struct will take up some multiple of cacheline sizes.
647 // This is particularly useful for arrays of thread private variables.
648 //
649 #define itkPadStruct( mincachesize, oldtype, newtype ) \
650  struct newtype: public oldtype \
651  { \
652  char _StructPadding[mincachesize - (sizeof(oldtype)%mincachesize) ]; \
653  };
654 
655 //
656 // itkAlignedTypedef is a macro which creates a new typedef to make a
657 // data structure aligned.
658 //
659 #if defined( ITK_HAS_GNU_ATTRIBUTE_ALIGNED )
660 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
661  typedef oldtype newtype __attribute__((aligned(alignment)))
662 #elif defined ( _MSC_VER )
663 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
664  typedef __declspec(align( alignment )) oldtype newtype
665 #else
666 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
667  typedef oldtype newtype
668 #endif
669 
670 //=============================================================================
671 /* Define a common way of declaring a templated function as a friend inside a class.
672  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
673 
674  The following templated function
675 
676  template <T>
677  T add(const T & a, const T & b);
678 
679  is declared as friend in some compilers as:
680 
681  class A
682  {
683  public:
684  friend Self add<Self>( const Self & a, const Self & b );
685  }
686 
687  while other compilers will do
688 
689  class A
690  {
691  public:
692  friend Self add<>( const Self & a, const Self & b );
693  }
694 
695  This characteristic of the compiler is checked by a TRY_COMPILE
696  command defined in Insight/CMake/itkTestFriendTemplatedFunction.cxx
697 
698 */
699 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_NULL_STRING )
700 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
701 #else
702 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_EMPTY_BRACKETS )
703 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
704 #else
705 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_TEMPLATE_ARGUMENTS )
706 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < T >
707 #endif
708 #endif
709 #endif
710 // THIS IS A TEMPORARY PATCH FOR Visual Studio 10. The correct solution must
711 // be implemented in Insight/CMake/itkTestFriendTemplatedFunction.cxx
712 #if ( defined ( _MSC_VER ) && ( _MSC_VER >= 1600 ) )
713 #ifdef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
714 #undef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
715 #endif
716 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
717 #endif
718 
719 //--------------------------------------------------------------------------------
720 // Helper macros for Template Meta-Programming techniques of for-loops
721 // unrolling
722 //--------------------------------------------------------------------------------
723 
724 //--------------------------------------------------------------------------------
725 // Macro that generates an unrolled for loop for assigning elements of one array
726 // to elements of another array The array are assumed to be of same length
727 // (dimension), and this is also assumed to be the value of NumberOfIterations.
728 // No verification of size is performed. Casting is perfomed as part of the
729 // assignment, by using the DestinationElementType as the casting type.
730 // Source and destination array types must have defined opearator[] in their
731 // API.
732 #define itkForLoopAssignmentMacro(DestinationType, \
733  SourceType, \
734  DestinationElementType, \
735  DestinationArray, \
736  SourceArray, \
737  NumberOfIterations) \
738  for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
739  { \
740  DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
741  }
742 
743 //--------------------------------------------------------------------------------
744 // Macro that generates an unrolled for loop for rounding and assigning
745 // elements of one array to elements of another array The array are assumed to
746 // be of same length (dimension), and this is also assumed to be the value of
747 // NumberOfIterations. No verification of size is performed. Casting is
748 // perfomed as part of the assignment, by using the DestinationElementType as
749 // the casting type.
750 // Source and destination array types must have defined opearator[] in their
751 // API.
752 #define itkForLoopRoundingAndAssignmentMacro(DestinationType, \
753  Sourcrnd_halfintup, \
754  DestinationElementType, \
755  DestinationArray, \
756  SourceArray, \
757  NumberOfIterations) \
758  for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
759  { \
760  DestinationArray[i] = itk::Math::Round< DestinationElementType >(SourceArray[i]); \
761  }
762 
763 // end of Template Meta Programming helper macros
764 
765 #ifndef NDEBUG
766 
767 #ifdef _POSIX_SOURCE
768 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
769 #else
770 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
771 #endif
772 
773 #else
774 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
775 #endif
776 
777 #define itkAssertOrThrowMacro(test, message) \
778  if ( !( test ) ) \
779  { \
780  std::ostringstream msgstr; \
781  msgstr << message; \
782  itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
783  }
784 
785 #ifndef NDEBUG
786 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
787 #else
788 #define itkAssertInDebugAndIgnoreInReleaseMacro(X)
789 #endif
790 
791 #ifdef ITKV3_COMPATIBILITY
792 // As of MSVS++ 7.1 and greater, typename is supported in templates
793 // All ITKv4 compilers support the typename keyword, but this is
794 // needed to ease transition from ITKv3.
795 #define ITK_TYPENAME typename
796 #endif
797 
801 template <typename TTarget, typename TSource>
802 TTarget itkDynamicCastInDebugMode(TSource x)
803 {
804 #ifndef NDEBUG
805  if(x == 0)
806  {
807  return 0;
808  }
809  TTarget rval = dynamic_cast<TTarget>(x);
810  if(rval == 0)
811  {
812  itkGenericExceptionMacro(<< "Failed dynamic cast to "
813  << typeid(TTarget).name()
814  << " object type = "
815  << x->GetNameOfClass());
816  }
817  return rval;
818 #else
819  return static_cast<TTarget>(x);
820 #endif
821 }
823 
824 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
825 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
826 // !! The ITK Get/Set Macros for various types !!
827 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
828 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
843 #if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__ ) < 405 && !defined( __clang__ ) && !defined( __INTEL_COMPILER )
844 # define itkStaticConstMacro(name,type,value) enum { name = value }
845 #else
846 # define itkStaticConstMacro(name,type,value) static ITK_CONSTEXPR_VAR type name = value
847 #endif
848 
849 #define itkGetStaticConstMacro(name) (Self::name)
850 
852 #define itkSetInputMacro(name, type) \
853  virtual void Set##name(const type *_arg) \
854  { \
855  itkDebugMacro("setting input " #name " to " << _arg); \
856  if ( _arg != itkDynamicCastInDebugMode< type * >( this->ProcessObject::GetInput(#name) ) ) \
857  { \
858  this->ProcessObject::SetInput( #name, const_cast< type * >( _arg ) ); \
859  this->Modified(); \
860  } \
861  }
862 
863 
865 #define itkGetInputMacro(name, type) \
866  virtual const type * Get##name() const \
867  { \
868  itkDebugMacro( "returning input " << #name " of " << this->ProcessObject::GetInput(#name) ); \
869  return itkDynamicCastInDebugMode< const type * >( this->ProcessObject::GetInput(#name) ); \
870  }
871 
872 
874 #define itkSetDecoratedInputMacro(name, type) \
875  virtual void Set##name##Input(const SimpleDataObjectDecorator< type > *_arg) \
876  { \
877  itkDebugMacro("setting input " #name " to " << _arg); \
878  if ( _arg != itkDynamicCastInDebugMode< SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
879  { \
880  this->ProcessObject::SetInput( #name, const_cast< SimpleDataObjectDecorator< type > * >( _arg ) ); \
881  this->Modified(); \
882  } \
883  } \
884  virtual void Set##name(const SimpleDataObjectDecorator< type > *_arg) \
885  { \
886  this->Set##name##Input(_arg); \
887  } \
888  virtual void Set##name(const type &_arg) \
889  { \
890  typedef SimpleDataObjectDecorator< type > DecoratorType; \
891  itkDebugMacro("setting input " #name " to " << _arg); \
892  const DecoratorType *oldInput = \
893  itkDynamicCastInDebugMode< const DecoratorType * >( \
894  this->ProcessObject::GetInput(#name) ); \
895 CLANG_PRAGMA_PUSH \
896 CLANG_SUPPRESS_Wfloat_equal \
897  if ( oldInput && oldInput->Get() == _arg ) \
898 CLANG_PRAGMA_POP \
899  { \
900  return; \
901  } \
902  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
903  newInput->Set(_arg); \
904  this->Set##name##Input(newInput); \
905  }
906 
907 
909 #define itkGetDecoratedInputMacro(name, type) \
910  virtual const SimpleDataObjectDecorator< type > * Get##name##Input() const \
911  { \
912  itkDebugMacro( "returning input " << #name " of " << this->ProcessObject::GetInput(#name) ); \
913  return itkDynamicCastInDebugMode< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
914  } \
915  virtual const type & Get##name() const \
916  { \
917  itkDebugMacro("Getting input " #name); \
918  typedef SimpleDataObjectDecorator< type > DecoratorType; \
919  const DecoratorType *input = \
920  itkDynamicCastInDebugMode< const DecoratorType * >( \
921  this->ProcessObject::GetInput(#name) ); \
922  if( input == ITK_NULLPTR ) \
923  { \
924  itkExceptionMacro(<<"input" #name " is not set"); \
925  } \
926  return input->Get(); \
927  }
928 
929 
932 #define itkSetGetDecoratedInputMacro(name, type) \
933  itkSetDecoratedInputMacro(name, type) \
934  itkGetDecoratedInputMacro(name, type)
935 
940 #define itkSetDecoratedObjectInputMacro(name, type) \
941  virtual void Set##name##Input(const DataObjectDecorator< type > *_arg) \
942  { \
943  itkDebugMacro("setting input " #name " to " << _arg); \
944  if ( _arg != itkDynamicCastInDebugMode< DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
945  { \
946  this->ProcessObject::SetInput( #name, const_cast< DataObjectDecorator< type > * >( _arg ) ); \
947  this->Modified(); \
948  } \
949  } \
950  virtual void Set##name(const type * _arg) \
951  { \
952  typedef DataObjectDecorator< type > DecoratorType; \
953  itkDebugMacro("setting input " #name " to " << _arg); \
954  const DecoratorType *oldInput = \
955  itkDynamicCastInDebugMode< const DecoratorType * >( \
956  this->ProcessObject::GetInput(#name) ); \
957  if ( oldInput && oldInput->Get() == _arg ) \
958  { \
959  return; \
960  } \
961  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
962  newInput->Set(_arg); \
963  this->Set##name##Input(newInput); \
964  }
965 
966 
971 #define itkGetDecoratedObjectInputMacro(name, type) \
972  virtual const DataObjectDecorator< type > * Get##name##Input() const \
973  { \
974  itkDebugMacro( "returning input " << #name " of "<< this->ProcessObject::GetInput(#name) ); \
975  return itkDynamicCastInDebugMode< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
976  } \
977  virtual const type * Get##name() const \
978  { \
979  itkDebugMacro("Getting input " #name); \
980  typedef DataObjectDecorator< type > DecoratorType; \
981  const DecoratorType *input = \
982  itkDynamicCastInDebugMode< const DecoratorType * >( \
983  this->ProcessObject::GetInput(#name) ); \
984  if( input == ITK_NULLPTR ) \
985  { \
986  return ITK_NULLPTR; \
987  } \
988  return input->Get(); \
989  }
990 
991 
994 #define itkSetGetDecoratedObjectInputMacro(name, type) \
995  itkSetDecoratedObjectInputMacro(name, type) \
996  itkGetDecoratedObjectInputMacro(name, type)
997 
999 #define itkSetMacro(name, type) \
1000  virtual void Set##name (const type _arg) \
1001  { \
1002  itkDebugMacro("setting " #name " to " << _arg); \
1003 CLANG_PRAGMA_PUSH \
1004 CLANG_SUPPRESS_Wfloat_equal \
1005  if ( this->m_##name != _arg ) \
1006  { \
1007  this->m_##name = _arg; \
1008  this->Modified(); \
1009  } \
1010 CLANG_PRAGMA_POP \
1011  }
1012 
1013 
1015 #define itkGetMacro(name, type) \
1016  virtual type Get##name () \
1017  { \
1018  return this->m_##name; \
1019  }
1020 
1021 
1025 #define itkGetConstMacro(name, type) \
1026  virtual type Get##name () const \
1027  { \
1028  return this->m_##name; \
1029  }
1030 
1031 
1036 #define itkGetConstReferenceMacro(name, type) \
1037  virtual const type &Get##name () const \
1038  { \
1039  return this->m_##name; \
1040  }
1041 
1042 
1047 #define itkSetEnumMacro(name, type) \
1048  virtual void Set##name (const type _arg) \
1049  { \
1050  itkDebugMacro( "setting " #name " to " << static_cast< long >( _arg ) ); \
1051  if ( this->m_##name != _arg ) \
1052  { \
1053  this->m_##name = _arg; \
1054  this->Modified(); \
1055  } \
1056  }
1057 
1058 
1063 #define itkGetEnumMacro(name, type) \
1064  virtual type Get##name () const \
1065  { \
1066  return this->m_##name; \
1067  }
1068 
1069 
1073 #define itkSetStringMacro(name) \
1074  virtual void Set##name (const char *_arg) \
1075  { \
1076  if ( _arg && ( _arg == this->m_##name ) ) { return; } \
1077  if ( _arg ) \
1078  { \
1079  this->m_##name = _arg; \
1080  } \
1081  else \
1082  { \
1083  this->m_##name = ""; \
1084  } \
1085  this->Modified(); \
1086  } \
1087  virtual void Set##name (const std::string & _arg) \
1088  { \
1089  this->Set##name( _arg.c_str() ); \
1090  } \
1091 
1092 
1093 
1097 #define itkGetStringMacro(name) \
1098  virtual const char *Get##name () const \
1099  { \
1100  return this->m_##name.c_str(); \
1101  }
1102 
1106 #define itkSetClampMacro(name, type, min, max) \
1107  virtual void Set##name (type _arg) \
1108  { \
1109  const type temp_extrema=( _arg < min ? min : ( _arg > max ? max : _arg ) );\
1110  itkDebugMacro("setting " << #name " to " << _arg); \
1111 CLANG_PRAGMA_PUSH \
1112 CLANG_SUPPRESS_Wfloat_equal \
1113  if ( this->m_##name != temp_extrema ) \
1114  { \
1115  this->m_##name = temp_extrema; \
1116  this->Modified(); \
1117  } \
1118 CLANG_PRAGMA_POP \
1119  }
1120 
1121 
1122 //NOTE: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
1127 #define itkSetObjectMacro(name, type) \
1128  virtual void Set##name (type * _arg) \
1129  { \
1130  itkDebugMacro("setting " << #name " to " << _arg); \
1131 CLANG_PRAGMA_PUSH \
1132 CLANG_SUPPRESS_Wfloat_equal \
1133  if ( this->m_##name != _arg ) \
1134  { \
1135  this->m_##name = _arg; \
1136  this->Modified(); \
1137  } \
1138 CLANG_PRAGMA_POP \
1139  }
1140 
1141 
1150 // NOTE: A class can use either itkGetModifiableObjectMacro
1151 // or itkGetObjectMacro, but not both.
1152 // A class can use either itkGetModifiableObjectMacro
1153 // or itkGetConstObjectMacro, but not both.
1154 // If the desired behavior is to only provide const
1155 // access to the itkObject ivar, then use itkGetConstObjectMacro,
1156 // else use itkGetModifiableObjectMacro for read/write access to
1157 // the ivar.
1158 // It is permissable to use both itkGetObjectMacro and itkGetConstObjectMacro
1159 // for backwards compatibility.
1160 // If the ITK_LEGACY_REMOVE=FALSE, then it is
1161 // permissable to use itkGetObjectMacro which
1162 // defines both signatures itk::GetXXX() and
1163 // itk::GetModifiableXXX()
1164 
1167 #define itkGetConstObjectMacro(name, type) \
1168  virtual const type * Get##name () const \
1169  { \
1170  return this->m_##name.GetPointer(); \
1171  }
1172 
1173 
1174 #if defined ( ITK_FUTURE_LEGACY_REMOVE )
1175 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1176 // flag. For now, this very advanced feature is only available
1177 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1178 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1179 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1180 # define itkGetObjectMacro(name, type) \
1181  virtual type * Get##name () \
1182  { \
1183  purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1184  }
1185 
1186 # define itkGetModifiableObjectMacro(name, type) \
1187  virtual type * GetModifiable##name () \
1188  { \
1189  return this->m_##name.GetPointer(); \
1190  } \
1191  itkGetConstObjectMacro(name, type)
1192 
1193 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1194 
1196 # define itkGetObjectMacro(name, type) \
1197  virtual type * Get##name () \
1198  { \
1199  return this->m_##name.GetPointer(); \
1200  }
1201 # define itkGetModifiableObjectMacro(name, type) \
1202  virtual type * GetModifiable##name () \
1203  { \
1204  return this->m_##name.GetPointer(); \
1205  } \
1206  itkGetConstObjectMacro(name, type) \
1207  itkGetObjectMacro(name, type)
1208 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1209 
1210 
1211 // For backwards compatibility define ITK_EXPORT to nothing
1212 #define ITK_EXPORT
1213 
1214 
1217 #define itkGetConstReferenceObjectMacro(name, type) \
1218  virtual const typename type::Pointer & Get##name () const \
1219  { \
1220  return this->m_##name; \
1221  }
1222 
1227 #define itkSetConstObjectMacro(name, type) \
1228  virtual void Set##name (const type * _arg) \
1229  { \
1230  itkDebugMacro("setting " << #name " to " << _arg); \
1231  if ( this->m_##name != _arg ) \
1232  { \
1233  this->m_##name = _arg; \
1234  this->Modified(); \
1235  } \
1236  }
1237 
1238 
1241 #define itkBooleanMacro(name) \
1242  virtual void name##On () \
1243  { \
1244  this->Set##name(true); \
1245  } \
1246  virtual void name##Off () \
1247  { \
1248  this->Set##name(false); \
1249  }
1250 
1251 
1255 #define itkSetVectorMacro(name, type, count) \
1256  virtual void Set##name(type data[]) \
1257  { \
1258  unsigned int i; \
1259  for ( i = 0; i < count; i++ ) \
1260  { \
1261 CLANG_PRAGMA_PUSH \
1262 CLANG_SUPPRESS_Wfloat_equal \
1263  if ( data[i] != this->m_##name[i] ) \
1264 CLANG_PRAGMA_POP \
1265  { \
1266  break; \
1267  } \
1268  } \
1269  if ( i < count ) \
1270  { \
1271  this->Modified(); \
1272  for ( i = 0; i < count; i++ ) \
1273  { \
1274  this->m_##name[i] = data[i]; \
1275  } \
1276  } \
1277  }
1278 
1279 
1282 #define itkGetVectorMacro(name, type, count) \
1283  virtual type * Get##name () const \
1284  { \
1285  return this->m_##name; \
1286  }
1287 
1292 #define itkGPUKernelClassMacro(kernel) \
1293 
1294 
1299 
1314 
1336 
1371 
1373