ITK  4.6.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  * ITK only supports MSVC++ 7.1 and greater
70  * MSVC++ 11.0 _MSC_VER = 1700
71  * MSVC++ 10.0 _MSC_VER = 1600
72  * MSVC++ 9.0 _MSC_VER = 1500
73  * MSVC++ 8.0 _MSC_VER = 1400
74  * MSVC++ 7.1 _MSC_VER = 1310
75  * MSVC++ 7.0 _MSC_VER = 1300
76  * MSVC++ 6.0 _MSC_VER = 1200
77  * MSVC++ 5.0 _MSC_VER = 1100
78 */
79 #if defined( _MSC_VER ) && ( _MSC_VER < 1310 )
80 //#error "_MSC_VER < 1310 (MSVC++ 7.1) not supported under ITKv4"
81 #endif
82 #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC < 0x590 )
83 #error "__SUNPRO_CC < 0x590 not supported under ITKv4"
84 #endif
85 #if defined( __CYGWIN__ )
86 #error "The Cygwin compiler is not supported in ITKv4 and above"
87 #endif
88 #if defined( __BORLANDC__ )
89 #error "The Borland C compiler is not supported in ITKv4 and above"
90 #endif
91 #if defined( __MWERKS__ )
92 #error "The MetroWerks compiler is not supported in ITKv4 and above"
93 #endif
94 #if defined( __GNUC__ ) && ( __GNUC__ < 3 )
95 #error "The __GNUC__ version 2.95 compiler is not supprted under ITKv4 and above"
96 #if defined( __sgi )
97 //This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
98 //TODO: At some future point, it may be necessary to
99 //define a minimum __sgi version that will work.
100 #error "The __sgi compiler is not supprted under ITKv4 and above"
101 #endif
102 #endif
103 
104 // Setup symbol exports
105 #if defined( _WIN32 ) || defined ( WIN32 )
106  #define ITK_ABI_IMPORT __declspec(dllimport)
107  #define ITK_ABI_EXPORT __declspec(dllexport)
108  #define ITK_ABI_HIDDEN
109 #else
110  #if __GNUC__ >= 4
111  #define ITK_ABI_IMPORT __attribute__ ((visibility ("default")))
112  #define ITK_ABI_EXPORT __attribute__ ((visibility ("default")))
113  #define ITK_ABI_HIDDEN __attribute__ ((visibility ("hidden")))
114  #else
115  #define ITK_ABI_IMPORT
116  #define ITK_ABI_EXPORT
117  #define ITK_ABI_HIDDEN
118  #endif
119 #endif
120 
121 #if __cplusplus >= 201103L
122 // In c++11 the override keyword allows you to explicity define that a function
123 // is intended to override the base-class version. This makes the code more
124 // managable and fixes a set of common hard-to-find bugs.
125 #define ITK_OVERRIDE override
126 // In c++11 there is an explicit nullptr type that introduces a new keyword to
127 // serve as a distinguished null pointer constant: nullptr. It is of type
128 // nullptr_t, which is implicitly convertible and comparable to any pointer type
129 // or pointer-to-member type. It is not implicitly convertible or comparable to
130 // integral types, except for bool.
131 #define ITK_NULLPTR nullptr
132 #else
133 #define ITK_OVERRIDE
134 #define ITK_NULLPTR NULL
135 #endif
136 
137 
158 #define itkNewMacro(x) \
159  itkSimpleNewMacro(x) \
160  itkCreateAnotherMacro(x) \
161  itkCloneMacro(x)
162 
163 #define itkSimpleNewMacro(x) \
164  static Pointer New(void) \
165  { \
166  Pointer smartPtr = ::itk::ObjectFactory< x >::Create(); \
167  if ( smartPtr.GetPointer() == ITK_NULLPTR ) \
168  { \
169  smartPtr = new x; \
170  } \
171  smartPtr->UnRegister(); \
172  return smartPtr; \
173  }
174 
175 #define itkCreateAnotherMacro(x) \
176  virtual::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE \
177  { \
178  ::itk::LightObject::Pointer smartPtr; \
179  smartPtr = x::New().GetPointer(); \
180  return smartPtr; \
181  }
182 
183 #define itkCloneMacro(x) \
184  Pointer Clone() const \
185  { \
186  Pointer rval = \
187  dynamic_cast<x *>(this->InternalClone().GetPointer()); \
188  return rval; \
189  }
190 
207 #define itkFactorylessNewMacro(x) \
208  static Pointer New(void) \
209  { \
210  Pointer smartPtr; \
211  x * rawPtr = new x; \
212  smartPtr = rawPtr; \
213  rawPtr->UnRegister(); \
214  return smartPtr; \
215  } \
216  virtual::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE \
217  { \
218  ::itk::LightObject::Pointer smartPtr; \
219  smartPtr = x::New().GetPointer(); \
220  return smartPtr; \
221  }
222 
223 
226 #define itkTypeMacro(thisClass, superclass) \
227  virtual const char *GetNameOfClass() const \
228  { \
229  return #thisClass; \
230  }
231 
232 namespace itk
233 {
240 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char *);
242 
243 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char *);
244 
245 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char *);
246 
247 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char *);
248 
249 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char *);
250 } // end namespace itk
251 
255 #if defined( NDEBUG )
256 #define itkDebugMacro(x)
257 #define itkDebugStatement(x)
258 #else
259 #define itkDebugMacro(x) \
260  { \
261  if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
262  { \
263  std::ostringstream itkmsg; \
264  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
265  << this->GetNameOfClass() << " (" << this << "): " x \
266  << "\n\n"; \
267  ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() ); \
268  } \
269  }
270 
271 
272 //The itkDebugStatement is to be used to protect code that is only
273 //used in the itkDebugMacro
274 #define itkDebugStatement(x) x
275 #endif
276 
280 #define itkWarningMacro(x) \
281  { \
282  if ( ::itk::Object::GetGlobalWarningDisplay() ) \
283  { \
284  std::ostringstream itkmsg; \
285  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
286  << this->GetNameOfClass() << " (" << this << "): " x \
287  << "\n\n"; \
288  ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() ); \
289  } \
290  }
291 
292 
293 //The itkDebugStatement is to be used ot protect code that is only
294 //used in the itkDebugMacro
295 #define itkWarningStatement(x) x
296 
297 #if defined( ITK_CPP_FUNCTION )
298  #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( CABLE_CONFIGURATION ) \
299  && !defined( __GCCXML__ )
300  #define ITK_LOCATION __FUNCSIG__
301  #elif defined( __GNUC__ )
302  #define ITK_LOCATION __PRETTY_FUNCTION__
303  #else
304  #define ITK_LOCATION __FUNCTION__
305  #endif
306 #else
307  #define ITK_LOCATION "unknown"
308 #endif
309 
310 #include "itkExceptionObject.h"
311 
315 #define itkExceptionMacro(x) \
316  { \
317  std::ostringstream message; \
318  message << "itk::ERROR: " << this->GetNameOfClass() \
319  << "(" << this << "): " x; \
320  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
321  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
322  }
323 
324 
325 #define itkGenericExceptionMacro(x) \
326  { \
327  std::ostringstream message; \
328  message << "itk::ERROR: " x; \
329  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
330  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
331  }
332 
333 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage) \
334 namespace itk { \
335 class newexcp : public parentexcp \
336 { \
337 public: \
338 newexcp( const char *file, unsigned int lineNumber ) : \
339 parentexcp( file, lineNumber ) \
340 { \
341  this->SetDescription( whatmessage ); \
342 } \
343 newexcp( const std::string & file, unsigned int lineNumber ) : \
344 parentexcp( file, lineNumber ) \
345 { \
346  this->SetDescription( whatmessage ); \
347 } \
348 itkTypeMacro(newexcp, parentexcp); \
349 }; \
350 }
351 
352 #define itkSpecializedExceptionMacro(exceptiontype) \
353  { \
354  ::itk::exceptiontype e_(__FILE__, __LINE__); \
355  e_.SetLocation(ITK_LOCATION); \
356  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
357  }
358 
359 #define itkSpecializedMessageExceptionMacro(exceptiontype,x) \
360  { \
361  ::itk::exceptiontype e_(__FILE__, __LINE__); \
362  std::ostringstream message; \
363  message << "itk::ERROR: " x; \
364  e_.SetDescription(message.str().c_str()); \
365  e_.SetLocation(ITK_LOCATION); \
366  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
367  }
368 
369 
370 #define itkGenericOutputMacro(x) \
371  { \
372  if ( ::itk::Object::GetGlobalWarningDisplay() ) \
373  { \
374  std::ostringstream itkmsg; \
375  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
376  x << "\n\n"; \
377  ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \
378  } \
379  }
380 
381 //----------------------------------------------------------------------------
382 // Macros for simplifying the use of logging
383 //
384 #define itkLogMacro(x, y) \
385  { \
386  if ( this->GetLogger() ) \
387  { \
388  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
389  } \
390  }
391 
392 #define itkLogMacroStatic(obj, x, y) \
393  { \
394  if ( obj->GetLogger() ) \
395  { \
396  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
397  } \
398  }
399 
400 //----------------------------------------------------------------------------
401 // Setup legacy code policy.
402 //
403 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted
404 // They may be used to completely remove legacy code or silence the
405 // warnings. The default is to warn about their use.
406 //
407 // Source files that test the legacy code may define ITK_LEGACY_TEST
408 // like this:
409 //
410 // #define ITK_LEGACY_TEST
411 // #include "itkClassWithDeprecatedMethod.h"
412 //
413 // in order to silence the warnings for calling deprecated methods.
414 // No other source files in ITK should call the methods since they are
415 // provided only for compatibility with older user code.
416 
417 // Define itkLegacyMacro to mark legacy methods where they are
418 // declared in their class. Example usage:
419 //
420 // // @deprecated Replaced by MyOtherMethod() as of ITK 2.0.
421 // itkLegacyMacro(void MyMethod());
422 #if defined( ITK_LEGACY_REMOVE )
423 #define itkLegacyMacro(method) /* no ';' */
424 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( __GCCXML__ )
425 // Provide legacy methods with no warnings.
426 #define itkLegacyMacro(method) method
427 #else
428 // Setup compile-time warnings for uses of deprecated methods if
429 // possible on this compiler.
430 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) )
431 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) )
432 #elif defined( _MSC_VER )
433 #define itkLegacyMacro(method) __declspec(deprecated) method
434 #else
435 #define itkLegacyMacro(method) method
436 #endif
437 #endif
438 
439 // Macros to create runtime deprecation warning messages in function
440 // bodies. Example usage:
441 //
442 // void itkMyClass::MyOldMethod()
443 // {
444 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
445 // }
446 //
447 // void itkMyClass::MyMethod()
448 // {
449 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
450 // itkMyClass::MyOtherMethod);
451 // }
452 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT )
453 #define itkLegacyBodyMacro(method, version)
454 #define itkLegacyReplaceBodyMacro(method, version, replace)
455 #define itkGenericLegacyBodyMacro(method, version)
456 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)
457 #else
458 #define itkLegacyBodyMacro(method, version) \
459  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
460 #define itkLegacyReplaceBodyMacro(method, version, replace) \
461  itkWarningMacro( \
462  #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
463  " instead.")
464 #define itkGenericLegacyBodyMacro(method, version) \
465  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
466 #define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
467  itkGenericOutputMacro( \
468  #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
469  " instead.")
470 #endif
471 
472 #if defined ( ITK_LEGACY_REMOVE )
473 #define ITK_TEMPLATE_TXX "error ITK_TEMPLATE_TXX is no longer a supported identifier, you should replace with ITK_MANUAL_INSTANTIATION as a replacement"
474 #else
475 #define ITK_TEMPLATE_TXX 1
476 #endif
477 
478 
479 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
480 // the cache lines. By aligning multi-threaded structures with the
481 // cache lines, false shared can be reduced, and performance
482 // increased.
483 #define ITK_CACHE_LINE_ALIGNMENT 64
484 
485 //
486 // itkPadStruct will add padding to a structure to ensure a minimum size
487 // for ensuring that adjacent structures do not share CACHE lines.
488 // Each struct will take up some multiple of cacheline sizes.
489 // This is particularly useful for arrays of thread private variables.
490 //
491 #define itkPadStruct( mincachesize, oldtype, newtype ) \
492  struct newtype: public oldtype \
493  { \
494  char _StructPadding[mincachesize - (sizeof(oldtype)%mincachesize) ]; \
495  };
496 
497 //
498 // itkAlignedTypedef is a macro which creates a new typedef to make a
499 // data structure aligned.
500 //
501 #if defined ( ITK_HAS_CPP11_ALIGNAS )
502 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
503  typedef oldtype newtype alignas(alignment)
504 #elif defined( ITK_HAS_GNU_ATTRIBUTE_ALIGNED )
505 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
506  typedef oldtype newtype __attribute__((aligned(alignment)))
507 #elif defined ( _MSC_VER )
508 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
509  typedef __declspec(align( alignment )) struct oldtype newtype
510 #else
511 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
512  typedef oldtype newtype
513 #endif
514 
515 //=============================================================================
516 /* Define a common way of declaring a templated function as a friend inside a class.
517  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
518 
519  The following templated function
520 
521  template <T>
522  T add(const T & a, const T & b);
523 
524  is declared as friend in some compilers as:
525 
526  class A
527  {
528  public:
529  friend Self add<Self>( const Self & a, const Self & b );
530  }
531 
532  while other compilers will do
533 
534  class A
535  {
536  public:
537  friend Self add<>( const Self & a, const Self & b );
538  }
539 
540  This characteristic of the compiler is checked by a TRY_COMPILE
541  command defined in Insight/CMake/itkTestFriendTemplatedFunction.cxx
542 
543 */
544 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_NULL_STRING )
545 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
546 #else
547 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_EMPTY_BRACKETS )
548 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
549 #else
550 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_TEMPLATE_ARGUMENTS )
551 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < T >
552 #endif
553 #endif
554 #endif
555 // THIS IS A TEMPORARY PATCH FOR Visual Studio 10. The correct solution must
556 // be implemented in Insight/CMake/itkTestFriendTemplatedFunction.cxx
557 #if ( defined ( _MSC_VER ) && ( _MSC_VER >= 1600 ) )
558 #ifdef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
559 #undef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
560 #endif
561 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
562 #endif
563 
564 //--------------------------------------------------------------------------------
565 // Helper macros for Template Meta-Programming techniques of for-loops
566 // unrolling
567 //--------------------------------------------------------------------------------
568 
569 //--------------------------------------------------------------------------------
570 // Macro that generates an unrolled for loop for assigning elements of one array
571 // to elements of another array The array are assumed to be of same length
572 // (dimension), and this is also assumed to be the value of NumberOfIterations.
573 // No verification of size is performed. Casting is perfomed as part of the
574 // assignment, by using the DestinationElementType as the casting type.
575 // Source and destination array types must have defined opearator[] in their
576 // API.
577 #define itkForLoopAssignmentMacro(DestinationType, \
578  SourceType, \
579  DestinationElementType, \
580  DestinationArray, \
581  SourceArray, \
582  NumberOfIterations) \
583  for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
584  { \
585  DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
586  }
587 
588 //--------------------------------------------------------------------------------
589 // Macro that generates an unrolled for loop for rounding and assigning
590 // elements of one array to elements of another array The array are assumed to
591 // be of same length (dimension), and this is also assumed to be the value of
592 // NumberOfIterations. No verification of size is performed. Casting is
593 // perfomed as part of the assignment, by using the DestinationElementType as
594 // the casting type.
595 // Source and destination array types must have defined opearator[] in their
596 // API.
597 #define itkForLoopRoundingAndAssignmentMacro(DestinationType, \
598  Sourcrnd_halfintup, \
599  DestinationElementType, \
600  DestinationArray, \
601  SourceArray, \
602  NumberOfIterations) \
603  for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
604  { \
605  DestinationArray[i] = itk::Math::Round< DestinationElementType >(SourceArray[i]); \
606  }
607 
608 // end of Template Meta Programming helper macros
609 
610 #ifndef NDEBUG
611 
612 #ifdef _POSIX_SOURCE
613 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
614 #else
615 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
616 #endif
617 
618 #else
619 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
620 #endif
621 
622 #define itkAssertOrThrowMacro(test, message) \
623  if ( !( test ) ) \
624  { \
625  std::ostringstream msgstr; \
626  msgstr << message; \
627  itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
628  }
629 
630 #ifndef NDEBUG
631 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
632 #else
633 #define itkAssertInDebugAndIgnoreInReleaseMacro(X)
634 #endif
635 
636 #ifdef ITKV3_COMPATIBILITY
637 // As of MSVS++ 7.1 and greater, typename is supported in templates
638 // All ITKv4 compilers support the typename keyword, but this is
639 // needed to ease transition from ITKv3.
640 #define ITK_TYPENAME typename
641 #endif
642 
646 template <typename TTarget, typename TSource>
647 TTarget itkDynamicCastInDebugMode(TSource x)
648 {
649 #ifndef NDEBUG
650  if(x == 0)
651  {
652  return 0;
653  }
654  TTarget rval = dynamic_cast<TTarget>(x);
655  if(rval == 0)
656  {
657  itkGenericExceptionMacro(<< "Failed dynamic cast to "
658  << typeid(TTarget).name()
659  << " object type = "
660  << x->GetNameOfClass());
661  }
662  return rval;
663 #else
664  return static_cast<TTarget>(x);
665 #endif
666 }
668 
669 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
670 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
671 // !! The ITK Get/Set Macros for various types !!
672 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
673 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
674 //This is probably better, but requires a lot of extra work
675 //for gettting ExplicitInstantiation to work properly. \#define
676 // itkStaticConstMacro(name, type, value) static const type name = value
677 #define itkStaticConstMacro(name, type, value) enum { name = value }
678 
679 #define itkGetStaticConstMacro(name) (Self::name)
680 
682 #define itkSetInputMacro(name, type) \
683  virtual void Set##name(const type *_arg) \
684  { \
685  itkDebugMacro("setting input " #name " to " << _arg); \
686  if ( _arg != itkDynamicCastInDebugMode< type * >( this->ProcessObject::GetInput(#name) ) ) \
687  { \
688  this->ProcessObject::SetInput( #name, const_cast< type * >( _arg ) ); \
689  this->Modified(); \
690  } \
691  }
692 
693 
695 #define itkGetInputMacro(name, type) \
696  virtual const type * Get##name() const \
697  { \
698  itkDebugMacro( "returning input " << #name " of " << this->ProcessObject::GetInput(#name) ); \
699  return itkDynamicCastInDebugMode< const type * >( this->ProcessObject::GetInput(#name) ); \
700  }
701 
702 
704 #define itkSetDecoratedInputMacro(name, type) \
705  virtual void Set##name##Input(const SimpleDataObjectDecorator< type > *_arg) \
706  { \
707  itkDebugMacro("setting input " #name " to " << _arg); \
708  if ( _arg != itkDynamicCastInDebugMode< SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
709  { \
710  this->ProcessObject::SetInput( #name, const_cast< SimpleDataObjectDecorator< type > * >( _arg ) ); \
711  this->Modified(); \
712  } \
713  } \
714  virtual void Set##name(const type &_arg) \
715  { \
716  typedef SimpleDataObjectDecorator< type > DecoratorType; \
717  itkDebugMacro("setting input " #name " to " << _arg); \
718  const DecoratorType *oldInput = \
719  itkDynamicCastInDebugMode< const DecoratorType * >( \
720  this->ProcessObject::GetInput(#name) ); \
721  if ( oldInput && oldInput->Get() == _arg ) \
722  { \
723  return; \
724  } \
725  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
726  newInput->Set(_arg); \
727  this->Set##name##Input(newInput); \
728  }
729 
730 
732 #define itkGetDecoratedInputMacro(name, type) \
733  virtual const SimpleDataObjectDecorator< type > * Get##name##Input() const \
734  { \
735  itkDebugMacro( "returning input " << #name " of " << this->ProcessObject::GetInput(#name) ); \
736  return itkDynamicCastInDebugMode< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
737  } \
738  virtual const type & Get##name() const \
739  { \
740  itkDebugMacro("Getting input " #name); \
741  typedef SimpleDataObjectDecorator< type > DecoratorType; \
742  const DecoratorType *input = \
743  itkDynamicCastInDebugMode< const DecoratorType * >( \
744  this->ProcessObject::GetInput(#name) ); \
745  if( input == ITK_NULLPTR ) \
746  { \
747  itkExceptionMacro(<<"input" #name " is not set"); \
748  } \
749  return input->Get(); \
750  }
751 
752 
755 #define itkSetGetDecoratedInputMacro(name, type) \
756  itkSetDecoratedInputMacro(name, type) \
757  itkGetDecoratedInputMacro(name, type)
758 
763 #define itkSetDecoratedObjectInputMacro(name, type) \
764  virtual void Set##name##Input(const DataObjectDecorator< type > *_arg) \
765  { \
766  itkDebugMacro("setting input " #name " to " << _arg); \
767  if ( _arg != itkDynamicCastInDebugMode< DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
768  { \
769  this->ProcessObject::SetInput( #name, const_cast< DataObjectDecorator< type > * >( _arg ) ); \
770  this->Modified(); \
771  } \
772  } \
773  virtual void Set##name(const type * _arg) \
774  { \
775  typedef DataObjectDecorator< type > DecoratorType; \
776  itkDebugMacro("setting input " #name " to " << _arg); \
777  const DecoratorType *oldInput = \
778  itkDynamicCastInDebugMode< const DecoratorType * >( \
779  this->ProcessObject::GetInput(#name) ); \
780  if ( oldInput && oldInput->Get() == _arg ) \
781  { \
782  return; \
783  } \
784  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
785  newInput->Set(_arg); \
786  this->Set##name##Input(newInput); \
787  }
788 
789 
794 #define itkGetDecoratedObjectInputMacro(name, type) \
795  virtual const DataObjectDecorator< type > * Get##name##Input() const \
796  { \
797  itkDebugMacro( "returning input " << #name " of "<< this->ProcessObject::GetInput(#name) ); \
798  return itkDynamicCastInDebugMode< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
799  } \
800  virtual const type * Get##name() const \
801  { \
802  itkDebugMacro("Getting input " #name); \
803  typedef DataObjectDecorator< type > DecoratorType; \
804  const DecoratorType *input = \
805  itkDynamicCastInDebugMode< const DecoratorType * >( \
806  this->ProcessObject::GetInput(#name) ); \
807  if( input == ITK_NULLPTR ) \
808  { \
809  return ITK_NULLPTR; \
810  } \
811  return input->Get(); \
812  }
813 
814 
817 #define itkSetGetDecoratedObjectInputMacro(name, type) \
818  itkSetDecoratedObjectInputMacro(name, type) \
819  itkGetDecoratedObjectInputMacro(name, type)
820 
822 #define itkSetMacro(name, type) \
823  virtual void Set##name (const type _arg) \
824  { \
825  itkDebugMacro("setting " #name " to " << _arg); \
826  if ( this->m_##name != _arg ) \
827  { \
828  this->m_##name = _arg; \
829  this->Modified(); \
830  } \
831  }
832 
833 
835 #define itkGetMacro(name, type) \
836  virtual type Get##name () \
837  { \
838  return this->m_##name; \
839  }
840 
841 
845 #define itkGetConstMacro(name, type) \
846  virtual type Get##name () const \
847  { \
848  return this->m_##name; \
849  }
850 
851 
856 #define itkGetConstReferenceMacro(name, type) \
857  virtual const type &Get##name () const \
858  { \
859  return this->m_##name; \
860  }
861 
862 
867 #define itkSetEnumMacro(name, type) \
868  virtual void Set##name (const type _arg) \
869  { \
870  itkDebugMacro( "setting " #name " to " << static_cast< long >( _arg ) ); \
871  if ( this->m_##name != _arg ) \
872  { \
873  this->m_##name = _arg; \
874  this->Modified(); \
875  } \
876  }
877 
878 
883 #define itkGetEnumMacro(name, type) \
884  virtual type Get##name () const \
885  { \
886  return this->m_##name; \
887  }
888 
889 
893 #define itkSetStringMacro(name) \
894  virtual void Set##name (const char *_arg) \
895  { \
896  if ( _arg && ( _arg == this->m_##name ) ) { return; } \
897  if ( _arg ) \
898  { \
899  this->m_##name = _arg; \
900  } \
901  else \
902  { \
903  this->m_##name = ""; \
904  } \
905  this->Modified(); \
906  } \
907  virtual void Set##name (const std::string & _arg) \
908  { \
909  this->Set##name( _arg.c_str() ); \
910  } \
911 
912 
913 
917 #define itkGetStringMacro(name) \
918  virtual const char *Get##name () const \
919  { \
920  return this->m_##name.c_str(); \
921  }
922 
926 #define itkSetClampMacro(name, type, min, max) \
927  virtual void Set##name (type _arg) \
928  { \
929  itkDebugMacro("setting " << #name " to " << _arg); \
930  if ( this->m_##name != ( _arg < min ? min : ( _arg > max ? max : _arg ) ) ) \
931  { \
932  this->m_##name = ( _arg < min ? min : ( _arg > max ? max : _arg ) ); \
933  this->Modified(); \
934  } \
935  }
936 
937 
942 #define itkSetObjectMacro(name, type) \
943  virtual void Set##name (type * _arg) \
944  { \
945  itkDebugMacro("setting " << #name " to " << _arg); \
946  if ( this->m_##name != _arg ) \
947  { \
948  this->m_##name = _arg; \
949  this->Modified(); \
950  } \
951  }
952 
953 
962 // NOTE: A class can use either itkGetModifiableObjectMacro
963 // or itkGetObjectMacro, but not both.
964 // A class can use either itkGetModifiableObjectMacro
965 // or itkGetConstObjectMacro, but not both.
966 // If the desired behavior is to only provide const
967 // access to the itkObject ivar, then use itkGetConstObjectMacro,
968 // else use itkGetModifiableObjectMacro for read/write access to
969 // the ivar.
970 // It is permissable to use both itkGetObjectMacro and itkGetConstObjectMacro
971 // for backwards compatibility.
972 // If the ITK_LEGACY_REMOVE=FALSE, then it is
973 // permissable to use itkGetObjectMacro which
974 // defines both signatures itk::GetXXX() and
975 // itk::GetModifiableXXX()
976 
979 #define itkGetConstObjectMacro(name, type) \
980  virtual const type * Get##name () const \
981  { \
982  return this->m_##name.GetPointer(); \
983  }
984 
985 
986 #if defined ( ITK_FUTURE_LEGACY_REMOVE )
987 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
988 // flag. For now, this very advanced feature is only available
989 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
990 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
991 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
992 # define itkGetObjectMacro(name, type) \
993  virtual type * Get##name () \
994  { \
995  purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
996  }
997 
998 # define itkGetModifiableObjectMacro(name, type) \
999  virtual type * GetModifiable##name () \
1000  { \
1001  return this->m_##name.GetPointer(); \
1002  } \
1003  itkGetConstObjectMacro(name, type)
1004 
1005 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1006 
1008 # define itkGetObjectMacro(name, type) \
1009  virtual type * Get##name () \
1010  { \
1011  return this->m_##name.GetPointer(); \
1012  }
1013 # define itkGetModifiableObjectMacro(name, type) \
1014  virtual type * GetModifiable##name () \
1015  { \
1016  return this->m_##name.GetPointer(); \
1017  } \
1018  itkGetConstObjectMacro(name, type) \
1019  itkGetObjectMacro(name, type)
1020 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1021 
1022 
1023 // For backwards compatibility define ITK_EXPORT to nothing
1024 #define ITK_EXPORT
1025 
1026 
1029 #define itkGetConstReferenceObjectMacro(name, type) \
1030  virtual const typename type::Pointer & Get##name () const \
1031  { \
1032  return this->m_##name; \
1033  }
1034 
1039 #define itkSetConstObjectMacro(name, type) \
1040  virtual void Set##name (const type * _arg) \
1041  { \
1042  itkDebugMacro("setting " << #name " to " << _arg); \
1043  if ( this->m_##name != _arg ) \
1044  { \
1045  this->m_##name = _arg; \
1046  this->Modified(); \
1047  } \
1048  }
1049 
1050 
1053 #define itkBooleanMacro(name) \
1054  virtual void name##On () \
1055  { \
1056  this->Set##name(true); \
1057  } \
1058  virtual void name##Off () \
1059  { \
1060  this->Set##name(false); \
1061  }
1062 
1063 
1067 #define itkSetVectorMacro(name, type, count) \
1068  virtual void Set##name(type data[]) \
1069  { \
1070  unsigned int i; \
1071  for ( i = 0; i < count; i++ ) \
1072  { \
1073  if ( data[i] != this->m_##name[i] ) \
1074  { \
1075  break; \
1076  } \
1077  } \
1078  if ( i < count ) \
1079  { \
1080  this->Modified(); \
1081  for ( i = 0; i < count; i++ ) \
1082  { \
1083  this->m_##name[i] = data[i]; \
1084  } \
1085  } \
1086  }
1087 
1088 
1091 #define itkGetVectorMacro(name, type, count) \
1092  virtual type * Get##name () const \
1093  { \
1094  return this->m_##name; \
1095  }
1096 
1100 #define itkGPUKernelClassMacro(kernel) \
1101 class kernel \
1102  { \
1103  public: \
1104  static const char* GetOpenCLSource(); \
1105  private: \
1106  kernel(); \
1107  virtual ~kernel(); \
1108  kernel(const kernel &); \
1109  void operator=(const kernel &); \
1110  };
1111 
1112 
1113 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1114  static const char* GetOpenCLSource() \
1115  { \
1116  return kernel::GetOpenCLSource(); \
1117  }
1118 
1119 // A useful macro in the PrintSelf method for printing member variables
1120 // which are pointers to object based on the LightObject class.
1121 #define itkPrintSelfObjectMacro(name) \
1122  if (static_cast<const LightObject*>(this->m_##name) == ITK_NULLPTR) \
1123  { \
1124  os << indent << #name << ": (null)" << std::endl; \
1125  } \
1126  else \
1127  { \
1128  os << indent << #name << ": " << std::endl; \
1129  this->m_##name->Print(os,indent.GetNextIndent()); \
1130  }
1131 
1132 #endif //end of itkMacro.h