ITK  4.2.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 
44 #include <string>
45 #include <cstdlib>
46 #ifndef NDEBUG
47 #include <cassert>
48 #endif
49 
50 #include <sstream>
51 
56 namespace itk
57 {
58 // end namespace itk - this is here for documentation purposes
59 }
60 
63 #define itkNotUsed(x)
64 
65 /*
66  * ITK only supports MSVC++ 7.1 and greater
67  * MSVC++ 11.0 _MSC_VER = 1700
68  * MSVC++ 10.0 _MSC_VER = 1600
69  * MSVC++ 9.0 _MSC_VER = 1500
70  * MSVC++ 8.0 _MSC_VER = 1400
71  * MSVC++ 7.1 _MSC_VER = 1310
72  * MSVC++ 7.0 _MSC_VER = 1300
73  * MSVC++ 6.0 _MSC_VER = 1200
74  * MSVC++ 5.0 _MSC_VER = 1100
75 */
76 #if defined( _MSC_VER ) && ( _MSC_VER < 1310 )
77 //#error "_MSC_VER < 1310 (MSVC++ 7.1) not supported under ITKv4"
78 #endif
79 #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC < 0x590 )
80 #error "__SUNPRO_CC < 0x590 not supported under ITKv4"
81 #endif
82 #if defined( __CYGWIN__ )
83 #error "The Cygwin compiler is not supported in ITKv4 and above"
84 #endif
85 #if defined( __BORLANDC__ )
86 #error "The Borland C compiler is not supported in ITKv4 and above"
87 #endif
88 #if defined( __MWERKS__ )
89 #error "The MetroWerks compiler is not supported in ITKv4 and above"
90 #endif
91 #if defined( __GNUC__ ) && ( __GNUC__ < 3 )
92 #error "The __GNUC__ version 2.95 compiler is not supprted under ITKv4 and above"
93 #if defined( __sgi )
94 //This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
95 //TODO: At some future point, it may be necessary to
96 //define a minimum __sgi version that will work.
97 #error "The __sgi compiler is not supprted under ITKv4 and above"
98 #endif
99 #endif
100 
101 // Setup symbol exports
102 //
103 // When a class definition has ITK_EXPORT, the class will be
104 // checked automatically, by Utilities/Dart/PrintSelfCheck.tcl
105 #define ITK_EXPORT
106 
107 #if defined( _WIN32 ) || defined ( WIN32 )
108  #define ITK_ABI_IMPORT __declspec(dllimport)
109  #define ITK_ABI_EXPORT __declspec(dllexport)
110  #define ITK_ABI_HIDDEN
111 #else
112  #if __GNUC__ >= 4
113  #define ITK_ABI_IMPORT __attribute__ ((visibility ("default")))
114  #define ITK_ABI_EXPORT __attribute__ ((visibility ("default")))
115  #define ITK_ABI_HIDDEN __attribute__ ((visibility ("hidden")))
116  #else
117  #define ITK_ABI_IMPORT
118  #define ITK_ABI_EXPORT
119  #define ITK_ABI_HIDDEN
120  #endif
121 #endif
122 
123 #define ITKCommon_HIDDEN ITK_ABI_HIDDEN
124 
125 #if !defined( ITKSTATIC )
126  #ifdef ITKCommon_EXPORTS
127  #define ITKCommon_EXPORT ITK_ABI_EXPORT
128  #else
129  #define ITKCommon_EXPORT ITK_ABI_IMPORT
130  #endif /* ITKCommon_EXPORTS */
131 #else
132  /* ITKCommon is build as a static lib */
133  #if __GNUC__ >= 4
134  // Don't hide symbols in the static ITKCommon library in case
135  // -fvisibility=hidden is used
136  #define ITKCommon_EXPORT ITK_ABI_EXPORT
137  #else
138  #define ITKCommon_EXPORT
139  #endif
140 #endif
141 
142 //This is probably better, but requires a lot of extra work
143 //for gettting ExplicitInstantiation to work properly. \#define
144 // itkStaticConstMacro(name, type, value) static const type name = value
145 #define itkStaticConstMacro(name, type, value) enum { name = value }
146 
147 #define itkGetStaticConstMacro(name) (Self::name)
148 
150 #define itkSetInputMacro(name, type) \
151  virtual void Set##name(const type *_arg) \
152  { \
153  itkDebugMacro("setting input " #name " to " << _arg); \
154  if ( _arg != static_cast< type * >( this->ProcessObject::GetInput(#name) ) ) \
155  { \
156  this->ProcessObject::SetInput( #name, const_cast< type * >( _arg ) ); \
157  this->Modified(); \
158  } \
159  }
160 
161 
163 #define itkGetInputMacro(name, type) \
164  virtual const type * Get##name() const \
165  { \
166  itkDebugMacro( "returning input " << #name " of " \
167  << static_cast< const type * >( this->ProcessObject::GetInput(#name) ) ); \
168  return static_cast< const type * >( this->ProcessObject::GetInput(#name) ); \
169  }
170 
171 
173 #define itkSetDecoratedInputMacro(name, type) \
174  virtual void Set##name##Input(const SimpleDataObjectDecorator< type > *_arg) \
175  { \
176  itkDebugMacro("setting input " #name " to " << _arg); \
177  if ( _arg != static_cast< SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
178  { \
179  this->ProcessObject::SetInput( #name, const_cast< SimpleDataObjectDecorator< type > * >( _arg ) ); \
180  this->Modified(); \
181  } \
182  } \
183  virtual void Set##name(const type &_arg) \
184  { \
185  typedef SimpleDataObjectDecorator< type > DecoratorType; \
186  itkDebugMacro("setting input " #name " to " << _arg); \
187  const DecoratorType *oldInput = \
188  static_cast< const DecoratorType * >( \
189  this->ProcessObject::GetInput(#name) ); \
190  if ( oldInput && oldInput->Get() == _arg ) \
191  { \
192  return; \
193  } \
194  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
195  newInput->Set(_arg); \
196  this->Set##name##Input(newInput); \
197  }
198 
199 
201 #define itkGetDecoratedInputMacro(name, type) \
202  virtual const SimpleDataObjectDecorator< type > * Get##name##Input() const \
203  { \
204  itkDebugMacro( "returning input " << #name " of " \
205  << static_cast< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ); \
206  return static_cast< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
207  } \
208  virtual const type & Get##name() const \
209  { \
210  itkDebugMacro("Getting input " #name); \
211  typedef SimpleDataObjectDecorator< type > DecoratorType; \
212  const DecoratorType *input = \
213  static_cast< const DecoratorType * >( \
214  this->ProcessObject::GetInput(#name) ); \
215  if( input == NULL ) \
216  { \
217  itkExceptionMacro(<<"input" #name " is not set"); \
218  } \
219  return input->Get(); \
220  }
221 
222 
225 #define itkSetGetDecoratedInputMacro(name, type) \
226  itkSetDecoratedInputMacro(name, type) \
227  itkGetDecoratedInputMacro(name, type)
228 
233 #define itkSetDecoratedObjectInputMacro(name, type) \
234  virtual void Set##name##Input(const DataObjectDecorator< type > *_arg) \
235  { \
236  itkDebugMacro("setting input " #name " to " << _arg); \
237  if ( _arg != static_cast< DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
238  { \
239  this->ProcessObject::SetInput( #name, const_cast< DataObjectDecorator< type > * >( _arg ) ); \
240  this->Modified(); \
241  } \
242  } \
243  virtual void Set##name(const type * _arg) \
244  { \
245  typedef DataObjectDecorator< type > DecoratorType; \
246  itkDebugMacro("setting input " #name " to " << _arg); \
247  const DecoratorType *oldInput = \
248  static_cast< const DecoratorType * >( \
249  this->ProcessObject::GetInput(#name) ); \
250  if ( oldInput && oldInput->Get() == _arg ) \
251  { \
252  return; \
253  } \
254  typename DecoratorType::Pointer newInput = DecoratorType::New(); \
255  newInput->Set(_arg); \
256  this->Set##name##Input(newInput); \
257  }
258 
259 
264 #define itkGetDecoratedObjectInputMacro(name, type) \
265  virtual const DataObjectDecorator< type > * Get##name##Input() const \
266  { \
267  itkDebugMacro( "returning input " << #name " of " \
268  << static_cast< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ); \
269  return static_cast< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
270  } \
271  virtual const type * Get##name() const \
272  { \
273  itkDebugMacro("Getting input " #name); \
274  typedef DataObjectDecorator< type > DecoratorType; \
275  const DecoratorType *input = \
276  static_cast< const DecoratorType * >( \
277  this->ProcessObject::GetInput(#name) ); \
278  if( input == NULL ) \
279  { \
280  itkExceptionMacro(<<"input" #name " is not set"); \
281  } \
282  return input->Get(); \
283  }
284 
285 
288 #define itkSetGetDecoratedObjectInputMacro(name, type) \
289  itkSetDecoratedObjectInputMacro(name, type) \
290  itkGetDecoratedObjectInputMacro(name, type)
291 
293 #define itkSetMacro(name, type) \
294  virtual void Set##name (const type _arg) \
295  { \
296  itkDebugMacro("setting " #name " to " << _arg); \
297  if ( this->m_##name != _arg ) \
298  { \
299  this->m_##name = _arg; \
300  this->Modified(); \
301  } \
302  }
303 
304 
306 #define itkGetMacro(name, type) \
307  virtual type Get##name () \
308  { \
309  return this->m_##name; \
310  }
311 
312 
316 #define itkGetConstMacro(name, type) \
317  virtual type Get##name () const \
318  { \
319  return this->m_##name; \
320  }
321 
322 
327 #define itkGetConstReferenceMacro(name, type) \
328  virtual const type &Get##name () const \
329  { \
330  return this->m_##name; \
331  }
332 
333 
338 #define itkSetEnumMacro(name, type) \
339  virtual void Set##name (const type _arg) \
340  { \
341  itkDebugMacro( "setting " #name " to " << static_cast< long >( _arg ) ); \
342  if ( this->m_##name != _arg ) \
343  { \
344  this->m_##name = _arg; \
345  this->Modified(); \
346  } \
347  }
348 
349 
354 #define itkGetEnumMacro(name, type) \
355  virtual type Get##name () const \
356  { \
357  return this->m_##name; \
358  }
359 
360 
364 #define itkSetStringMacro(name) \
365  virtual void Set##name (const char *_arg) \
366  { \
367  if ( _arg && ( _arg == this->m_##name ) ) { return; } \
368  if ( _arg ) \
369  { \
370  this->m_##name = _arg; \
371  } \
372  else \
373  { \
374  this->m_##name = ""; \
375  } \
376  this->Modified(); \
377  } \
378  virtual void Set##name (const std::string & _arg) \
379  { \
380  this->Set##name( _arg.c_str() ); \
381  } \
382 
383 
384 
388 #define itkGetStringMacro(name) \
389  virtual const char *Get##name () const \
390  { \
391  return this->m_##name.c_str(); \
392  }
393 
397 #define itkSetClampMacro(name, type, min, max) \
398  virtual void Set##name (type _arg) \
399  { \
400  itkDebugMacro("setting " << #name " to " << _arg); \
401  if ( this->m_##name != ( _arg < min ? min : ( _arg > max ? max : _arg ) ) ) \
402  { \
403  this->m_##name = ( _arg < min ? min : ( _arg > max ? max : _arg ) ); \
404  this->Modified(); \
405  } \
406  }
407 
408 
413 #define itkSetObjectMacro(name, type) \
414  virtual void Set##name (type * _arg) \
415  { \
416  itkDebugMacro("setting " << #name " to " << _arg); \
417  if ( this->m_##name != _arg ) \
418  { \
419  this->m_##name = _arg; \
420  this->Modified(); \
421  } \
422  }
423 
424 
427 #define itkGetObjectMacro(name, type) \
428  virtual type * Get##name () \
429  { \
430  return this->m_##name.GetPointer(); \
431  }
432 
437 #define itkSetConstObjectMacro(name, type) \
438  virtual void Set##name (const type * _arg) \
439  { \
440  itkDebugMacro("setting " << #name " to " << _arg); \
441  if ( this->m_##name != _arg ) \
442  { \
443  this->m_##name = _arg; \
444  this->Modified(); \
445  } \
446  }
447 
448 
451 #define itkGetConstObjectMacro(name, type) \
452  virtual const type * Get##name () const \
453  { \
454  return this->m_##name.GetPointer(); \
455  }
456 
459 #define itkGetConstReferenceObjectMacro(name, type) \
460  virtual const typename type::Pointer & Get##name () const \
461  { \
462  return this->m_##name; \
463  }
464 
467 #define itkBooleanMacro(name) \
468  virtual void name##On () \
469  { \
470  this->Set##name(true); \
471  } \
472  virtual void name##Off () \
473  { \
474  this->Set##name(false); \
475  }
476 
477 
481 #define itkSetVectorMacro(name, type, count) \
482  virtual void Set##name(type data[]) \
483  { \
484  unsigned int i; \
485  for ( i = 0; i < count; i++ ) \
486  { \
487  if ( data[i] != this->m_##name[i] ) \
488  { \
489  break; \
490  } \
491  } \
492  if ( i < count ) \
493  { \
494  this->Modified(); \
495  for ( i = 0; i < count; i++ ) \
496  { \
497  this->m_##name[i] = data[i]; \
498  } \
499  } \
500  }
501 
502 
505 #define itkGetVectorMacro(name, type, count) \
506  virtual type * Get##name () const \
507  { \
508  return this->m_##name; \
509  }
510 
514 #define itkGPUKernelClassMacro(kernel) \
515 class ITK_EXPORT kernel \
516  { \
517  public: \
518  static const char* GetOpenCLSource(); \
519  private: \
520  kernel(); \
521  virtual ~kernel(); \
522  kernel(const kernel &); \
523  void operator=(const kernel &); \
524  };
525 
526 
527 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
528  static const char* GetOpenCLSource() \
529  { \
530  return kernel::GetOpenCLSource(); \
531  }
532 
553 #define itkNewMacro(x) \
554  itkSimpleNewMacro(x) \
555  itkCreateAnotherMacro(x) \
556  itkCloneMacro(x)
557 
558 #define itkSimpleNewMacro(x) \
559  static Pointer New(void) \
560  { \
561  Pointer smartPtr = ::itk::ObjectFactory< x >::Create(); \
562  if ( smartPtr.GetPointer() == NULL ) \
563  { \
564  smartPtr = new x; \
565  } \
566  smartPtr->UnRegister(); \
567  return smartPtr; \
568  }
569 
570 #define itkCreateAnotherMacro(x) \
571  virtual::itk::LightObject::Pointer CreateAnother(void) const \
572  { \
573  ::itk::LightObject::Pointer smartPtr; \
574  smartPtr = x::New().GetPointer(); \
575  return smartPtr; \
576  }
577 
578 #define itkCloneMacro(x) \
579  Pointer Clone() const \
580  { \
581  Pointer rval = \
582  dynamic_cast<x *>(this->InternalClone().GetPointer()); \
583  return rval; \
584  }
585 
602 #define itkFactorylessNewMacro(x) \
603  static Pointer New(void) \
604  { \
605  Pointer smartPtr; \
606  x * rawPtr = new x; \
607  smartPtr = rawPtr; \
608  rawPtr->UnRegister(); \
609  return smartPtr; \
610  } \
611  virtual::itk::LightObject::Pointer CreateAnother(void) const \
612  { \
613  ::itk::LightObject::Pointer smartPtr; \
614  smartPtr = x::New().GetPointer(); \
615  return smartPtr; \
616  }
617 
618 
621 #define itkTypeMacro(thisClass, superclass) \
622  virtual const char *GetNameOfClass() const \
623  { \
624  return #thisClass; \
625  }
626 
627 namespace itk
628 {
635 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char *);
637 
638 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char *);
639 
640 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char *);
641 
642 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char *);
643 
644 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char *);
645 } // end namespace itk
646 
650 #if defined( NDEBUG )
651 #define itkDebugMacro(x)
652 #define itkDebugStatement(x)
653 #else
654 #define itkDebugMacro(x) \
655  { \
656  if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
657  { \
658  std::ostringstream itkmsg; \
659  itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
660  << this->GetNameOfClass() << " (" << this << "): " x \
661  << "\n\n"; \
662  ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() ); \
663  } \
664  }
665 
666 
667 //The itkDebugStatement is to be used to protect code that is only
668 //used in the itkDebugMacro
669 #define itkDebugStatement(x) x
670 #endif
671 
675 #define itkWarningMacro(x) \
676  { \
677  if ( ::itk::Object::GetGlobalWarningDisplay() ) \
678  { \
679  std::ostringstream itkmsg; \
680  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
681  << this->GetNameOfClass() << " (" << this << "): " x \
682  << "\n\n"; \
683  ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() ); \
684  } \
685  }
686 
687 
688 //The itkDebugStatement is to be used ot protect code that is only
689 //used in the itkDebugMacro
690 #define itkWarningStatement(x) x
691 
692 #if defined( ITK_CPP_FUNCTION )
693  #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( CABLE_CONFIGURATION ) \
694  && !defined( CSWIG )
695  #define ITK_LOCATION __FUNCSIG__
696  #elif defined( __GNUC__ )
697  #define ITK_LOCATION __PRETTY_FUNCTION__
698  #else
699  #define ITK_LOCATION __FUNCTION__
700  #endif
701 #else
702  #define ITK_LOCATION "unknown"
703 #endif
704 
705 #include "itkExceptionObject.h"
706 
710 #define itkExceptionMacro(x) \
711  { \
712  std::ostringstream message; \
713  message << "itk::ERROR: " << this->GetNameOfClass() \
714  << "(" << this << "): " x; \
715  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
716  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
717  }
718 
719 
720 #define itkGenericExceptionMacro(x) \
721  { \
722  std::ostringstream message; \
723  message << "itk::ERROR: " x; \
724  ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
725  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
726  }
727 
728 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage) \
729 namespace itk { \
730 class ITK_EXPORT newexcp : public parentexcp \
731 { \
732 public: \
733 newexcp( const char *file, unsigned int lineNumber ) : \
734 parentexcp( file, lineNumber ) \
735 { \
736  this->SetDescription( whatmessage ); \
737 } \
738 newexcp( const std::string & file, unsigned int lineNumber ) : \
739 parentexcp( file, lineNumber ) \
740 { \
741  this->SetDescription( whatmessage ); \
742 } \
743 itkTypeMacro(newexcp, parentexcp); \
744 }; \
745 }
746 
747 #define itkSpecializedExceptionMacro(exceptiontype) \
748  { \
749  ::itk::exceptiontype e_(__FILE__, __LINE__); \
750  e_.SetLocation(ITK_LOCATION); \
751  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
752  }
753 
754 #define itkSpecializedMessageExceptionMacro(exceptiontype,x) \
755  { \
756  ::itk::exceptiontype e_(__FILE__, __LINE__); \
757  std::ostringstream message; \
758  message << "itk::ERROR: " x; \
759  e_.SetDescription(message.str().c_str()); \
760  e_.SetLocation(ITK_LOCATION); \
761  throw e_; /* Explicit naming to work around Intel compiler bug. */ \
762  }
763 
764 
765 #define itkGenericOutputMacro(x) \
766  { \
767  if ( ::itk::Object::GetGlobalWarningDisplay() ) \
768  { \
769  std::ostringstream itkmsg; \
770  itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
771  x << "\n\n"; \
772  ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \
773  } \
774  }
775 
776 //----------------------------------------------------------------------------
777 // Macros for simplifying the use of logging
778 //
779 #define itkLogMacro(x, y) \
780  { \
781  if ( this->GetLogger() ) \
782  { \
783  this->GetLogger()->Write(::itk::LoggerBase::x, y); \
784  } \
785  }
786 
787 #define itkLogMacroStatic(obj, x, y) \
788  { \
789  if ( obj->GetLogger() ) \
790  { \
791  obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
792  } \
793  }
794 
795 //----------------------------------------------------------------------------
796 // Setup legacy code policy.
797 //
798 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted
799 // They may be used to completely remove legacy code or silence the
800 // warnings. The default is to warn about their use.
801 //
802 // Source files that test the legacy code may define ITK_LEGACY_TEST
803 // like this:
804 //
805 // #define ITK_LEGACY_TEST
806 // #include "itkClassWithDeprecatedMethod.h"
807 //
808 // in order to silence the warnings for calling deprecated methods.
809 // No other source files in ITK should call the methods since they are
810 // provided only for compatibility with older user code.
811 
812 // Define itkLegacyMacro to mark legacy methods where they are
813 // declared in their class. Example usage:
814 //
815 // // @deprecated Replaced by MyOtherMethod() as of ITK 2.0.
816 // itkLegacyMacro(void MyMethod());
817 #if defined( ITK_LEGACY_REMOVE )
818 // Remove legacy methods completely. Put a bogus declaration in
819 // place to avoid stray semicolons because this is an error for some
820 // compilers. Using a class forward declaration allows any number
821 // of repeats in any context without generating unique names.
822 #define itkLegacyMacro(method) class itkLegacyMethodRemoved /* no ';' */
823 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( CSWIG )
824 // Provide legacy methods with no warnings.
825 #define itkLegacyMacro(method) method
826 #else
827 // Setup compile-time warnings for uses of deprecated methods if
828 // possible on this compiler.
829 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) )
830 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) )
831 #elif defined( _MSC_VER )
832 #define itkLegacyMacro(method) __declspec(deprecated) method
833 #else
834 #define itkLegacyMacro(method) method
835 #endif
836 #endif
837 
838 // Macros to create runtime deprecation warning messages in function
839 // bodies. Example usage:
840 //
841 // void itkMyClass::MyOldMethod()
842 // {
843 // itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
844 // }
845 //
846 // void itkMyClass::MyMethod()
847 // {
848 // itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
849 // itkMyClass::MyOtherMethod);
850 // }
851 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT )
852 #define itkLegacyBodyMacro(method, version)
853 #define itkLegacyReplaceBodyMacro(method, version, replace)
854 #define itkGenericLegacyBodyMacro(method, version)
855 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)
856 #else
857 #define itkLegacyBodyMacro(method, version) \
858  itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
859 #define itkLegacyReplaceBodyMacro(method, version, replace) \
860  itkWarningMacro( \
861  #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
862  " instead.")
863 #define itkGenericLegacyBodyMacro(method, version) \
864  itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
865 #define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
866  itkGenericOutputMacro( \
867  #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
868  " instead.")
869 #endif
870 
871 //=============================================================================
872 /* Define a common way of declaring a templated function as a friend inside a class.
873  - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
874 
875  The following templated function
876 
877  template <T>
878  T add(const T & a, const T & b);
879 
880  is declared as friend in some compilers as:
881 
882  class A
883  {
884  public:
885  friend Self add<Self>( const Self & a, const Self & b );
886  }
887 
888  while other compilers will do
889 
890  class A
891  {
892  public:
893  friend Self add<>( const Self & a, const Self & b );
894  }
895 
896  This characteristic of the compiler is checked by a TRY_COMPILE
897  command defined in Insight/CMake/itkTestFriendTemplatedFunction.cxx
898 
899 */
900 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_NULL_STRING )
901 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
902 #else
903 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_EMPTY_BRACKETS )
904 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
905 #else
906 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_TEMPLATE_ARGUMENTS )
907 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < T >
908 #endif
909 #endif
910 #endif
911 // THIS IS A TEMPORARY PATCH FOR Visual Studio 10. The correct solution must
912 // be implemented in Insight/CMake/itkTestFriendTemplatedFunction.cxx
913 #if ( defined ( _MSC_VER ) && ( _MSC_VER >= 1600 ) )
914 #ifdef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
915 #undef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
916 #endif
917 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
918 #endif
919 
920 //=============================================================================
921 /* Choose a way to prevent template instantiation on this platform.
922  - ITK_TEMPLATE_DO_NOT_INSTANTIATE = use #pragma do_not_instantiate to
923  prevent instantiation
924  - ITK_TEMPLATE_EXTERN = use extern template to prevent instantiation
925 
926  Note that VS 6 supports extern template instantiation but it is
927  hard to block the resulting warning because its stream headers
928  re-enable it. Therefore we just disable support for now.
929 */
930 #if defined( __INTEL_COMPILER ) && __INTEL_COMPILER >= 700
931 #define ITK_TEMPLATE_EXTERN 1
932 #elif defined( __GNUC__ ) && __GNUC__ >= 3
933 #define ITK_TEMPLATE_EXTERN 1
934 #elif defined( _MSC_VER )
935 #define ITK_TEMPLATE_EXTERN 1
936 #endif
937 #if !defined( ITK_TEMPLATE_DO_NOT_INSTANTIATE )
938 #define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
939 #endif
940 #if !defined( ITK_TEMPLATE_EXTERN )
941 #define ITK_TEMPLATE_EXTERN 0
942 #endif
943 
944 /* Define a macro to explicitly instantiate a template.
945  - ITK_TEMPLATE_EXPORT(X) =
946  Explicitly instantiate X, where X is of the form N(a1[,a2...,aN]).
947  examples: ITK_TEMPLATE_EXPORT(1(class Foo<int>))
948  ITK_TEMPLATE_EXPORT(2(class Bar<int, char>))
949  Use one level of expansion delay to allow user code to have
950  a macro determining the number of arguments. */
951 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
952 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
953 
954 /* Define a macro to prevent template instantiations.
955  - ITK_TEMPLATE_IMPORT(X) =
956  Prevent instantiation of X, where X is of the form N(a1[,a2...,aN]).
957  examples: ITK_TEMPLATE_IMPORT(1(class Foo<int>))
958  ITK_TEMPLATE_IMPORT(2(class Bar<int, char>))
959  Use one level of expansion delay to allow user code to have
960  a macro determining the number of arguments.
961 */
962 #if ITK_TEMPLATE_EXTERN
963 #define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
964 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
965 #define ITK_TEMPLATE_IMPORT_DELAY(x) \
966  ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
967 #define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
968 #endif
969 #if defined( ITK_TEMPLATE_IMPORT_DELAY )
970 #define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
971 #define ITK_TEMPLATE_IMPORT_WORKS 1
972 #else
973 #define ITK_TEMPLATE_IMPORT(x)
974 #define ITK_TEMPLATE_IMPORT_WORKS 0
975 #endif
976 
1042 #define ITK_EXPORT_TEMPLATE(EXPORT, c, x, y) \
1043  ITK_TEMPLATE_##c(ITK_TEMPLATE_EXPORT, EXPORT ITK_EMPTY, x, y)
1044 #define ITK_IMPORT_TEMPLATE(EXPORT, c, x, y) \
1045  ITK_TEMPLATE_##c(ITK_TEMPLATE_IMPORT, EXPORT ITK_EMPTY, x, y)
1046 #define ITK_EMPTY
1047 
1048 /* Define macros to support passing a variable number of arguments
1049  throug other macros. This is used by ITK_TEMPLATE_EXPORT,
1050  ITK_TEMPLATE_IMPORT, and by each template's instantiation
1051  macro. */
1052 #define ITK_TEMPLATE_1(x1) x1
1053 #define ITK_TEMPLATE_2(x1, x2) x1, x2
1054 #define ITK_TEMPLATE_3(x1, x2, x3) x1, x2, x3
1055 #define ITK_TEMPLATE_4(x1, x2, x3, x4) x1, x2, x3, x4
1056 #define ITK_TEMPLATE_5(x1, x2, x3, x4, x5) x1, x2, x3, x4, x5
1057 #define ITK_TEMPLATE_6(x1, x2, x3, x4, x5, x6) x1, x2, x3, x4, x5, x6
1058 #define ITK_TEMPLATE_7(x1, x2, x3, x4, x5, x6, x7) x1, x2, x3, x4, x5, x6, x7
1059 #define ITK_TEMPLATE_8(x1, x2, x3, x4, x5, x6, x7, x8) x1, x2, x3, x4, x5, x6, x7, x8
1060 #define ITK_TEMPLATE_9(x1, x2, x3, x4, x5, x6, x7, x8, x9) x1, x2, x3, x4, x5, x6, x7, x8, x9
1061 
1062 /* In order to support both implicit and explicit instantation a .h
1063  file needs to know whether it should include its .hxx file
1064  containing the template definitions. Define a macro to tell
1065  it. Typical usage in itkFoo.h:
1066  #if ITK_TEMPLATE_TXX
1067  #include "itkFoo.hxx"
1068  #endif
1069 */
1070 #ifndef ITK_TEMPLATE_CXX //At this point this variable MUST be defined
1071 #define ITK_TEMPLATE_CXX 0
1072 #endif
1073 #ifndef ITK_TEMPLATE_TYPE
1074 #define ITK_TEMPLATE_TYPE 0
1075 #endif
1076 #if defined( ITK_MANUAL_INSTANTIATION )
1077 #define ITK_TEMPLATE_TXX 0
1078 #else
1079 #define ITK_TEMPLATE_TXX !( ITK_TEMPLATE_CXX || ITK_TEMPLATE_TYPE )
1080 #endif
1081 
1082 /* All explicit instantiation source files define ITK_TEMPLATE_CXX.
1083  Define ITK_MANUAL_INSTANTIATION to tell .h files that have not been
1084  converted to this explicit instantiation scheme to not include
1085  their .hxx files. Also disable warnings that commonly occur in
1086  these files but are not useful. */
1087 #if ITK_TEMPLATE_CXX
1088 #undef ITK_MANUAL_INSTANTIATION
1089 #define ITK_MANUAL_INSTANTIATION
1090 #endif
1091 //=============================================================================
1092 
1093 /* Define macros to export and import template instantiations for each
1094  library in ITK. */
1095 #define ITK_EXPORT_ITKCommon(c, x, n) \
1096  ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
1097 #define ITK_IMPORT_ITKCommon(c, x, n) \
1098  ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
1099 
1100 /* Define a macro to decide whether to block instantiation of ITK
1101  templates. They should be blocked only if the platform supports
1102  blocking template instantiation and the explicit instantiations are
1103  available.
1104 
1105  - ITK_TEMPLATE_EXPLICIT =
1106  Whether to include "XXX+-.h" from "XXX.h" to prevent implicit
1107  instantiations of templates explicitly instantiated elsewhere.
1108  Typical usage in itkFoo.h:
1109  #if ITK_TEMPLATE_EXPLICIT
1110  #include "itkFoo+-.h"
1111  #endif
1112 */
1113 #if ITK_TEMPLATE_IMPORT_WORKS && defined( ITK_EXPLICIT_INSTANTIATION )
1114 #define ITK_TEMPLATE_EXPLICIT !ITK_TEMPLATE_CXX
1115 #else
1116 #define ITK_TEMPLATE_EXPLICIT 0
1117 #endif
1118 
1119 //--------------------------------------------------------------------------------
1120 // Helper macros for Template Meta-Programming techniques of for-loops
1121 // unrolling
1122 //--------------------------------------------------------------------------------
1123 
1124 //--------------------------------------------------------------------------------
1125 // Macro that generates an unrolled for loop for assigning elements of one array
1126 // to elements of another array The array are assumed to be of same length
1127 // (dimension), and this is also assumed to be the value of NumberOfIterations.
1128 // No verification of size is performed. Casting is perfomed as part of the
1129 // assignment, by using the DestinationElementType as the casting type.
1130 // Source and destination array types must have defined opearator[] in their
1131 // API.
1132 #define itkForLoopAssignmentMacro(DestinationType, \
1133  SourceType, \
1134  DestinationElementType, \
1135  DestinationArray, \
1136  SourceArray, \
1137  NumberOfIterations) \
1138  for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
1139  { \
1140  DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
1141  }
1142 
1143 //--------------------------------------------------------------------------------
1144 // Macro that generates an unrolled for loop for rounding and assigning
1145 // elements of one array to elements of another array The array are assumed to
1146 // be of same length (dimension), and this is also assumed to be the value of
1147 // NumberOfIterations. No verification of size is performed. Casting is
1148 // perfomed as part of the assignment, by using the DestinationElementType as
1149 // the casting type.
1150 // Source and destination array types must have defined opearator[] in their
1151 // API.
1152 #define itkForLoopRoundingAndAssignmentMacro(DestinationType, \
1153  Sourcrnd_halfintup, \
1154  DestinationElementType, \
1155  DestinationArray, \
1156  SourceArray, \
1157  NumberOfIterations) \
1158  for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
1159  { \
1160  DestinationArray[i] = itk::Math::Round< DestinationElementType >(SourceArray[i]); \
1161  }
1162 
1163 // end of Template Meta Programming helper macros
1164 
1165 #ifndef NDEBUG
1166 
1167 #ifdef _POSIX_SOURCE
1168 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
1169 #else
1170 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
1171 #endif
1172 
1173 #else
1174 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
1175 #endif
1176 
1177 #define itkAssertOrThrowMacro(test, message) \
1178  if ( !( test ) ) \
1179  { \
1180  std::ostringstream msgstr; \
1181  msgstr << message; \
1182  itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
1183  }
1184 
1185 #ifndef NDEBUG
1186 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
1187 #else
1188 #define itkAssertInDebugAndIgnoreInReleaseMacro(X)
1189 #endif
1190 
1191 #ifdef ITKV3_COMPATIBILITY
1192 // As of MSVS++ 7.1 and greater, typename is supported in templates
1193 // All ITKv4 compilers support the typename keyword, but this is
1194 // needed to ease transition from ITKv3.
1195 #define ITK_TYPENAME typename
1196 #endif
1197 
1198 
1199 #endif //end of itkMacro.h
1200