ITK  4.11.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 #if ITK_COMPILED_CXX_STANDARD_VERSION >= 201103L
192  #define ITK_HAS_CXX11_RVREF
193 #endif
194 
195 #if ! defined( ITK_FUTURE_LEGACY_REMOVE )
196  #if ITK_COMPILER_CXX_STATIC_ASSERT
197  #define ITK_HAS_CXX11_STATIC_ASSERT //NOTE DEPRECATED! should be ITK_COMPILER_CXX_STATIC_ASSERT
198  #endif
199 
200  #if ITK_COMPILER_CXX_DELETED_FUNCTIONS
201  #define ITK_DELETE_FUNCTION =delete //NOTE DEPRECATED! should be ITK_DELETED_FUNCTION
202  #else
203  #define ITK_DELETE_FUNCTION
204  #endif
205  #if ITK_COMPILER_CXX_ALIGNAS //NOTE DEPRECATED! should use ITK_COMPILER_CXX_ALIGNAS
206  // defined if the compiler supports C++11 alignas type specifier
207  #define ITK_HAS_CPP11_ALIGNAS
208  #else
209  #ifdef ITK_HAS_CPP11_ALIGNAS
210  #undef ITK_HAS_CPP11_ALIGNAS
211  #endif
212  #endif
213 #endif
214 
215 #if ITK_COMPILER_CXX_NOEXCEPT
216  #define ITK_NOEXCEPT_OR_THROW noexcept
217 #else
218  #define ITK_NOEXCEPT_OR_THROW throw()
219 #endif
220 
221 #if ITK_COMPILER_CXX_CONSTEXPR
222  #define ITK_CONSTEXPR_FUNC constexpr
223  #define ITK_CONSTEXPR_VAR constexpr
224 #else
225  #define ITK_CONSTEXPR_FUNC inline
226  #define ITK_CONSTEXPR_VAR const
227 #endif
228 
229 // Use "ITK_FALLTHROUGH;" to annotate deliberate fall-through in switches,
230 // use it analogously to "break;". The trailing semi-colon is required.
231 #if ITK_COMPILED_CXX_STANDARD_VERSION >= 201103L && defined(__has_warning)
232 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
233 # define ITK_FALLTHROUGH [[clang::fallthrough]]
234 # endif
235 #endif
236 
237 #ifndef ITK_FALLTHROUGH
238 # define ITK_FALLTHROUGH ((void)0)
239 #endif
240 
261 #define itkNewMacro(x) \
262  itkSimpleNewMacro(x) \
263  itkCreateAnotherMacro(x) \
264  itkCloneMacro(x)
265 
266 #define itkSimpleNewMacro(x) \
267  static Pointer New(void) \
268  { \
269  Pointer smartPtr = ::itk::ObjectFactory< x >::Create(); \
270  if ( smartPtr.GetPointer() == ITK_NULLPTR ) \
271  { \
272  smartPtr = new x; \
273  } \
274  smartPtr->UnRegister(); \
275  return smartPtr; \
276  }
277 
278 #define itkCreateAnotherMacro(x) \
279  virtual ::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE \
280  { \
281  ::itk::LightObject::Pointer smartPtr; \
282  smartPtr = x::New().GetPointer(); \
283  return smartPtr; \
284  }
285 
286 #define itkCloneMacro(x) \
287  Pointer Clone() const \
288  { \
289  Pointer rval = \
290  dynamic_cast<x *>(this->InternalClone().GetPointer()); \
291  return rval; \
292  }
293 
306 #define itkFactorylessNewMacro(x) \
307  static Pointer New(void) \
308  { \
309  Pointer smartPtr; \
310  x * rawPtr = new x; \
311  smartPtr = rawPtr; \
312  rawPtr->UnRegister(); \
313  return smartPtr; \
314  } \
315  virtual ::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE \
316  { \
317  ::itk::LightObject::Pointer smartPtr; \
318  smartPtr = x::New().GetPointer(); \
319  return smartPtr; \
320  }
321 
322 
323 //
324 // A macro to disallow the copy constructor and operator= functions
325 // This should be used in the private: declarations for a class
326 //
327 // ITK's paradigm for smart pointer and pipeline consistency
328 // prohibits the use of copy construction and operator= functions.
329 //
330 #define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
331  TypeName(const TypeName&) ITK_DELETED_FUNCTION; \
332  void operator=(const TypeName&) ITK_DELETED_FUNCTION
333 
336 #define itkTypeMacro(thisClass, superclass) \
337  virtual const char *GetNameOfClass() const ITK_OVERRIDE \
338  { \
339  return #thisClass; \
340  }
341 
342 #define itkTypeMacroNoParent(thisClass) \
343  virtual const char *GetNameOfClass() const \
344  { \
345  return #thisClass; \
346  }
347 
348 namespace itk
349 {
356 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char *);
358 
359 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char *);
360 
361 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char *);
362 
363 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char *);
364 
365 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char *);
366 } // end namespace itk
367 
371 #if defined( NDEBUG )
372 #define itkDebugMacro(x)
373 #define itkDebugStatement(x)
374 #else
375 #define itkDebugMacro(x) \
376  { \
377  if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
378  { \
379  std::ostringstream itkmsg; \
380  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
381  << this->GetNameOfClass() << " (" << this << "): " x \
382  << "\n\n"; \
383  ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() ); \
384  } \
385  }
386 
387 
388 //The itkDebugStatement is to be used to protect code that is only
389 //used in the itkDebugMacro
390 #define itkDebugStatement(x) x
391 #endif
392 
396 #define itkWarningMacro(x) \
397  { \
398  if ( ::itk::Object::GetGlobalWarningDisplay() ) \
399  { \
400  std::ostringstream itkmsg; \
401  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
402  << this->GetNameOfClass() << " (" << this << "): " x \
403  << "\n\n"; \
404  ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() ); \
405  } \
406  }
407 
408 
409 //The itkDebugStatement is to be used ot protect code that is only
410 //used in the itkDebugMacro
411 #define itkWarningStatement(x) x
412 
413 #if defined( ITK_CPP_FUNCTION )
414  #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( ITK_WRAPPING_PARSER )
415  #define ITK_LOCATION __FUNCSIG__
416  #elif defined( __GNUC__ )
417  #define ITK_LOCATION __PRETTY_FUNCTION__
418  #else
419  #define ITK_LOCATION __FUNCTION__
420  #endif
421 #else
422  #define ITK_LOCATION "unknown"
423 #endif
424 
425 #include "itkExceptionObject.h"
426 
430 #define itkExceptionMacro(x) \
431  { \
432  std::ostringstream message; \
433  message << "itk::ERROR: " << this->GetNameOfClass() \
434  << "(" << this << "): " x; \
435  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
436  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
437  }
438 
439 
440 #define itkGenericExceptionMacro(x) \
441  { \
442  std::ostringstream message; \
443  message << "itk::ERROR: " x; \
444  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
445  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
446  }
447 
448 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage) \
449 namespace itk { \
450 class newexcp : public parentexcp \
451 { \
452 public: \
453 newexcp( const char *file, unsigned int lineNumber ) : \
454 parentexcp( file, lineNumber ) \
455 { \
456  this->SetDescription( whatmessage ); \
457 } \
458 newexcp( const std::string & file, unsigned int lineNumber ) : \
459 parentexcp( file, lineNumber ) \
460 { \
461  this->SetDescription( whatmessage ); \
462 } \
463 itkTypeMacro(newexcp, parentexcp); \
464 }; \
465 }
466 
467 #define itkSpecializedExceptionMacro(exceptiontype) \
468  { \
469  ::itk::exceptiontype e_(__FILE__, __LINE__); \
470  e_.SetLocation(ITK_LOCATION); \
471  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
472  }
473 
474 #define itkSpecializedMessageExceptionMacro(exceptiontype,x) \
475  { \
476  ::itk::exceptiontype e_(__FILE__, __LINE__); \
477  std::ostringstream message; \
478  message << "itk::ERROR: " x; \
479  e_.SetDescription(message.str().c_str()); \
480  e_.SetLocation(ITK_LOCATION); \
481  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
482  }
483 
484 
485 #define itkGenericOutputMacro(x) \
486  { \
487  if ( ::itk::Object::GetGlobalWarningDisplay() ) \
488  { \
489  std::ostringstream itkmsg; \
490  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
491  x << "\n\n"; \
492  ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \
493  } \
494  }
495 
496 //----------------------------------------------------------------------------
497 // Macros for simplifying the use of logging
498 //
499 #define itkLogMacro(x, y) \
500  { \
501  if ( this->GetLogger() ) \
502  { \
503  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
504  } \
505  }
506 
507 #define itkLogMacroStatic(obj, x, y) \
508  { \
509  if ( obj->GetLogger() ) \
510  { \
511  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
512  } \
513  }
514 
515 //----------------------------------------------------------------------------
516 // Setup legacy code policy.
517 //
518 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted
519 // They may be used to completely remove legacy code or silence the
520 // warnings. The default is to warn about their use.
521 //
522 // Source files that test the legacy code may define ITK_LEGACY_TEST
523 // like this:
524 //
525 // #define ITK_LEGACY_TEST
526 // #include "itkClassWithDeprecatedMethod.h"
527 //
528 // in order to silence the warnings for calling deprecated methods.
529 // No other source files in ITK should call the methods since they are
530 // provided only for compatibility with older user code.
531 
532 // Define itkLegacyMacro to mark legacy methods where they are
533 // declared in their class. Example usage:
534 //
535 // // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
536 // itkLegacyMacro(void MyMethod());
537 //
538 // See below for what to do for the method definition.
539 #if defined( ITK_LEGACY_REMOVE )
540 #define itkLegacyMacro(method) /* no ';' */
541 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( ITK_WRAPPING_PARSER )
542 // Provide legacy methods with no warnings.
543 #define itkLegacyMacro(method) method
544 #else
545 // Setup compile-time warnings for uses of deprecated methods if
546 // possible on this compiler.
547 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) )
548 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) )
549 #elif defined( _MSC_VER )
550 #define itkLegacyMacro(method) __declspec(deprecated) method
551 #else
552 #define itkLegacyMacro(method) method
553 #endif
554 #endif
555 
556 // Macros to create runtime deprecation warning messages in function
557 // bodies. Example usage:
558 //
559 // #if !defined( ITK_LEGACY_REMOVE )
560 // void itkMyClass::MyOldMethod()
561 // {
562 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
563 // }
564 //
565 // void itkMyClass::MyMethod()
566 // {
567 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
568 // itkMyClass::MyOtherMethod);
569 // }
570 // #endif
571 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT )
572 #define itkLegacyBodyMacro(method, version)
573 #define itkLegacyReplaceBodyMacro(method, version, replace)
574 #define itkGenericLegacyBodyMacro(method, version)
575 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)
576 #else
577 #define itkLegacyBodyMacro(method, version) \
578  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
579 #define itkLegacyReplaceBodyMacro(method, version, replace) \
580  itkWarningMacro( \
581  #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
582  " instead.")
583 #define itkGenericLegacyBodyMacro(method, version) \
584  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
585 #define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
586  itkGenericOutputMacro( \
587  #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
588  " instead.")
589 #endif
590 
591 #if defined ( ITK_LEGACY_REMOVE )
592 #define ITK_TEMPLATE_TXX "error ITK_TEMPLATE_TXX is no longer a supported identifier, you should replace with ITK_MANUAL_INSTANTIATION as a replacement"
593 #else
594 #define ITK_TEMPLATE_TXX 1
595 #endif
596 
597 
598 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
599 // the cache lines. By aligning multi-threaded structures with the
600 // cache lines, false shared can be reduced, and performance
601 // increased.
602 #define ITK_CACHE_LINE_ALIGNMENT 64
603 
604 //
605 // itkPadStruct will add padding to a structure to ensure a minimum size
606 // for ensuring that adjacent structures do not share CACHE lines.
607 // Each struct will take up some multiple of cacheline sizes.
608 // This is particularly useful for arrays of thread private variables.
609 //
610 #define itkPadStruct( mincachesize, oldtype, newtype ) \
611  struct newtype: public oldtype \
612  { \
613  char _StructPadding[mincachesize - (sizeof(oldtype)%mincachesize) ]; \
614  };
615 
616 //
617 // itkAlignedTypedef is a macro which creates a new typedef to make a
618 // data structure aligned.
619 //
620 #if defined( ITK_HAS_GNU_ATTRIBUTE_ALIGNED )
621 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
622  typedef oldtype newtype __attribute__((aligned(alignment)))
623 #elif defined ( _MSC_VER )
624 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
625  typedef __declspec(align( alignment )) oldtype newtype
626 #else
627 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
628  typedef oldtype newtype
629 #endif
630 
631 //=============================================================================
632 /* Define a common way of declaring a templated function as a friend inside a class.
633  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
634 
635  The following templated function
636 
637  template <T>
638  T add(const T & a, const T & b);
639 
640  is declared as friend in some compilers as:
641 
642  class A
643  {
644  public:
645  friend Self add<Self>( const Self & a, const Self & b );
646  }
647 
648  while other compilers will do
649 
650  class A
651  {
652  public:
653  friend Self add<>( const Self & a, const Self & b );
654  }
655 
656  This characteristic of the compiler is checked by a TRY_COMPILE
657  command defined in Insight/CMake/itkTestFriendTemplatedFunction.cxx
658 
659 */
660 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_NULL_STRING )
661 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
662 #else
663 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_EMPTY_BRACKETS )
664 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
665 #else
666 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_TEMPLATE_ARGUMENTS )
667 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < T >
668 #endif
669 #endif
670 #endif
671 // THIS IS A TEMPORARY PATCH FOR Visual Studio 10. The correct solution must
672 // be implemented in Insight/CMake/itkTestFriendTemplatedFunction.cxx
673 #if ( defined ( _MSC_VER ) && ( _MSC_VER >= 1600 ) )
674 #ifdef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
675 #undef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
676 #endif
677 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
678 #endif
679 
680 //--------------------------------------------------------------------------------
681 // Helper macros for Template Meta-Programming techniques of for-loops
682 // unrolling
683 //--------------------------------------------------------------------------------
684 
685 //--------------------------------------------------------------------------------
686 // Macro that generates an unrolled for loop for assigning elements of one array
687 // to elements of another array The array are assumed to be of same length
688 // (dimension), and this is also assumed to be the value of NumberOfIterations.
689 // No verification of size is performed. Casting is perfomed as part of the
690 // assignment, by using the DestinationElementType as the casting type.
691 // Source and destination array types must have defined opearator[] in their
692 // API.
693 #define itkForLoopAssignmentMacro(DestinationType, \
694  SourceType, \
695  DestinationElementType, \
696  DestinationArray, \
697  SourceArray, \
698  NumberOfIterations) \
699  for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
700  { \
701  DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
702  }
703 
704 //--------------------------------------------------------------------------------
705 // Macro that generates an unrolled for loop for rounding and assigning
706 // elements of one array to elements of another array The array are assumed to
707 // be of same length (dimension), and this is also assumed to be the value of
708 // NumberOfIterations. No verification of size is performed. Casting is
709 // perfomed as part of the assignment, by using the DestinationElementType as
710 // the casting type.
711 // Source and destination array types must have defined opearator[] in their
712 // API.
713 #define itkForLoopRoundingAndAssignmentMacro(DestinationType, \
714  Sourcrnd_halfintup, \
715  DestinationElementType, \
716  DestinationArray, \
717  SourceArray, \
718  NumberOfIterations) \
719  for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
720  { \
721  DestinationArray[i] = itk::Math::Round< DestinationElementType >(SourceArray[i]); \
722  }
723 
724 // end of Template Meta Programming helper macros
725 
726 #ifndef NDEBUG
727 
728 #ifdef _POSIX_SOURCE
729 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
730 #else
731 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
732 #endif
733 
734 #else
735 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
736 #endif
737 
738 #define itkAssertOrThrowMacro(test, message) \
739  if ( !( test ) ) \
740  { \
741  std::ostringstream msgstr; \
742  msgstr << message; \
743  itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
744  }
745 
746 #ifndef NDEBUG
747 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
748 #else
749 #define itkAssertInDebugAndIgnoreInReleaseMacro(X)
750 #endif
751 
752 #ifdef ITKV3_COMPATIBILITY
753 // As of MSVS++ 7.1 and greater, typename is supported in templates
754 // All ITKv4 compilers support the typename keyword, but this is
755 // needed to ease transition from ITKv3.
756 #define ITK_TYPENAME typename
757 #endif
758 
762 template <typename TTarget, typename TSource>
763 TTarget itkDynamicCastInDebugMode(TSource x)
764 {
765 #ifndef NDEBUG
766  if(x == 0)
767  {
768  return 0;
769  }
770  TTarget rval = dynamic_cast<TTarget>(x);
771  if(rval == 0)
772  {
773  itkGenericExceptionMacro(<< "Failed dynamic cast to "
774  << typeid(TTarget).name()
775  << " object type = "
776  << x->GetNameOfClass());
777  }
778  return rval;
779 #else
780  return static_cast<TTarget>(x);
781 #endif
782 }
784 
785 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
786 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
787 // !! The ITK Get/Set Macros for various types !!
788 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
789 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
804 #if defined(__GNUC__) && ((__GNUC__ * 100) + __GNUC_MINOR__ ) < 405 && !defined( __clang__ ) && !defined( __INTEL_COMPILER )
805 # define itkStaticConstMacro(name,type,value) enum { name = value }
806 #else
807 # define itkStaticConstMacro(name,type,value) static ITK_CONSTEXPR_VAR type name = value
808 #endif
809 
810 #define itkGetStaticConstMacro(name) (Self::name)
811 
813 #define itkSetInputMacro(name, type) \
814  virtual void Set##name(const type *_arg) \
815  { \
816  itkDebugMacro("setting input " #name " to " << _arg); \
817  if ( _arg != itkDynamicCastInDebugMode< type * >( this->ProcessObject::GetInput(#name) ) ) \
818  { \
819  this->ProcessObject::SetInput( #name, const_cast< type * >( _arg ) ); \
820  this->Modified(); \
821  } \
822  }
823 
824 
826 #define itkGetInputMacro(name, type) \
827  virtual const type * Get##name() const \
828  { \
829  itkDebugMacro( "returning input " << #name " of " << this->ProcessObject::GetInput(#name) ); \
830  return itkDynamicCastInDebugMode< const type * >( this->ProcessObject::GetInput(#name) ); \
831  }
832 
833 
835 #define itkSetDecoratedInputMacro(name, type) \
836  virtual void Set##name##Input(const SimpleDataObjectDecorator< type > *_arg) \
837  { \
838  itkDebugMacro("setting input " #name " to " << _arg); \
839  if ( _arg != itkDynamicCastInDebugMode< SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
840  { \
841  this->ProcessObject::SetInput( #name, const_cast< SimpleDataObjectDecorator< type > * >( _arg ) ); \
842  this->Modified(); \
843  } \
844  } \
845  virtual void Set##name(const SimpleDataObjectDecorator< type > *_arg) \
846  { \
847  this->Set##name##Input(_arg); \
848  } \
849  virtual void Set##name(const type &_arg) \
850  { \
851  typedef SimpleDataObjectDecorator< type > DecoratorType; \
852  itkDebugMacro("setting input " #name " to " << _arg); \
853  const DecoratorType *oldInput = \
854  itkDynamicCastInDebugMode< const DecoratorType * >( \
855  this->ProcessObject::GetInput(#name) ); \
856 CLANG_PRAGMA_PUSH \
857 CLANG_SUPPRESS_Wfloat_equal \
858  if ( oldInput && oldInput->Get() == _arg ) \
859 CLANG_PRAGMA_POP \
860  { \
861  return; \
862  } \
863  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
864  newInput->Set(_arg); \
865  this->Set##name##Input(newInput); \
866  }
867 
868 
870 #define itkGetDecoratedInputMacro(name, type) \
871  virtual const SimpleDataObjectDecorator< type > * Get##name##Input() const \
872  { \
873  itkDebugMacro( "returning input " << #name " of " << this->ProcessObject::GetInput(#name) ); \
874  return itkDynamicCastInDebugMode< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
875  } \
876  virtual const type & Get##name() const \
877  { \
878  itkDebugMacro("Getting input " #name); \
879  typedef SimpleDataObjectDecorator< type > DecoratorType; \
880  const DecoratorType *input = \
881  itkDynamicCastInDebugMode< const DecoratorType * >( \
882  this->ProcessObject::GetInput(#name) ); \
883  if( input == ITK_NULLPTR ) \
884  { \
885  itkExceptionMacro(<<"input" #name " is not set"); \
886  } \
887  return input->Get(); \
888  }
889 
890 
893 #define itkSetGetDecoratedInputMacro(name, type) \
894  itkSetDecoratedInputMacro(name, type) \
895  itkGetDecoratedInputMacro(name, type)
896 
901 #define itkSetDecoratedObjectInputMacro(name, type) \
902  virtual void Set##name##Input(const DataObjectDecorator< type > *_arg) \
903  { \
904  itkDebugMacro("setting input " #name " to " << _arg); \
905  if ( _arg != itkDynamicCastInDebugMode< DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
906  { \
907  this->ProcessObject::SetInput( #name, const_cast< DataObjectDecorator< type > * >( _arg ) ); \
908  this->Modified(); \
909  } \
910  } \
911  virtual void Set##name(const type * _arg) \
912  { \
913  typedef DataObjectDecorator< type > DecoratorType; \
914  itkDebugMacro("setting input " #name " to " << _arg); \
915  const DecoratorType *oldInput = \
916  itkDynamicCastInDebugMode< const DecoratorType * >( \
917  this->ProcessObject::GetInput(#name) ); \
918  if ( oldInput && oldInput->Get() == _arg ) \
919  { \
920  return; \
921  } \
922  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
923  newInput->Set(_arg); \
924  this->Set##name##Input(newInput); \
925  }
926 
927 
932 #define itkGetDecoratedObjectInputMacro(name, type) \
933  virtual const DataObjectDecorator< type > * Get##name##Input() const \
934  { \
935  itkDebugMacro( "returning input " << #name " of "<< this->ProcessObject::GetInput(#name) ); \
936  return itkDynamicCastInDebugMode< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
937  } \
938  virtual const type * Get##name() const \
939  { \
940  itkDebugMacro("Getting input " #name); \
941  typedef DataObjectDecorator< type > DecoratorType; \
942  const DecoratorType *input = \
943  itkDynamicCastInDebugMode< const DecoratorType * >( \
944  this->ProcessObject::GetInput(#name) ); \
945  if( input == ITK_NULLPTR ) \
946  { \
947  return ITK_NULLPTR; \
948  } \
949  return input->Get(); \
950  }
951 
952 
955 #define itkSetGetDecoratedObjectInputMacro(name, type) \
956  itkSetDecoratedObjectInputMacro(name, type) \
957  itkGetDecoratedObjectInputMacro(name, type)
958 
960 #define itkSetMacro(name, type) \
961  virtual void Set##name (const type _arg) \
962  { \
963  itkDebugMacro("setting " #name " to " << _arg); \
964 CLANG_PRAGMA_PUSH \
965 CLANG_SUPPRESS_Wfloat_equal \
966  if ( this->m_##name != _arg ) \
967  { \
968  this->m_##name = _arg; \
969  this->Modified(); \
970  } \
971 CLANG_PRAGMA_POP \
972  }
973 
974 
976 #define itkGetMacro(name, type) \
977  virtual type Get##name () \
978  { \
979  return this->m_##name; \
980  }
981 
982 
986 #define itkGetConstMacro(name, type) \
987  virtual type Get##name () const \
988  { \
989  return this->m_##name; \
990  }
991 
992 
997 #define itkGetConstReferenceMacro(name, type) \
998  virtual const type &Get##name () const \
999  { \
1000  return this->m_##name; \
1001  }
1002 
1003 
1008 #define itkSetEnumMacro(name, type) \
1009  virtual void Set##name (const type _arg) \
1010  { \
1011  itkDebugMacro( "setting " #name " to " << static_cast< long >( _arg ) ); \
1012  if ( this->m_##name != _arg ) \
1013  { \
1014  this->m_##name = _arg; \
1015  this->Modified(); \
1016  } \
1017  }
1018 
1019 
1024 #define itkGetEnumMacro(name, type) \
1025  virtual type Get##name () const \
1026  { \
1027  return this->m_##name; \
1028  }
1029 
1030 
1034 #define itkSetStringMacro(name) \
1035  virtual void Set##name (const char *_arg) \
1036  { \
1037  if ( _arg && ( _arg == this->m_##name ) ) { return; } \
1038  if ( _arg ) \
1039  { \
1040  this->m_##name = _arg; \
1041  } \
1042  else \
1043  { \
1044  this->m_##name = ""; \
1045  } \
1046  this->Modified(); \
1047  } \
1048  virtual void Set##name (const std::string & _arg) \
1049  { \
1050  this->Set##name( _arg.c_str() ); \
1051  } \
1052 
1053 
1054 
1058 #define itkGetStringMacro(name) \
1059  virtual const char *Get##name () const \
1060  { \
1061  return this->m_##name.c_str(); \
1062  }
1063 
1067 #define itkSetClampMacro(name, type, min, max) \
1068  virtual void Set##name (type _arg) \
1069  { \
1070  const type temp_extrema=( _arg < min ? min : ( _arg > max ? max : _arg ) );\
1071  itkDebugMacro("setting " << #name " to " << _arg); \
1072 CLANG_PRAGMA_PUSH \
1073 CLANG_SUPPRESS_Wfloat_equal \
1074  if ( this->m_##name != temp_extrema ) \
1075  { \
1076  this->m_##name = temp_extrema; \
1077  this->Modified(); \
1078  } \
1079 CLANG_PRAGMA_POP \
1080  }
1081 
1082 
1083 //NOTE: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
1088 #define itkSetObjectMacro(name, type) \
1089  virtual void Set##name (type * _arg) \
1090  { \
1091  itkDebugMacro("setting " << #name " to " << _arg); \
1092 CLANG_PRAGMA_PUSH \
1093 CLANG_SUPPRESS_Wfloat_equal \
1094  if ( this->m_##name != _arg ) \
1095  { \
1096  this->m_##name = _arg; \
1097  this->Modified(); \
1098  } \
1099 CLANG_PRAGMA_POP \
1100  }
1101 
1102 
1111 // NOTE: A class can use either itkGetModifiableObjectMacro
1112 // or itkGetObjectMacro, but not both.
1113 // A class can use either itkGetModifiableObjectMacro
1114 // or itkGetConstObjectMacro, but not both.
1115 // If the desired behavior is to only provide const
1116 // access to the itkObject ivar, then use itkGetConstObjectMacro,
1117 // else use itkGetModifiableObjectMacro for read/write access to
1118 // the ivar.
1119 // It is permissable to use both itkGetObjectMacro and itkGetConstObjectMacro
1120 // for backwards compatibility.
1121 // If the ITK_LEGACY_REMOVE=FALSE, then it is
1122 // permissable to use itkGetObjectMacro which
1123 // defines both signatures itk::GetXXX() and
1124 // itk::GetModifiableXXX()
1125 
1128 #define itkGetConstObjectMacro(name, type) \
1129  virtual const type * Get##name () const \
1130  { \
1131  return this->m_##name.GetPointer(); \
1132  }
1133 
1134 
1135 #if defined ( ITK_FUTURE_LEGACY_REMOVE )
1136 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1137 // flag. For now, this very advanced feature is only available
1138 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1139 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1140 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1141 # define itkGetObjectMacro(name, type) \
1142  virtual type * Get##name () \
1143  { \
1144  purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1145  }
1146 
1147 # define itkGetModifiableObjectMacro(name, type) \
1148  virtual type * GetModifiable##name () \
1149  { \
1150  return this->m_##name.GetPointer(); \
1151  } \
1152  itkGetConstObjectMacro(name, type)
1153 
1154 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1155 
1157 # define itkGetObjectMacro(name, type) \
1158  virtual type * Get##name () \
1159  { \
1160  return this->m_##name.GetPointer(); \
1161  }
1162 # define itkGetModifiableObjectMacro(name, type) \
1163  virtual type * GetModifiable##name () \
1164  { \
1165  return this->m_##name.GetPointer(); \
1166  } \
1167  itkGetConstObjectMacro(name, type) \
1168  itkGetObjectMacro(name, type)
1169 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1170 
1171 
1172 // For backwards compatibility define ITK_EXPORT to nothing
1173 #define ITK_EXPORT
1174 
1175 
1178 #define itkGetConstReferenceObjectMacro(name, type) \
1179  virtual const typename type::Pointer & Get##name () const \
1180  { \
1181  return this->m_##name; \
1182  }
1183 
1188 #define itkSetConstObjectMacro(name, type) \
1189  virtual void Set##name (const type * _arg) \
1190  { \
1191  itkDebugMacro("setting " << #name " to " << _arg); \
1192  if ( this->m_##name != _arg ) \
1193  { \
1194  this->m_##name = _arg; \
1195  this->Modified(); \
1196  } \
1197  }
1198 
1199 
1202 #define itkBooleanMacro(name) \
1203  virtual void name##On () \
1204  { \
1205  this->Set##name(true); \
1206  } \
1207  virtual void name##Off () \
1208  { \
1209  this->Set##name(false); \
1210  }
1211 
1212 
1216 #define itkSetVectorMacro(name, type, count) \
1217  virtual void Set##name(type data[]) \
1218  { \
1219  unsigned int i; \
1220  for ( i = 0; i < count; i++ ) \
1221  { \
1222 CLANG_PRAGMA_PUSH \
1223 CLANG_SUPPRESS_Wfloat_equal \
1224  if ( data[i] != this->m_##name[i] ) \
1225 CLANG_PRAGMA_POP \
1226  { \
1227  break; \
1228  } \
1229  } \
1230  if ( i < count ) \
1231  { \
1232  this->Modified(); \
1233  for ( i = 0; i < count; i++ ) \
1234  { \
1235  this->m_##name[i] = data[i]; \
1236  } \
1237  } \
1238  }
1239 
1240 
1243 #define itkGetVectorMacro(name, type, count) \
1244  virtual type * Get##name () const \
1245  { \
1246  return this->m_##name; \
1247  }
1248 
1253 #define itkGPUKernelClassMacro(kernel) \
1254 
1255 
1260 
1275 
1297 
1332 
1334