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  *=========================================================================*/
28 /**
29  * itkMacro.h defines standard system-wide macros, constants, and other
30  * parameters. One of its most important functions is to define macros used
31  * to interface to instance variables in a standard fashion. For example,
32  * these macros manage modified time, debugging information, and provide a
33  * standard interface to set and get instance variables.  Macros are
34  * available for built-in types; for string classe; vector arrays;
35  * object pointers; and debug, warning, and error printout information.
36  */
37 
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 
55 /** \namespace itk
56  * \brief The "itk" namespace contains all Insight Segmentation and
57  * Registration Toolkit (ITK) classes. There are several nested namespaces
58  * within the itk:: namespace. */
59 namespace itk
60 {
61 // end namespace itk - this is here for documentation purposes
62 }
63 
64 /** A convenience macro marks variables as not being used by a method,
65  * avoiding compile-time warnings. */
66 #define itkNotUsed(x)
67 
68 
69 // Define ITK_PRAGMA macro.
70 //
71 // It sets "#pragma" preprocessor directives without expecting the arguments
72 // to be quoted.
73 #define ITK_PRAGMA(x) _Pragma (#x)
74 
75 // The clang compiler has many useful non-default compiler warnings
76 // that tend to have a high false positive rate.
77 // The following set of defines allows us to suppress false positives
78 // and still track down suspicious code
79 #if defined(__clang__) && defined(__has_warning)
80   #define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
81   #define CLANG_PRAGMA_POP  ITK_PRAGMA(clang diagnostic pop)
82   #if __has_warning("-Wfloat-equal")
83     #define CLANG_SUPPRESS_Wfloat_equal ITK_PRAGMA( clang diagnostic ignored "-Wfloat-equal" )
84   #else
85     #define CLANG_SUPPRESS_Wfloat_equal
86   #endif
87   #if __has_warning( "-Wc++14-extensions" )
88     #define CLANG_SUPPRESS_Wc__14_extensions ITK_PRAGMA( clang diagnostic ignored "-Wc++14-extensions" )
89   #else
90     #define CLANG_SUPPRESS_Wc__14_extensions
91   #endif
92 #else
93   #define CLANG_PRAGMA_PUSH
94   #define CLANG_PRAGMA_POP
95   #define CLANG_SUPPRESS_Wfloat_equal
96   #define CLANG_SUPPRESS_Wc__14_extensions
97 #endif
98 
99 // Intel compiler convenience macros
100 #if defined(__INTEL_COMPILER)
101   #define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
102   #define INTEL_PRAGMA_WARN_POP  ITK_PRAGMA(warning pop)
103   #define INTEL_SUPPRESS_warning_1292  ITK_PRAGMA(warning disable 1292)
104 #else
105   #define INTEL_PRAGMA_WARN_PUSH
106   #define INTEL_PRAGMA_WARN_POP
107   #define INTEL_SUPPRESS_warning_1292
108 #endif
109 
110 // Define ITK_GCC_PRAGMA_DIAG(param1 [param2 [...]]) macro.
111 //
112 // This macro sets a pragma diagnostic
113 //
114 // Define ITK_GCC_PRAGMA_DIAG_(PUSH|POP) macros.
115 //
116 // These macros respectively push and pop the diagnostic context
117 //
118 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER )
119   #define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
120   #define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
121   #define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
122 #else
123   #define ITK_GCC_PRAGMA_DIAG(x)
124   #define ITK_GCC_PRAGMA_DIAG_PUSH()
125   #define ITK_GCC_PRAGMA_DIAG_POP()
126 #endif
127 
128 /*
129  * ITK only supports MSVC++ 14.0 and greater
130  * MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015 version 14.0)
131  * MSVC++ 14.1 _MSC_VER == 1910 (Visual Studio 2017 version 15.0)
132  * MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3)
133  * MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5)
134  * MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6)
135  * MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7)
136  * MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8)
137  * MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9)
138  * MSVC++ 14.2 _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
139 */
140 #if defined( _MSC_VER ) && ( _MSC_VER < 1900 )
141   #error "Visual Studio < 2015 is not supported under ITKv5"
142 #endif
143 #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC < 0x5140 )
144   #error "SUNPro C++ < 5.14.0 is not supported under ITKv5 and above"
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__ ) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (( __GNUC__ < 4 ) || (( __GNUC__ == 4 ) && ( __GNUC_MINOR__ < 8 )))
156   #error "GCC < 4.8 is not supported under ITKv5"
157 #endif
158 #if defined( __sgi )
159   //This is true for IRIX 6.5.18m with MIPSPro 7.3.1.3m.
160   //TODO: At some future point, it may be necessary to
161   //define a minimum __sgi version that will work.
162   #error "The SGI compiler is not supported under ITKv4 and above"
163 #endif
164 #if defined(__APPLE__)
165   #if defined( __clang__ ) && ( __cplusplus < 201103L )
166     #error "Apple LLVM < 5.0 (clang < 3.3) is not supported under ITKv5"
167   #endif
168 #elif defined( __clang__ ) && (( __clang_major__ < 3 ) || (( __clang_major__ == 3 ) && ( __clang_minor__ < 3 )))
169   #error "Clang < 3.3 is not supported under ITKv5"
170 #endif
171 #if defined( __INTEL_COMPILER ) && ( __INTEL_COMPILER < 1504 )
172   #error "Intel C++ < 15.0.4 is not supported under ITKv5"
173 #endif
174 
175 // Setup symbol exports
176 #if defined( _WIN32 ) || defined ( WIN32 )
177   #define ITK_ABI_IMPORT __declspec(dllimport)
178   #define ITK_ABI_EXPORT __declspec(dllexport)
179   #define ITK_ABI_HIDDEN
180 #else
181   #if __GNUC__ >= 4
182     #define ITK_ABI_IMPORT __attribute__ ((visibility ("default")))
183     #define ITK_ABI_EXPORT __attribute__ ((visibility ("default")))
184     #define ITK_ABI_HIDDEN __attribute__ ((visibility ("hidden")))
185   #else
186     #define ITK_ABI_IMPORT
187     #define ITK_ABI_EXPORT
188     #define ITK_ABI_HIDDEN
189   #endif
190 #endif
191 
192 // Setup symbol exports
193 #ifndef ITK_TEMPLATE_EXPORT
194   #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
195     #define ITK_TEMPLATE_EXPORT __attribute__ ((visibility ("default")))
196   #else
197     #define ITK_TEMPLATE_EXPORT
198   #endif
199 #endif
200 
201 // Setup symbol exports
202 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
203   #define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__ ((visibility ("default")))
204 #else
205   #define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName ## _EXPORT
206 #endif
207 
208 #ifndef ITK_FORWARD_EXPORT
209   // If build with shared libraries, on MacOS, if USE_COMPILER_HIDDEN_VISIBILITY is ON
210   #if defined(__APPLE__)\
211    && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT)\
212    && defined(ITK_BUILD_SHARED_LIBS)\
213    && defined(USE_COMPILER_HIDDEN_VISIBILITY)
214     #define ITK_FORWARD_EXPORT __attribute__ ((visibility ("default")))
215   #else
216     #define ITK_FORWARD_EXPORT
217   #endif
218 #endif
219 
220 
221 //-*-*-*
222 //The following deprecations should be removed in ITKV6 and later
223 //NOTE DEPRECATED should be ITK_NOEXCEPT
224 #define ITK_NOEXCEPT_OR_THROW error "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT"
225 //NOTE DEPRECATED!  should be ITK_COMPILER_CXX_STATIC_ASSERT
226 #if !defined( ITK_LEGACY_REMOVE )
227 #define ITK_DELETE_FUNCTION = delete
228 #else
229 #define ITK_DELETE_FUNCTION error "Replace ITK_DELETE_FUNCTION with = delete"
230 #endif
231 //-*-*-*
232 
233 // DEPRECATED: These macros are left here for compatibility with remote modules.
234 // Once they have been removed from all known remote modules, this code should
235 // be removed.
236 #if defined ( ITK_FUTURE_LEGACY_REMOVE )
237   #define ITK_CONSTEXPR_FUNC "Replace ITK_CONSTEXPR_FUNC with constexpr"
238   #define ITK_CONSTEXPR_VAR  "Replace ITK_CONSTEXPR_VAR with constexpr"
239 #else
240   #define ITK_CONSTEXPR_FUNC constexpr
241   #define ITK_CONSTEXPR_VAR constexpr
242 #endif
243 
244 // Use "ITK_FALLTHROUGH;" to annotate deliberate fall-through in switches,
245 // use it analogously to "break;".  The trailing semi-colon is required.
246 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER )
247 # if ( __GNUC__ >= 7 )
248 #  define ITK_FALLTHROUGH __attribute__((fallthrough))
249 # endif
250 #elif defined(__has_warning)
251 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
252 #  define ITK_FALLTHROUGH [[clang::fallthrough]]
253 # endif
254 #endif
255 
256 #ifndef ITK_FALLTHROUGH
257 # define ITK_FALLTHROUGH ((void)0)
258 #endif
259 
260 /** Define two object creation methods.  The first method, New(),
261  * creates an object from a class, potentially deferring to a factory.
262  * The second method, CreateAnother(), creates an object from an
263  * instance, potentially deferring to a factory.  This second method
264  * allows you to create an instance of an object that is exactly the
265  * same type as the referring object.  This is useful in cases where
266  * an object has been cast back to a base class.
267  *
268  * These creation methods first try asking the object factory to create
269  * an instance, and then default to the standard "new" operator if the
270  * factory fails.
271  *
272  * These routines assigns the raw pointer to a smart pointer and then call
273  * UnRegister() on the rawPtr to compensate for LightObject's constructor
274  * initializing an object's reference count to 1 (needed for proper
275  * initialization of process objects and data objects cycles).
276  *
277  * Break the methods into itkSimpleNewMacro and itkCreateAnotherMacro
278  * so we can selectively overload CreateAnother() without having to
279  * provide a definition for New(). */
280 #define itkNewMacro(x)                                         \
281   itkSimpleNewMacro(x)                                         \
282   itkCreateAnotherMacro(x)                                     \
283   itkCloneMacro(x)
284 
285 #define itkSimpleNewMacro(x)                                   \
286   static Pointer New()                                         \
287     {                                                          \
288     Pointer smartPtr = ::itk::ObjectFactory< x >::Create();    \
289     if ( smartPtr == nullptr )                                 \
290       {                                                        \
291       smartPtr = new x;                                        \
292       }                                                        \
293     smartPtr->UnRegister();                                    \
294     return smartPtr;                                           \
295     }
296 
297 #define itkCreateAnotherMacro(x)                               \
298   ::itk::LightObject::Pointer CreateAnother() const override   \
299     {                                                          \
300     ::itk::LightObject::Pointer smartPtr;                      \
301     smartPtr = x::New().GetPointer();                          \
302     return smartPtr;                                           \
303     }
304 
305 #define itkCloneMacro(x)                                       \
306   Pointer Clone() const                                        \
307   {                                                            \
308     Pointer rval =                                             \
309       dynamic_cast<x *>(this->InternalClone().GetPointer());   \
310     return rval;                                               \
311   }
312 
313 /** Define two object creation methods.  The first method, New(),
314  * creates an object from a class but does not defer to a factory.
315  * The second method, CreateAnother(), creates an object from an
316  * instance, again without deferring to a factory.  This second method
317  * allows you to create an instance of an object that is exactly the
318  * same type as the referring object.  This is useful in cases where
319  * an object has been cast back to a base class.
320  *
321  * These routines assigns the raw pointer to a smart pointer and then call
322  * UnRegister() on the rawPtr to compensate for LightObject's constructor
323  * initializing an object's reference count to 1 (needed for proper
324  * initialization of process objects and data objects cycles). */
325 #define itkFactorylessNewMacro(x)                              \
326   static Pointer New()                                         \
327     {                                                          \
328     Pointer smartPtr;                                          \
329     x *     rawPtr = new x;                                    \
330     smartPtr = rawPtr;                                         \
331     rawPtr->UnRegister();                                      \
332     return smartPtr;                                           \
333     }                                                          \
334   ::itk::LightObject::Pointer CreateAnother() const override   \
335     {                                                          \
336     ::itk::LightObject::Pointer smartPtr;                      \
337     smartPtr = x::New().GetPointer();                          \
338     return smartPtr;                                           \
339     }
340 
341 //
342 // A macro to disallow the copy constructor, copy assignment,
343 // move constructor, and move assignment functions.
344 // This should be used in the public: declarations for a class
345 //
346 // ITK's paradigm for smart pointer and pipeline consistency
347 // prohibits the use of copy/move construction and copy/move assignment
348 // functions.
349 //
350 #define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName)   \
351   TypeName(const TypeName&) = delete;            \
352   TypeName& operator=(const TypeName&) = delete; \
353   TypeName(TypeName&&) = delete;                 \
354   TypeName& operator=(TypeName&&) = delete
355 
356 /** Macro used to add standard methods to all classes, mainly type
357  * information. */
358 #define itkTypeMacro(thisClass, superclass)   \
359   const char *GetNameOfClass() const override \
360     {                                         \
361     return #thisClass;                        \
362     }
363 
364 #define itkTypeMacroNoParent(thisClass)      \
365   virtual const char *GetNameOfClass() const \
366   {                                          \
367     return #thisClass;                       \
368   }
369 
370 namespace itk
371 {
372 /**
373  * The following is used to output debug, warning, and error messages.
374  * Use a global function which actually calls:
375  * OutputWindow::GetInstance()->DisplayText();
376  * This is to avoid Object \#include of OutputWindow
377  * while OutputWindow \#includes Object. */
378 extern ITKCommon_EXPORT void OutputWindowDisplayText(const char *);
379 
380 extern ITKCommon_EXPORT void OutputWindowDisplayErrorText(const char *);
381 
382 extern ITKCommon_EXPORT void OutputWindowDisplayWarningText(const char *);
383 
384 extern ITKCommon_EXPORT void OutputWindowDisplayGenericOutputText(const char *);
385 
386 extern ITKCommon_EXPORT void OutputWindowDisplayDebugText(const char *);
387 } // end namespace itk
388 
389 /** This macro is used to print debug (or other information). They are
390  * also used to catch errors, etc. Example usage looks like:
391  * itkDebugMacro(<< "this is debug info" << this->SomeVariable); */
392 #if defined( NDEBUG )
393 #define itkDebugMacro(x)
394 #define itkDebugStatement(x)
395 #else
396 #define itkDebugMacro(x)                                                \
397     {                                                                   \
398     if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
399       {                                                                 \
400       std::ostringstream itkmsg;                                        \
401       itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n"     \
402              << this->GetNameOfClass() << " (" << this << "): " x       \
403              << "\n\n";                                                 \
404       ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() );      \
405       }                                                                 \
406     }
407 
408 //The itkDebugStatement is to be used to protect code that is only
409 //used in the itkDebugMacro
410 #define itkDebugStatement(x) x
411 #endif
412 
413 /** This macro is used to print warning information (i.e., unusual circumstance
414  * but not necessarily fatal.) Example usage looks like:
415  * itkWarningMacro(<< "this is warning info" << this->SomeVariable); */
416 #define itkWarningMacro(x)                                            \
417     {                                                                 \
418     if ( ::itk::Object::GetGlobalWarningDisplay() )                   \
419       {                                                               \
420       std::ostringstream itkmsg;                                      \
421       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
422              << this->GetNameOfClass() << " (" << this << "): " x     \
423              << "\n\n";                                               \
424       ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() );  \
425       }                                                               \
426     }
427 
428 //The itkDebugStatement is to be used ot protect code that is only
429 //used in the itkDebugMacro
430 #define itkWarningStatement(x) x
431 
432 #if defined( ITK_CPP_FUNCTION )
433   #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( ITK_WRAPPING_PARSER )
434     #define ITK_LOCATION __FUNCSIG__
435   #elif defined( __GNUC__ )
436     #define ITK_LOCATION __PRETTY_FUNCTION__
437   #else
438     #define ITK_LOCATION __FUNCTION__
439   #endif
440 #else
441   #define ITK_LOCATION "unknown"
442 #endif
443 
444 /** The exception macro is used to print error information (i.e., usually
445  * a condition that results in program failure). Example usage looks like:
446  * itkExceptionMacro(<< "this is error info" << this->SomeVariable); */
447 #define itkExceptionMacro(x)                                                            \
448     {                                                                                   \
449     std::ostringstream message;                                                         \
450     message << "itk::ERROR: " << this->GetNameOfClass()                                 \
451             << "(" << this << "): " x;                                                  \
452     ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
453     throw e_; /* Explicit naming to work around Intel compiler bug.  */                 \
454     }
455 
456 #define itkGenericExceptionMacro(x)                                                     \
457     {                                                                                   \
458     std::ostringstream message;                                                         \
459     message << "itk::ERROR: " x;                                                        \
460     ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
461     throw e_; /* Explicit naming to work around Intel compiler bug.  */                 \
462     }
463 
464 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage)  \
465 namespace itk {                                                   \
466 class newexcp : public parentexcp                                 \
467 {                                                                 \
468 public:                                                           \
469 newexcp( const char *file, unsigned int lineNumber ) :            \
470 parentexcp( file, lineNumber )                                    \
471 {                                                                 \
472   this->SetDescription( whatmessage );                            \
473 }                                                                 \
474 newexcp( const std::string & file, unsigned int lineNumber ) :    \
475 parentexcp( file, lineNumber )                                    \
476 {                                                                 \
477   this->SetDescription( whatmessage );                            \
478 }                                                                 \
479 itkTypeMacro(newexcp, parentexcp);                                \
480 };                                                                \
481 }
482 
483 #define itkSpecializedExceptionMacro(exceptiontype)                      \
484     {                                                                    \
485     ::itk::exceptiontype e_(__FILE__, __LINE__);                         \
486     e_.SetLocation(ITK_LOCATION);                                        \
487     throw e_; /* Explicit naming to work around Intel compiler bug.  */  \
488     }
489 
490 #define itkSpecializedMessageExceptionMacro(exceptiontype,x)             \
491     {                                                                    \
492     ::itk::exceptiontype e_(__FILE__, __LINE__);                         \
493     std::ostringstream message;                                          \
494     message << "itk::ERROR: " x;                                         \
495     e_.SetDescription(message.str().c_str());                            \
496     e_.SetLocation(ITK_LOCATION);                                        \
497     throw e_; /* Explicit naming to work around Intel compiler bug.  */  \
498     }
499 
500 
501 #define itkGenericOutputMacro(x)                                           \
502     {                                                                      \
503     if ( ::itk::Object::GetGlobalWarningDisplay() )                        \
504       {                                                                    \
505       std::ostringstream itkmsg;                                           \
506       itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n"      \
507       x << "\n\n";                                                         \
508       ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \
509       }                                                                    \
510     }
511 
512 //----------------------------------------------------------------------------
513 // Macros for simplifying the use of logging
514 //
515 #define itkLogMacro(x, y)                                \
516     {                                                    \
517     if ( this->GetLogger() )                             \
518       {                                                  \
519       this->GetLogger()->Write(::itk::LoggerBase::x, y); \
520       }                                                  \
521     }
522 
523 #define itkLogMacroStatic(obj, x, y)                    \
524     {                                                   \
525     if ( obj->GetLogger() )                             \
526       {                                                 \
527       obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
528       }                                                 \
529     }
530 
531 //----------------------------------------------------------------------------
532 // Setup legacy code policy.
533 //
534 // CMake options ITK_LEGACY_REMOVE and ITK_LEGACY_SILENT are converted
535 // They may be used to completely remove legacy code or silence the
536 // warnings.  The default is to warn about their use.
537 //
538 // Source files that test the legacy code may define ITK_LEGACY_TEST
539 // like this:
540 //
541 //  #define ITK_LEGACY_TEST
542 //  #include "itkClassWithDeprecatedMethod.h"
543 //
544 // in order to silence the warnings for calling deprecated methods.
545 // No other source files in ITK should call the methods since they are
546 // provided only for compatibility with older user code.
547 
548 // Define itkLegacyMacro to mark legacy methods where they are
549 // declared in their class.  Example usage:
550 //
551 //   // \deprecated Replaced by MyOtherMethod() as of ITK 2.0.
552 //   itkLegacyMacro(void MyMethod());
553 //
554 // See below for what to do for the method definition.
555 #if defined( ITK_LEGACY_REMOVE )
556 #define itkLegacyMacro(method) /* no ';' */
557 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( ITK_WRAPPING_PARSER )
558 // Provide legacy methods with no warnings.
559 #define itkLegacyMacro(method) method
560 #else
561 // Setup compile-time warnings for uses of deprecated methods if
562 // possible on this compiler.
563 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER )
564 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) )
565 #elif defined( _MSC_VER )
566 #define itkLegacyMacro(method) __declspec(deprecated) method
567 #else
568 #define itkLegacyMacro(method) method
569 #endif
570 #endif
571 
572 // Macros to create runtime deprecation warning messages in function
573 // bodies.  Example usage:
574 //
575 //   #if !defined( ITK_LEGACY_REMOVE )
576 //   void itkMyClass::MyOldMethod()
577 //     {
578 //     itkLegacyBodyMacro(itkMyClass::MyOldMethod, 2.0);
579 //     }
580 //
581 //   void itkMyClass::MyMethod()
582 //     {
583 //     itkLegacyReplaceBodyMacro(itkMyClass::MyMethod, 2.0,
584 //                               itkMyClass::MyOtherMethod);
585 //     }
586 //   #endif
587 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT )
588 #define itkLegacyBodyMacro(method, version)
589 #define itkLegacyReplaceBodyMacro(method, version, replace)
590 #define itkGenericLegacyBodyMacro(method, version)
591 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)
592 #else
593 #define itkLegacyBodyMacro(method, version)                          \
594   itkWarningMacro(#method " was deprecated for ITK " #version        \
595     " and will be removed in a future version.")
596 #define itkLegacyReplaceBodyMacro(method, version, replace)          \
597   itkWarningMacro( #method " was deprecated for ITK " #version       \
598     " and will be removed in a future version.  Use " #replace " instead.")
599 #define itkGenericLegacyBodyMacro(method, version) \
600   itkGenericOutputMacro(#method " was deprecated for ITK " #version  \
601     " and will be removed in a future version.")
602 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)   \
603   itkGenericOutputMacro( #method " was deprecated for ITK " #version \
604     " and will be removed in a future version.  Use " #replace " instead.")
605 #endif
606 
607 // Most modern x86 CPUs have 64 byte aligned blocks which are used for
608 // the cache lines. By aligning multi-threaded structures with the
609 // cache lines, false shared can be reduced, and performance
610 // increased.
611 #define ITK_CACHE_LINE_ALIGNMENT 64
612 
613 //
614 // itkPadStruct will add padding to a structure to ensure a minimum size
615 // for ensuring that adjacent structures do not share CACHE lines.
616 // Each struct will take up some multiple of cacheline sizes.
617 // This is particularly useful for arrays of thread private variables.
618 //
619 #define itkPadStruct( mincachesize, oldtype, newtype )                        \
620     struct newtype: public oldtype                                            \
621       {                                                                       \
622          char _StructPadding[mincachesize - (sizeof(oldtype)%mincachesize) ]; \
623       };
624 
625 //
626 // itkAlignedTypedef is a macro which creates a new typedef to make a
627 // data structure aligned.
628 //
629 #if defined( ITK_HAS_GNU_ATTRIBUTE_ALIGNED )
630 # define itkAlignedTypedef( alignment, oldtype, newtype )   \
631   typedef oldtype newtype __attribute__((aligned(alignment)))
632 #elif defined ( _MSC_VER )
633 # define itkAlignedTypedef( alignment, oldtype, newtype )   \
634   typedef __declspec(align( alignment )) oldtype newtype
635 #else
636 # define itkAlignedTypedef( alignment, oldtype, newtype )   \
637   typedef oldtype newtype
638 #endif
639 
640 #if defined ( ITK_FUTURE_LEGACY_REMOVE )
641 //=============================================================================
642 /*
643 NOTE: DEPRECATED - This macro is not longer needed to support modern
644 compilers.
645 
646  Define a common way of declaring a templated function as a friend inside a class.
647   - ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENTS(T)
648 
649   The following templated function
650 
651             template <T>
652             T add(const T & a, const T & b);
653 
654    is declared as friend with
655 
656             class A
657               {
658               public:
659                 friend Self add<>( const Self & a, const Self & b );
660               }
661 
662 */
663 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)  < >
664 #else // LEGACY_REMOVE
665 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
666 #endif
667 
668 //--------------------------------------------------------------------------------
669 //  Helper macros for Template Meta-Programming techniques of for-loops
670 // unrolling
671 //--------------------------------------------------------------------------------
672 
673 //--------------------------------------------------------------------------------
674 // Macro that generates an unrolled for loop for assigning elements of one array
675 // to elements of another array The array are assumed to be of same length
676 // (dimension), and this is also assumed to be the value of NumberOfIterations.
677 // No verification of size is performed. Casting is perfomed as part of the
678 // assignment, by using the DestinationElementType as the casting type.
679 // Source and destination array types must have defined opearator[] in their
680 // API.
681 #define itkForLoopAssignmentMacro(DestinationType,             \
682                                   SourceType,                  \
683                                   DestinationElementType,      \
684                                   DestinationArray,            \
685                                   SourceArray,                 \
686                                   NumberOfIterations)          \
687   for ( unsigned int i = 0; i < NumberOfIterations; ++i )      \
688     {                                                          \
689     DestinationArray[i] =                                      \
690       static_cast< DestinationElementType >( SourceArray[i] ); \
691     }
692 
693 //--------------------------------------------------------------------------------
694 // Macro that generates an unrolled for loop for rounding and assigning
695 // elements of one array to elements of another array The array are assumed to
696 // be of same length (dimension), and this is also assumed to be the value of
697 // NumberOfIterations.  No verification of size is performed. Casting is
698 // perfomed as part of the assignment, by using the DestinationElementType as
699 // the casting type.
700 // Source and destination array types must have defined opearator[] in their
701 // API.
702 #define itkForLoopRoundingAndAssignmentMacro(DestinationType,        \
703                                              Sourcrnd_halfintup,     \
704                                              DestinationElementType, \
705                                              DestinationArray,       \
706                                              SourceArray,            \
707                                              NumberOfIterations)     \
708   for ( unsigned int i = 0; i < NumberOfIterations; ++i )            \
709     {                                                                \
710     DestinationArray[i] =                                            \
711       itk::Math::Round< DestinationElementType >(SourceArray[i]);    \
712     }
713 
714 // end of Template Meta Programming helper macros
715 
716 #ifndef NDEBUG
717 
718 #ifdef _POSIX_SOURCE
719 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
720 #else
721 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
722 #endif
723 
724 #else
725 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
726 #endif
727 
728 #define itkAssertOrThrowMacro(test, message)                       \
729   if ( !( test ) )                                                 \
730     {                                                              \
731     std::ostringstream msgstr;                                     \
732     msgstr << message;                                             \
733     itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
734     }
735 
736 #ifndef NDEBUG
737 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
738 #else
739 #define itkAssertInDebugAndIgnoreInReleaseMacro(X)
740 #endif
741 
742 
743 //  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
744 //  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
745 //  !!  The ITK Get/Set Macros for various types !!
746 //  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
747 //  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
748 /** Portable definition of static constants.
749  *
750  * \pre \c type shall be an integral type (\c bool and enums are accepted as
751  * well). If using C++, float may be valid (see below).
752  *
753  * \warning If the compiler does not support in-class member initialization,
754  * the constants will be signed integers. You may observe warnings due to signed /
755  * unsigned comparisons.
756  *
757  * When using C++11 or greater, constexpr
758  * may be necessary for static const float initialization
759  * and is beneficial in other cases where a value can be constant.
760  *
761  * \ingroup ITKCommon */
762 #define itkStaticConstMacro(name,type,value) static constexpr type name = value
763 
764 #define itkGetStaticConstMacro(name) (Self::name)
765 
766 /** Set an input. This defines the Set"name"() method */
767 #define itkSetInputMacro(name, type)                                        \
768   virtual void Set##name(const type *_arg)                                  \
769     {                                                                       \
770     itkDebugMacro("setting input " #name " to " << _arg);                   \
771     if ( _arg != itkDynamicCastInDebugMode< type * >(                       \
772       this->ProcessObject::GetInput(#name) ) )                              \
773       {                                                                     \
774       this->ProcessObject::SetInput( #name, const_cast< type * >( _arg ) ); \
775       this->Modified();                                                     \
776       }                                                                     \
777     }
778 
779 /** Get an input. This defines the Get"name"() method */
780 #define itkGetInputMacro(name, type)                  \
781   virtual const type * Get##name() const              \
782     {                                                 \
783     itkDebugMacro( "returning input " << #name " of " \
784       <<  this->ProcessObject::GetInput(#name) );     \
785     return itkDynamicCastInDebugMode< const type * >( \
786       this->ProcessObject::GetInput(#name) );         \
787     }
788 
789 /** Set a decorated input. This defines the Set"name"() and a Set"name"Input() method */
790 #define itkSetDecoratedInputMacro(name, type)                                      \
791   virtual void Set##name##Input(const SimpleDataObjectDecorator< type > *_arg)     \
792     {                                                                              \
793     itkDebugMacro("setting input " #name " to " << _arg);                          \
794     if ( _arg != itkDynamicCastInDebugMode< SimpleDataObjectDecorator< type > * >( \
795       this->ProcessObject::GetInput(#name) ) )                                     \
796       {                                                                            \
797       this->ProcessObject::SetInput(                                               \
798         #name, const_cast< SimpleDataObjectDecorator< type > * >( _arg ) );        \
799       this->Modified();                                                            \
800       }                                                                            \
801     }                                                                              \
802   virtual void Set##name(const SimpleDataObjectDecorator< type > *_arg)            \
803     {                                                                              \
804     this->Set##name##Input(_arg);                                                  \
805     }                                                                              \
806   virtual void Set##name(const type &_arg)                                         \
807     {                                                                              \
808     using DecoratorType = SimpleDataObjectDecorator< type >;                       \
809     itkDebugMacro("setting input " #name " to " << _arg);                          \
810     const DecoratorType *oldInput =                                                \
811       itkDynamicCastInDebugMode< const DecoratorType * >(                          \
812         this->ProcessObject::GetInput(#name) );                                    \
813 CLANG_PRAGMA_PUSH                                                                  \
814 CLANG_SUPPRESS_Wfloat_equal                                                        \
815     if ( oldInput && oldInput->Get() == _arg )                                     \
816 CLANG_PRAGMA_POP                                                                   \
817       {                                                                            \
818       return;                                                                      \
819       }                                                                            \
820     typename DecoratorType::Pointer newInput = DecoratorType::New();               \
821     newInput->Set(_arg);                                                           \
822     this->Set##name##Input(newInput);                                              \
823     }
824 
825 /** Set a decorated input. This defines the Set"name"() and Set"name"Input() method */
826 #define itkGetDecoratedInputMacro(name, type)                                      \
827   virtual const SimpleDataObjectDecorator< type > * Get##name##Input() const       \
828     {                                                                              \
829     itkDebugMacro( "returning input " << #name " of "                              \
830       << this->ProcessObject::GetInput(#name) );                                   \
831     return itkDynamicCastInDebugMode< const SimpleDataObjectDecorator< type > * >( \
832       this->ProcessObject::GetInput(#name) );                                      \
833     }                                                                              \
834   virtual const type & Get##name() const                                           \
835     {                                                                              \
836     itkDebugMacro("Getting input " #name);                                         \
837     using DecoratorType = SimpleDataObjectDecorator< type >;                       \
838     const DecoratorType *input =                                                   \
839       itkDynamicCastInDebugMode< const DecoratorType * >(                          \
840         this->ProcessObject::GetInput(#name) );                                    \
841     if( input == nullptr )                                                         \
842       {                                                                            \
843       itkExceptionMacro(<<"input" #name " is not set");                            \
844       }                                                                            \
845     return input->Get();                                                           \
846     }
847 
848 /** Set a decorated input. This defines the Set"name"() and Set"name"Input() method
849  * and Get"name" and Get"name"Input methods */
850 #define itkSetGetDecoratedInputMacro(name, type)  \
851   itkSetDecoratedInputMacro(name, type)           \
852   itkGetDecoratedInputMacro(name, type)
853 
854 /** Set a decorated input that derives from itk::Object, but not from
855  * itk::DataObject. This defines the Set"name"() and Set"name"Input
856  * methods.
857  */
858 #define itkSetDecoratedObjectInputMacro(name, type)          \
859   virtual void Set##name##Input(const DataObjectDecorator< type > *_arg)     \
860     {                                                                        \
861     itkDebugMacro("setting input " #name " to " << _arg);                    \
862     if ( _arg != itkDynamicCastInDebugMode< DataObjectDecorator< type > * >( \
863       this->ProcessObject::GetInput(#name) ) )                               \
864       {                                                                      \
865       this->ProcessObject::SetInput( #name,                                  \
866         const_cast< DataObjectDecorator< type > * >( _arg ) );               \
867       this->Modified();                                                      \
868       }                                                                      \
869     }                                                                        \
870   virtual void Set##name(const type * _arg)                                  \
871     {                                                                        \
872     using DecoratorType = DataObjectDecorator< type >;                       \
873     itkDebugMacro("setting input " #name " to " << _arg);                    \
874     const DecoratorType *oldInput =                                          \
875       itkDynamicCastInDebugMode< const DecoratorType * >(                    \
876         this->ProcessObject::GetInput(#name) );                              \
877     if ( oldInput && oldInput->Get() == _arg )                               \
878       {                                                                      \
879       return;                                                                \
880       }                                                                      \
881     typename DecoratorType::Pointer newInput = DecoratorType::New();         \
882     newInput->Set(_arg);                                                     \
883     this->Set##name##Input(newInput);                                        \
884     }
885 
886 /** Get a decorated input that derives from itk::Object, but not from
887  * itk::DataObject. This defines the Get"name"() and Get"name"Input
888  * methods.
889  */
890 #define itkGetDecoratedObjectInputMacro(name, type)                     \
891   virtual const DataObjectDecorator< type > * Get##name##Input() const  \
892     {                                                                   \
893       itkDebugMacro( "returning input " << #name " of "                 \
894         << this->ProcessObject::GetInput(#name) );                      \
895     return itkDynamicCastInDebugMode<                                   \
896       const DataObjectDecorator< type > * >(                            \
897       this->ProcessObject::GetInput(#name) );                           \
898     }                                                                   \
899   virtual const type * Get##name() const                                \
900     {                                                                   \
901     itkDebugMacro("Getting input " #name);                              \
902     using DecoratorType = DataObjectDecorator< type >;                  \
903     const DecoratorType *input =                                        \
904       itkDynamicCastInDebugMode< const DecoratorType * >(               \
905         this->ProcessObject::GetInput(#name) );                         \
906     if( input == nullptr )                                              \
907       {                                                                 \
908       return nullptr;                                                   \
909       }                                                                 \
910     return input->Get();                                                \
911     }
912 
913 /** Set a decorated input. This defines the Set"name"() and Set"name"Input() method
914  * and Get"name" and Get"name"Input methods */
915 #define itkSetGetDecoratedObjectInputMacro(name, type)  \
916   itkSetDecoratedObjectInputMacro(name, type)           \
917   itkGetDecoratedObjectInputMacro(name, type)
918 
919 /** Set built-in type.  Creates member Set"name"() (e.g., SetVisibility()); */
920 #define itkSetMacro(name, type)                     \
921   virtual void Set##name (const type _arg)          \
922     {                                               \
923     itkDebugMacro("setting " #name " to " << _arg); \
924 CLANG_PRAGMA_PUSH                                   \
925 CLANG_SUPPRESS_Wfloat_equal                         \
926     if ( this->m_##name != _arg )                   \
927       {                                             \
928       this->m_##name = _arg;                        \
929       this->Modified();                             \
930       }                                             \
931 CLANG_PRAGMA_POP                                    \
932     }
933 
934 /** Get built-in type.  Creates member Get"name"() (e.g., GetVisibility()); */
935 #define itkGetMacro(name, type)  \
936   virtual type Get##name ()      \
937     {                            \
938     return this->m_##name;       \
939     }
940 
941 /** Get built-in type.  Creates member Get"name"() (e.g., GetVisibility());
942  * This is the "const" form of the itkGetMacro.  It should be used unless
943  * the member can be changed through the "Get" access routine. */
944 #define itkGetConstMacro(name, type)  \
945   virtual type Get##name () const     \
946     {                                 \
947     return this->m_##name;            \
948     }
949 
950 /** Get built-in type.  Creates member Get"name"() (e.g., GetVisibility());
951  * This is the "const" form of the itkGetMacro.  It should be used unless
952  * the member can be changed through the "Get" access routine.
953  * This versions returns a const reference to the variable. */
954 #define itkGetConstReferenceMacro(name, type)  \
955   virtual const type &Get##name () const       \
956     {                                          \
957     return this->m_##name;                     \
958     }
959 
960 /** Set built-in type.  Creates member Set"name"() (e.g., SetVisibility());
961  * This should be used when the type is an enum. It is used to avoid warnings on
962  * some compilers with non specified enum types passed to
963  * itkDebugMacro. */
964 #define itkSetEnumMacro(name, type)         \
965   virtual void Set##name (const type _arg)  \
966     {                                       \
967     itkDebugMacro( "setting " #name " to "  \
968       << static_cast< long >( _arg ) );     \
969     if ( this->m_##name != _arg )           \
970       {                                     \
971       this->m_##name = _arg;                \
972       this->Modified();                     \
973       }                                     \
974     }
975 
976 /** Get built-in type.  Creates member Get"name"() (e.g., GetVisibility());
977   * This should be use when the type is an enum. It is use to avoid warnings on
978   * some compilers with non specified enum types passed to
979   * itkDebugMacro. */
980 #define itkGetEnumMacro(name, type)  \
981   virtual type Get##name () const    \
982     {                                \
983     return this->m_##name;           \
984     }
985 
986 /** Set character string.  Creates member Set"name"()
987  * (e.g., SetFilename(char *)). The macro assumes that
988  * the class member (name) is declared a type std::string. */
989 #define itkSetStringMacro(name)                             \
990   virtual void Set##name (const char *_arg)                 \
991     {                                                       \
992     if ( _arg && ( _arg == this->m_##name ) ) { return; }   \
993     if ( _arg )                                             \
994       {                                                     \
995       this->m_##name = _arg;                                \
996       }                                                     \
997     else                                                    \
998       {                                                     \
999       this->m_##name = "";                                  \
1000       }                                                     \
1001     this->Modified();                                       \
1002     }                                                       \
1003   virtual void Set##name (const std::string & _arg)         \
1004     {                                                       \
1005     this->Set##name( _arg.c_str() );                        \
1006     }                                                       \
1007 
1008 
1009 /** Get character string.  Creates member Get"name"()
1010  * (e.g., SetFilename(char *)). The macro assumes that
1011  * the class member (name) is declared as a type std::string. */
1012 #define itkGetStringMacro(name)            \
1013   virtual const char *Get##name () const \
1014     {                                      \
1015     return this->m_##name.c_str();       \
1016     }
1017 
1018 /** Set built-in type where value is constrained between min/max limits.
1019  * Create member Set"name"() (e.q., SetRadius()). \#defines are
1020  * convienience for clamping open-ended values. */
1021 #define itkSetClampMacro(name, type, min, max)         \
1022   virtual void Set##name (type _arg)                   \
1023     {                                                  \
1024     const type temp_extrema=( _arg < min ? min         \
1025       : ( _arg > max ? max : _arg ) );                 \
1026     itkDebugMacro("setting " << #name " to " << _arg); \
1027 CLANG_PRAGMA_PUSH                                      \
1028 CLANG_SUPPRESS_Wfloat_equal                            \
1029     if ( this->m_##name != temp_extrema )              \
1030       {                                                \
1031       this->m_##name = temp_extrema;                   \
1032       this->Modified();                                \
1033       }                                                \
1034 CLANG_PRAGMA_POP                                       \
1035     }
1036 
1037 //NOTE: warning: comparing floating point with == or != is unsafe [-Wfloat-equal]
1038 /** Set pointer to object; uses Object reference counting methodology.
1039  * Creates method Set"name"() (e.g., SetPoints()). Note that using
1040  * smart pointers requires using real pointers when setting input,
1041  * but returning smart pointers on output. */
1042 #define itkSetObjectMacro(name, type)                  \
1043   virtual void Set##name (type * _arg)                 \
1044     {                                                  \
1045     itkDebugMacro("setting " << #name " to " << _arg); \
1046 CLANG_PRAGMA_PUSH                                      \
1047 CLANG_SUPPRESS_Wfloat_equal                            \
1048     if ( this->m_##name != _arg )                      \
1049       {                                                \
1050       this->m_##name = _arg;                           \
1051       this->Modified();                                \
1052       }                                                \
1053 CLANG_PRAGMA_POP                                       \
1054     }
1055 
1056 /** Get a smart pointer to an object.  Creates the member
1057  * Get"name"() (e.g., GetPoints()).
1058  * NOTE:  This function returns a non-const
1059  * version of the internal member variable
1060  * and could easily be used to modify the
1061  * behavior of the class without
1062  * properly resetting the pipeline
1063  * symantics */
1064 // NOTE: A class can use either itkGetModifiableObjectMacro
1065 //       or itkGetObjectMacro, but not both.
1066 //       A class can use either itkGetModifiableObjectMacro
1067 //       or itkGetConstObjectMacro, but not both.
1068 //       If the desired behavior is to only provide const
1069 //       access to the itkObject ivar, then use itkGetConstObjectMacro,
1070 //       else use itkGetModifiableObjectMacro for read/write access to
1071 //       the ivar.
1072 //       It is permissable to use both itkGetObjectMacro and itkGetConstObjectMacro
1073 //       for backwards compatibility.
1074 //       If the ITK_LEGACY_REMOVE=FALSE, then it is
1075 //       permissable to use itkGetObjectMacro which
1076 //       defines both signatures itk::GetXXX() and
1077 //       itk::GetModifiableXXX()
1078 
1079 /** Get a smart const pointer to an object.  Creates the member
1080  * Get"name"() (e.g., GetPoints()). */
1081 #define itkGetConstObjectMacro(name, type)  \
1082   virtual const type * Get##name () const   \
1083     {                                       \
1084     return this->m_##name.GetPointer();     \
1085     }
1086 
1087 
1088 #if defined ( ITK_FUTURE_LEGACY_REMOVE )
1089 // In the future, the itkGetObjectMacro will be deprecated with the ITK_LEGACY_REMOVE
1090 // flag.  For now, this very advanced feature is only available
1091 // through manual setting of a compiler define -DITK_FUTURE_LEGACY_REMOVE
1092 // ("/DITK_FUTURE_LEGACY_REMOVE /EHsc" with Visual Studio)
1093 // to ease the transition from the historical GetObjectMacro to the GetModifiableObjectMacro
1094 #  define itkGetObjectMacro(name, type)                                                         \
1095   virtual type * Get##name ()                                                                   \
1096     {                                                                                           \
1097     purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1098     }
1099 
1100 #  define itkGetModifiableObjectMacro(name, type)     \
1101   virtual type * GetModifiable##name ()               \
1102     {                                                 \
1103     return this->m_##name.GetPointer();               \
1104     }                                                 \
1105   itkGetConstObjectMacro(name, type)
1106 
1107 #else  // defined ( ITK_FUTURE_LEGACY_REMOVE )
1108 /** Get a smart pointer to an object.  Creates the member
1109  * Get"name"() (e.g., GetPoints()). */
1110 # define itkGetObjectMacro(name, type)   \
1111   virtual type * Get##name ()            \
1112     {                                    \
1113     return this->m_##name.GetPointer();  \
1114     }
1115 #  define itkGetModifiableObjectMacro(name, type)  \
1116   virtual type * GetModifiable##name ()            \
1117     {                                              \
1118     return this->m_##name.GetPointer();            \
1119     }                                              \
1120   itkGetConstObjectMacro(name, type)               \
1121   itkGetObjectMacro(name, type)
1122 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1123 
1124 // For backwards compatibility define ITK_EXPORT to nothing
1125 #define ITK_EXPORT
1126 
1127 
1128 /** Get a const reference to a smart pointer to an object.
1129  * Creates the member Get"name"() (e.g., GetPoints()). */
1130 #define itkGetConstReferenceObjectMacro(name, type)          \
1131   virtual const typename type::Pointer & Get##name () const  \
1132     {                                                        \
1133     return this->m_##name;                                   \
1134     }
1135 
1136 /** Set const pointer to object; uses Object reference counting methodology.
1137  * Creates method Set"name"() (e.g., SetPoints()). Note that using
1138  * smart pointers requires using real pointers when setting input,
1139  * but returning smart pointers on output. */
1140 #define itkSetConstObjectMacro(name, type)              \
1141   virtual void Set##name (const type * _arg)            \
1142     {                                                   \
1143     itkDebugMacro("setting " << #name " to " << _arg);  \
1144     if ( this->m_##name != _arg )                       \
1145       {                                                 \
1146       this->m_##name = _arg;                            \
1147       this->Modified();                                 \
1148       }                                                 \
1149     }
1150 
1151 /** Create members "name"On() and "name"Off() (e.g., DebugOn() DebugOff()).
1152  * Set method must be defined to use this macro. */
1153 #define itkBooleanMacro(name) \
1154   virtual void name##On ()    \
1155     {                         \
1156     this->Set##name(true);    \
1157     }                         \
1158   virtual void name##Off ()   \
1159     {                         \
1160     this->Set##name(false);   \
1161     }
1162 
1163 /** General set vector macro creates a single method that copies specified
1164  * number of values into object.
1165  * Examples: void SetColor(c,3) */
1166 #define itkSetVectorMacro(name, type, count) \
1167   virtual void Set##name(type data[])        \
1168     {                                        \
1169     unsigned int i;                          \
1170     for ( i = 0; i < count; i++ )            \
1171       {                                      \
1172 CLANG_PRAGMA_PUSH                            \
1173 CLANG_SUPPRESS_Wfloat_equal                  \
1174       if ( data[i] != this->m_##name[i] )    \
1175 CLANG_PRAGMA_POP                             \
1176         {                                    \
1177         break;                               \
1178         }                                    \
1179       }                                      \
1180     if ( i < count )                         \
1181       {                                      \
1182       this->Modified();                      \
1183       for ( i = 0; i < count; i++ )          \
1184         {                                    \
1185         this->m_##name[i] = data[i];         \
1186         }                                    \
1187       }                                      \
1188     }
1189 
1190 /** Get vector macro. Returns pointer to type (i.e., array of type).
1191  * This is for efficiency. */
1192 #define itkGetVectorMacro(name, type, count) \
1193   virtual type * Get##name () const          \
1194     {                                        \
1195     return this->m_##name;                   \
1196     }
1197 
1198 /**\def itkGPUKernelClassMacro
1199  * Construct a non-templatized helper class that
1200  * provides the GPU kernel source code as a const char*
1201  */
1202 #define itkGPUKernelClassMacro(kernel)      \
1203 /**\class kernel                            \
1204  * Workaround KWstyle bug                   \
1205  * \ingroup ITKCommon                       \
1206  */                                         \
1207 class kernel                                \
1208   {                                         \
1209     public:                                 \
1210       static const char* GetOpenCLSource(); \
1211     private:                                \
1212       kernel();                             \
1213       virtual ~kernel();                    \
1214       kernel(const kernel &);               \
1215       void operator=(const kernel &);       \
1216   };
1217 
1218 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1219   static const char* GetOpenCLSource() \
1220   {                                 \
1221     return kernel::GetOpenCLSource();  \
1222   }
1223 
1224 // A useful macro in the PrintSelf method for printing member variables
1225 // which are pointers to object based on the LightObject class.
1226 #define itkPrintSelfObjectMacro(name)                                 \
1227   if (static_cast<const LightObject*>(this->m_##name) == nullptr)     \
1228     {                                                                 \
1229     os << indent << #name << ": (null)" << std::endl;                 \
1230     }                                                                 \
1231   else                                                                \
1232     {                                                                 \
1233     os << indent << #name << ": " << std::endl;                       \
1234     this->m_##name->Print(os,indent.GetNextIndent());                 \
1235     }
1236 
1237 
1238 /** Set a decorated output. This defines the Set"name"() and a Set"name"Output() method */
1239 #define itkSetDecoratedOutputMacro(name, type)                                   \
1240   virtual void Set##name##Output(const SimpleDataObjectDecorator< type > *_arg)  \
1241     {                                                                            \
1242     itkDebugMacro("setting output " #name " to " << _arg);                       \
1243     if ( _arg != itkDynamicCastInDebugMode<                                      \
1244       SimpleDataObjectDecorator< type > * >(                                     \
1245       this->ProcessObject::GetOutput(#name) ) )                                  \
1246       {                                                                          \
1247       this->ProcessObject::SetOutput( #name,                                     \
1248         const_cast< SimpleDataObjectDecorator< type > * >( _arg ) );             \
1249       this->Modified();                                                          \
1250       }                                                                          \
1251     }                                                                            \
1252   virtual void Set##name(const type &_arg)                                       \
1253     {                                                                            \
1254     using DecoratorType = SimpleDataObjectDecorator< type >;                     \
1255     itkDebugMacro("setting output " #name " to " << _arg);                       \
1256     DecoratorType *output = itkDynamicCastInDebugMode< DecoratorType * >(        \
1257         this->ProcessObject::GetOutput(#name) );                                 \
1258     if ( output )                                                                \
1259       {                                                                          \
1260       if ( output->Get() == _arg )                                               \
1261         {                                                                        \
1262         return;                                                                  \
1263         }                                                                        \
1264       else                                                                       \
1265         {                                                                        \
1266         output->Set(_arg);                                                       \
1267         }                                                                        \
1268       }                                                                          \
1269     else                                                                         \
1270       {                                                                          \
1271       typename DecoratorType::Pointer newOutput = DecoratorType::New();          \
1272       newOutput->Set(_arg);                                                      \
1273       this->Set##name##Output(newOutput);                                        \
1274       }                                                                          \
1275     }
1276 
1277 /** Set a decorated output. This defines the Get"name"() and Get"name"Output() method */
1278 #define itkGetDecoratedOutputMacro(name, type)                                \
1279   virtual const SimpleDataObjectDecorator< type > * Get##name##Output() const \
1280     {                                                                         \
1281     itkDebugMacro( "returning output " << #name " of "                        \
1282       << this->ProcessObject::GetOutput(#name) );                             \
1283     return itkDynamicCastInDebugMode<                                         \
1284       const SimpleDataObjectDecorator< type > * >(                            \
1285         this->ProcessObject::GetOutput(#name) );                              \
1286     }                                                                         \
1287   virtual const type & Get##name() const                                      \
1288     {                                                                         \
1289     itkDebugMacro("Getting output " #name);                                   \
1290     using DecoratorType = SimpleDataObjectDecorator< type >;                  \
1291     const DecoratorType *output =                                             \
1292       itkDynamicCastInDebugMode< const DecoratorType * >(                     \
1293         this->ProcessObject::GetOutput(#name) );                              \
1294     if( output == nullptr )                                                   \
1295       {                                                                       \
1296       itkExceptionMacro(<<"output" #name " is not set");                      \
1297       }                                                                       \
1298     return output->Get();                                                     \
1299     }
1300 
1301 
1302 /** Defines to provide compatibility with derived iterators.
1303  *
1304  * With ITKv5 several methods for Image Iterators have been
1305  * devirtualized for performance reasons. These definitions may help
1306  * provide legacy compatibility, or help  detecting derived iterators
1307  * relying on the virtual  interface. Compatibility for derived
1308  * classes can be achieved with defining ITKV4_COMPATIBILITY. Code
1309  * should be migrated to no longer rely on the old virtual interface.
1310  */
1311 #if defined(ITKV4_COMPATIBILITY)
1312 #define ITK_ITERATOR_VIRTUAL virtual
1313 #define ITK_ITERATOR_OVERRIDE override
1314 #define ITK_ITERATOR_FINAL
1315 #elif !defined(ITK_LEGACY_REMOVE)
1316 #define ITK_ITERATOR_VIRTUAL  virtual
1317 #define ITK_ITERATOR_OVERRIDE override
1318 #define ITK_ITERATOR_FINAL    final
1319 #else
1320 #define ITK_ITERATOR_VIRTUAL
1321 #define ITK_ITERATOR_OVERRIDE
1322 #define ITK_ITERATOR_FINAL
1323 #endif
1324 
1325 #if defined( ITKV4_COMPATIBILITY )
1326 // A macro for methods which are const in ITKv5, but not in ITKv4
1327 #define ITKv5_CONST
1328 #else
1329 // A macro for methods which are const in ITKv5, but not in ITKv4
1330 #define ITKv5_CONST const
1331 #endif
1332 
1333 #include "itkExceptionObject.h"
1334 
1335 /** itkDynamicCastInDebugMode
1336   * Use static_cast in Release builds, and dynamic_cast in Debug
1337   *
1338   * Note: this must come after:
1339   *
1340   *   #include "itkExceptionObject.h"
1341   */
1342 template <typename TTarget, typename TSource>
itkDynamicCastInDebugMode(TSource x)1343 TTarget itkDynamicCastInDebugMode(TSource x)
1344 {
1345 #ifndef NDEBUG
1346     if(x == 0)
1347       {
1348       return 0;
1349       }
1350     TTarget rval = dynamic_cast<TTarget>(x);
1351     if(rval == 0)
1352       {
1353       itkGenericExceptionMacro(<< "Failed dynamic cast to "
1354                                << typeid(TTarget).name()
1355                                << " object type = "
1356                                << x->GetNameOfClass());
1357       }
1358     return rval;
1359 #else
1360   return static_cast<TTarget>(x);
1361 #endif
1362 }
1363 
1364 #endif //end of itkMacro.h
1365