1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkSetGet.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /**
16  * @class   SetGet
17  *
18  * The SetGet macros are used to interface to instance variables
19  * in a standard fashion. This includes properly treating modified time
20  * and printing out debug information.
21  *
22  * Macros are available for built-in types; for character strings;
23  * vector arrays of built-in types size 2,3,4; for setting objects; and
24  * debug, warning, and error printout information.
25 */
26 
27 #ifndef vtkSetGet_h
28 #define vtkSetGet_h
29 
30 #include "vtkCommonCoreModule.h" // For export macro
31 #include "vtkSystemIncludes.h"
32 #include <math.h>
33 #include <typeinfo>
34 
35 //----------------------------------------------------------------------------
36 // Check for unsupported old compilers.
37 #if defined(_MSC_VER) && _MSC_VER < 1800
38 # error VTK requires MSVC++ 12.0 aka Visual Studio 2013 or newer
39 #endif
40 
41 #if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))
42 # error VTK requires GCC 4.8 or newer
43 #endif
44 
45 // Convert a macro representing a value to a string.
46 //
47 // Example: vtkQuoteMacro(__LINE__) will expand to "1234" whereas
48 // vtkInternalQuoteMacro(__LINE__) will expand to "__LINE__"
49 #define vtkInternalQuoteMacro(x) #x
50 #define vtkQuoteMacro(x) vtkInternalQuoteMacro(x)
51 
52 // A macro to get the name of a type
53 #define vtkImageScalarTypeNameMacro(type) \
54 (((type) == VTK_VOID) ? "void" : \
55 (((type) == VTK_BIT) ? "bit" : \
56 (((type) == VTK_CHAR) ? "char" : \
57 (((type) == VTK_SIGNED_CHAR) ? "signed char" : \
58 (((type) == VTK_UNSIGNED_CHAR) ? "unsigned char" : \
59 (((type) == VTK_SHORT) ? "short" : \
60 (((type) == VTK_UNSIGNED_SHORT) ? "unsigned short" : \
61 (((type) == VTK_INT) ? "int" : \
62 (((type) == VTK_UNSIGNED_INT) ? "unsigned int" : \
63 (((type) == VTK_LONG) ? "long" : \
64 (((type) == VTK_UNSIGNED_LONG) ? "unsigned long" : \
65 (((type) == VTK_LONG_LONG) ? "long long" : \
66 (((type) == VTK_UNSIGNED_LONG_LONG) ? "unsigned long long" : \
67 (((type) == 18 /*VTK___INT64*/) ? "__int64" : \
68 (((type) == 19 /*VTK_UNSIGNED___INT64*/) ? "unsigned __int64" : \
69 (((type) == VTK_FLOAT) ? "float" : \
70 (((type) == VTK_DOUBLE) ? "double" : \
71 (((type) == VTK_ID_TYPE) ? "idtype" : \
72 (((type) == VTK_STRING) ? "string" : \
73 (((type) == VTK_UNICODE_STRING) ? "unicode string" : \
74 (((type) == VTK_VARIANT) ? "variant" : \
75 (((type) == VTK_OBJECT) ? "object" : \
76 "Undefined"))))))))))))))))))))))
77 
78 //
79 // Set built-in type.  Creates member Set"name"() (e.g., SetVisibility());
80 //
81 #define vtkSetMacro(name,type) \
82 virtual void Set##name (type _arg) \
83 { \
84   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " #name " to " << _arg); \
85   if (this->name != _arg) \
86   { \
87     this->name = _arg; \
88     this->Modified(); \
89   } \
90 }
91 
92 //
93 // Get built-in type.  Creates member Get"name"() (e.g., GetVisibility());
94 //
95 #define vtkGetMacro(name,type) \
96 virtual type Get##name () { \
97   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " of " << this->name ); \
98   return this->name; \
99 }
100 
101 
102 //
103 // Set character string.  Creates member Set"name"()
104 // (e.g., SetFilename(char *));
105 //
106 #define vtkSetStringMacro(name) \
107 virtual void Set##name (const char* _arg) \
108 { \
109   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \
110   if ( this->name == nullptr && _arg == nullptr) { return;} \
111   if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \
112   delete [] this->name; \
113   if (_arg) \
114   { \
115     size_t n = strlen(_arg) + 1; \
116     char *cp1 =  new char[n]; \
117     const char *cp2 = (_arg); \
118     this->name = cp1; \
119     do { *cp1++ = *cp2++; } while ( --n ); \
120   } \
121   else \
122   { \
123     this->name = nullptr; \
124   } \
125   this->Modified(); \
126 }
127 
128 //
129 // Get character string.  Creates member Get"name"()
130 // (e.g., char *GetFilename());
131 //
132 #define vtkGetStringMacro(name) \
133 virtual char* Get##name () { \
134   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " of " << (this->name?this->name:"(null)")); \
135   return this->name; \
136 }
137 
138 //
139 // Set built-in type where value is constrained between min/max limits.
140 // Create member Set"name"() (eg., SetRadius()). #defines are
141 // convenience for clamping open-ended values.
142 // The Get"name"MinValue() and Get"name"MaxValue() members return the
143 // min and max limits.
144 //
145 #define vtkSetClampMacro(name,type,min,max) \
146 virtual void Set##name (type _arg) \
147 { \
148   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << _arg ); \
149   if (this->name != (_arg<min?min:(_arg>max?max:_arg))) \
150   { \
151     this->name = (_arg<min?min:(_arg>max?max:_arg)); \
152     this->Modified(); \
153   } \
154 } \
155 virtual type Get##name##MinValue () \
156 { \
157   return min; \
158 } \
159 virtual type Get##name##MaxValue () \
160 { \
161   return max; \
162 }
163 
164 //
165 // This macro defines a body of set object macro. It can be used either in
166 // the header file vtkSetObjectMacro or in the implementation one
167 // vtkSetObjectMacro. It sets the pointer to object; uses vtkObject
168 // reference counting methodology. Creates method
169 // Set"name"() (e.g., SetPoints()).
170 //
171 #define vtkSetObjectBodyMacro(name,type,args)                   \
172   {                                                             \
173   vtkDebugMacro(<< this->GetClassName() << " (" << this         \
174                 << "): setting " << #name " to " << args );     \
175   if (this->name != args)                                       \
176   {                                                           \
177     type* tempSGMacroVar = this->name;                          \
178     this->name = args;                                          \
179     if (this->name != nullptr) { this->name->Register(this); }     \
180     if (tempSGMacroVar != nullptr)                                 \
181     {                                                         \
182       tempSGMacroVar->UnRegister(this);                         \
183     }                                                         \
184     this->Modified();                                           \
185   }                                                           \
186   }
187 
188 //
189 // Set pointer to object; uses vtkObject reference counting methodology.
190 // Creates method Set"name"() (e.g., SetPoints()). This macro should
191 // be used in the header file.
192 //
193 #define vtkSetObjectMacro(name,type)            \
194 virtual void Set##name (type* _arg)             \
195 {                                               \
196   vtkSetObjectBodyMacro(name,type,_arg);        \
197 }
198 
199 //
200 // Set pointer to object; uses vtkObject reference counting methodology.
201 // Creates method Set"name"() (e.g., SetPoints()). This macro should
202 // be used in the implementation file. You will also have to write
203 // prototype in the header file. The prototype should look like this:
204 // virtual void Set"name"("type" *);
205 //
206 // Please use vtkCxxSetObjectMacro not vtkSetObjectImplementationMacro.
207 // The first one is just for people who already used it.
208 #define vtkSetObjectImplementationMacro(class,name,type)        \
209   vtkCxxSetObjectMacro(class,name,type)
210 
211 #define vtkCxxSetObjectMacro(class,name,type)   \
212 void class::Set##name (type* _arg)              \
213 {                                               \
214   vtkSetObjectBodyMacro(name,type,_arg);        \
215 }
216 
217 //
218 // Get pointer to object wrapped in vtkNew.  Creates member Get"name"
219 // (e.g., GetPoints()).  This macro should be used in the header file.
220 //
221 #define vtkGetNewMacro(name,type)                                       \
222 virtual type *Get##name ()                                              \
223 {                                                                       \
224   vtkDebugMacro(<< this->GetClassName() << " (" << this                 \
225                 << "): returning " #name " address "                    \
226                 << this->name );                                        \
227   return this->name;                                                    \
228 }
229 
230 //
231 // Get pointer to object.  Creates member Get"name" (e.g., GetPoints()).
232 // This macro should be used in the header file.
233 //
234 #define vtkGetObjectMacro(name,type)                                    \
235 virtual type *Get##name ()                                              \
236 {                                                                       \
237   vtkDebugMacro(<< this->GetClassName() << " (" << this                 \
238                 << "): returning " #name " address " << this->name );   \
239   return this->name;                                                    \
240 }
241 
242 //
243 // Create members "name"On() and "name"Off() (e.g., DebugOn() DebugOff()).
244 // Set method must be defined to use this macro.
245 //
246 #define vtkBooleanMacro(name,type) \
247   virtual void name##On () { this->Set##name(static_cast<type>(1));}   \
248   virtual void name##Off () { this->Set##name(static_cast<type>(0));}
249 
250 //
251 // Following set macros for vectors define two members for each macro.  The first
252 // allows setting of individual components (e.g, SetColor(float,float,float)),
253 // the second allows setting from an array (e.g., SetColor(float* rgb[3])).
254 // The macros vary in the size of the vector they deal with.
255 //
256 #define vtkSetVector2Macro(name,type) \
257 virtual void Set##name (type _arg1, type _arg2) \
258 { \
259   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to (" << _arg1 << "," << _arg2 << ")"); \
260   if ((this->name[0] != _arg1)||(this->name[1] != _arg2)) \
261   { \
262     this->name[0] = _arg1; \
263     this->name[1] = _arg2; \
264     this->Modified(); \
265   } \
266 } \
267 void Set##name (type _arg[2]) \
268 { \
269   this->Set##name (_arg[0], _arg[1]); \
270 }
271 
272 #define vtkGetVector2Macro(name,type) \
273 virtual type *Get##name () VTK_SIZEHINT(2) \
274 { \
275   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << this->name); \
276   return this->name; \
277 } \
278 virtual void Get##name (type &_arg1, type &_arg2) \
279 { \
280     _arg1 = this->name[0]; \
281     _arg2 = this->name[1]; \
282   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " = (" << _arg1 << "," << _arg2 << ")"); \
283 } \
284 virtual void Get##name (type _arg[2]) \
285 { \
286   this->Get##name (_arg[0], _arg[1]);\
287 }
288 
289 #define vtkSetVector3Macro(name,type) \
290 virtual void Set##name (type _arg1, type _arg2, type _arg3) \
291 { \
292   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to (" << _arg1 << "," << _arg2 << "," << _arg3 << ")"); \
293   if ((this->name[0] != _arg1)||(this->name[1] != _arg2)||(this->name[2] != _arg3)) \
294   { \
295     this->name[0] = _arg1; \
296     this->name[1] = _arg2; \
297     this->name[2] = _arg3; \
298     this->Modified(); \
299   } \
300 } \
301 virtual void Set##name (type _arg[3]) \
302 { \
303   this->Set##name (_arg[0], _arg[1], _arg[2]);\
304 }
305 
306 #define vtkGetVector3Macro(name,type) \
307 virtual type *Get##name () VTK_SIZEHINT(3) \
308 { \
309   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << this->name); \
310   return this->name; \
311 } \
312 virtual void Get##name (type &_arg1, type &_arg2, type &_arg3) \
313 { \
314     _arg1 = this->name[0]; \
315     _arg2 = this->name[1]; \
316     _arg3 = this->name[2]; \
317   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " = (" << _arg1 << "," << _arg2 << "," << _arg3 << ")"); \
318 } \
319 virtual void Get##name (type _arg[3]) \
320 { \
321   this->Get##name (_arg[0], _arg[1], _arg[2]);\
322 }
323 
324 #define vtkSetVector4Macro(name,type) \
325 virtual void Set##name (type _arg1, type _arg2, type _arg3, type _arg4) \
326 { \
327   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to (" << _arg1 << "," << _arg2 << "," << _arg3 << "," << _arg4 << ")"); \
328   if ((this->name[0] != _arg1)||(this->name[1] != _arg2)||(this->name[2] != _arg3)||(this->name[3] != _arg4)) \
329   { \
330     this->name[0] = _arg1; \
331     this->name[1] = _arg2; \
332     this->name[2] = _arg3; \
333     this->name[3] = _arg4; \
334     this->Modified(); \
335   } \
336 } \
337 virtual void Set##name (type _arg[4]) \
338 { \
339   this->Set##name (_arg[0], _arg[1], _arg[2], _arg[3]);\
340 }
341 
342 
343 #define vtkGetVector4Macro(name,type) \
344 virtual type *Get##name () VTK_SIZEHINT(4) \
345 { \
346   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << this->name); \
347   return this->name; \
348 } \
349 virtual void Get##name (type &_arg1, type &_arg2, type &_arg3, type &_arg4) \
350 { \
351     _arg1 = this->name[0]; \
352     _arg2 = this->name[1]; \
353     _arg3 = this->name[2]; \
354     _arg4 = this->name[3]; \
355   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " = (" << _arg1 << "," << _arg2 << "," << _arg3 << "," << _arg4 << ")"); \
356 } \
357 virtual void Get##name (type _arg[4]) \
358 { \
359   this->Get##name (_arg[0], _arg[1], _arg[2], _arg[3]);\
360 }
361 
362 #define vtkSetVector6Macro(name,type) \
363 virtual void Set##name (type _arg1, type _arg2, type _arg3, type _arg4, type _arg5, type _arg6) \
364 { \
365   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to (" << _arg1 << "," << _arg2 << "," << _arg3 << "," << _arg4 << "," << _arg5 << "," << _arg6 << ")"); \
366   if ((this->name[0] != _arg1)||(this->name[1] != _arg2)||(this->name[2] != _arg3)||(this->name[3] != _arg4)||(this->name[4] != _arg5)||(this->name[5] != _arg6)) \
367   { \
368     this->name[0] = _arg1; \
369     this->name[1] = _arg2; \
370     this->name[2] = _arg3; \
371     this->name[3] = _arg4; \
372     this->name[4] = _arg5; \
373     this->name[5] = _arg6; \
374     this->Modified(); \
375   } \
376 } \
377 virtual void Set##name (type _arg[6]) \
378 { \
379   this->Set##name (_arg[0], _arg[1], _arg[2], _arg[3], _arg[4], _arg[5]);\
380 }
381 
382 #define vtkGetVector6Macro(name,type) \
383 virtual type *Get##name () VTK_SIZEHINT(6) \
384 { \
385   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << this->name); \
386   return this->name; \
387 } \
388 virtual void Get##name (type &_arg1, type &_arg2, type &_arg3, type &_arg4, type &_arg5, type &_arg6) \
389 { \
390     _arg1 = this->name[0]; \
391     _arg2 = this->name[1]; \
392     _arg3 = this->name[2]; \
393     _arg4 = this->name[3]; \
394     _arg5 = this->name[4]; \
395     _arg6 = this->name[5]; \
396   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " = (" << _arg1 << "," << _arg2 << "," << _arg3 << "," << _arg4 << "," << _arg5 <<"," << _arg6 << ")"); \
397 } \
398 virtual void Get##name (type _arg[6]) \
399 { \
400   this->Get##name (_arg[0], _arg[1], _arg[2], _arg[3], _arg[4], _arg[5]);\
401 }
402 
403 //
404 // General set vector macro creates a single method that copies specified
405 // number of values into object.
406 // Examples: void SetColor(c,3)
407 //
408 #define vtkSetVectorMacro(name,type,count) \
409 virtual void Set##name(type data[]) \
410 { \
411   int i; \
412   for (i=0; i<count; i++) { if ( data[i] != this->name[i] ) { break; }} \
413   if ( i < count ) \
414   { \
415     for (i=0; i<count; i++) { this->name[i] = data[i]; }\
416     this->Modified(); \
417   } \
418 }
419 
420 //
421 // Get vector macro defines two methods. One returns pointer to type
422 // (i.e., array of type). This is for efficiency. The second copies data
423 // into user provided array. This is more object-oriented.
424 // Examples: float *GetColor() and void GetColor(float c[count]).
425 //
426 #define vtkGetVectorMacro(name,type,count) \
427 virtual type *Get##name () VTK_SIZEHINT(count)\
428 { \
429   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " << #name " pointer " << this->name); \
430   return this->name; \
431 } \
432 virtual void Get##name (type data[count]) \
433 { \
434   for (int i=0; i<count; i++) { data[i] = this->name[i]; }\
435 }
436 
437 // Use a global function which actually calls:
438 //  vtkOutputWindow::GetInstance()->DisplayText();
439 // This is to avoid vtkObject #include of vtkOutputWindow
440 // while vtkOutputWindow #includes vtkObject
441 
442 extern VTKCOMMONCORE_EXPORT void vtkOutputWindowDisplayText(const char*);
443 extern VTKCOMMONCORE_EXPORT void vtkOutputWindowDisplayErrorText(const char*);
444 extern VTKCOMMONCORE_EXPORT void vtkOutputWindowDisplayWarningText(const char*);
445 extern VTKCOMMONCORE_EXPORT void vtkOutputWindowDisplayGenericWarningText(const char*);
446 extern VTKCOMMONCORE_EXPORT void vtkOutputWindowDisplayDebugText(const char*);
447 
448 //
449 // This macro is used for any output that may not be in an instance method
450 // vtkGenericWarningMacro(<< "this is debug info" << this->SomeVariable);
451 //
452 #define vtkGenericWarningMacro(x) \
453 { if (vtkObject::GetGlobalWarningDisplay()) { \
454       vtkOStreamWrapper::EndlType endl; \
455       vtkOStreamWrapper::UseEndl(endl); \
456       vtkOStrStreamWrapper vtkmsg; \
457       vtkmsg << "Generic Warning: In " __FILE__ ", line " << __LINE__ << "\n" x \
458       << "\n\n"; \
459       vtkOutputWindowDisplayGenericWarningText(vtkmsg.str());\
460       vtkmsg.rdbuf()->freeze(0);}}
461 
462 //
463 // This macro is used for debug statements in instance methods
464 // vtkDebugMacro(<< "this is debug info" << this->SomeVariable);
465 //
466 #define vtkDebugMacro(x) \
467    vtkDebugWithObjectMacro(this,x)
468 
469 //
470 // This macro is used to print out warning messages.
471 // vtkWarningMacro(<< "Warning message" << variable);
472 //
473 #define vtkWarningMacro(x)                      \
474    vtkWarningWithObjectMacro(this,x)
475 
476 //
477 // This macro is used to print out errors
478 // vtkErrorMacro(<< "Error message" << variable);
479 //
480 #define vtkErrorMacro(x)                        \
481    vtkErrorWithObjectMacro(this,x)
482 
483 //
484 // This macro is used to print out errors
485 // vtkErrorWithObjectMacro(self, << "Error message" << variable);
486 // self can be null
487 // Using two casts here so that nvcc compiler can handle const this
488 // pointer properly
489 //
490 #define vtkErrorWithObjectMacro(self, x)                             \
491 {                                                                    \
492   vtkObject* _object = const_cast<vtkObject*>(static_cast            \
493 <const vtkObject*>(self));                                           \
494   if (vtkObject::GetGlobalWarningDisplay())                          \
495   {                                                                  \
496     vtkOStreamWrapper::EndlType endl;                                \
497     vtkOStreamWrapper::UseEndl(endl);                                \
498     vtkOStrStreamWrapper vtkmsg;                                     \
499     vtkmsg << "ERROR: In " __FILE__ ", line " << __LINE__ << "\n";   \
500     if (_object)                                                     \
501     {                                                                \
502       vtkmsg << _object->GetClassName() << " (" << _object << "): "; \
503     }                                                                \
504     vtkmsg << "" x << "\n\n";                                        \
505     if (_object && _object->HasObserver("ErrorEvent") )              \
506     {                                                                \
507       _object->InvokeEvent("ErrorEvent", vtkmsg.str());              \
508     }                                                                \
509     else                                                             \
510     {                                                                \
511       vtkOutputWindowDisplayErrorText(vtkmsg.str());                 \
512     }                                                                \
513     vtkmsg.rdbuf()->freeze(0); vtkObject::BreakOnError();            \
514   }                                                                  \
515 }
516 
517 //
518 // This macro is used to print out warnings
519 // vtkWarningWithObjectMacro(self, "Warning message" << variable);
520 // self can be null
521 // Using two casts here so that nvcc compiler can handle const this
522 // pointer properly
523 //
524 #define vtkWarningWithObjectMacro(self, x)                           \
525 {                                                                    \
526   vtkObject* _object = const_cast<vtkObject*>(static_cast            \
527 <const vtkObject*>(self));                                           \
528   if (vtkObject::GetGlobalWarningDisplay())                          \
529   {                                                                  \
530     vtkOStreamWrapper::EndlType endl;                                \
531     vtkOStreamWrapper::UseEndl(endl);                                \
532     vtkOStrStreamWrapper vtkmsg;                                     \
533     vtkmsg << "Warning: In " __FILE__ ", line " << __LINE__ << "\n"; \
534     if (_object)                                                     \
535     {                                                                \
536       vtkmsg << _object->GetClassName() << " (" << _object << "): "; \
537     }                                                                \
538     vtkmsg << "" x << "\n\n";                                        \
539                                                                      \
540     if (_object && _object->HasObserver("WarningEvent"))             \
541     {                                                                \
542       _object->InvokeEvent("WarningEvent", vtkmsg.str());            \
543     }                                                                \
544     else                                                             \
545     {                                                                \
546       vtkOutputWindowDisplayWarningText(vtkmsg.str());               \
547     }                                                                \
548     vtkmsg.rdbuf()->freeze(0);                                       \
549   }                                                                  \
550 }
551 
552 /**
553  * This macro is used to print out debug message
554  * vtkDebugWithObjectMacro(self, "Warning message" << variable);
555  * self can be null
556  * Using two casts here so that nvcc compiler can handle const this
557  * pointer properly
558  */
559 #ifdef NDEBUG
560 # define vtkDebugWithObjectMacro(self, x)
561 #else
562 # define vtkDebugWithObjectMacro(self, x)                                        \
563 {                                                                                \
564   vtkObject* _object = const_cast<vtkObject*>(static_cast                        \
565 <const vtkObject*>(self));                                                       \
566   if ((!_object || _object->GetDebug()) && vtkObject::GetGlobalWarningDisplay()) \
567   {                                                                              \
568     vtkOStreamWrapper::EndlType endl;                                            \
569     vtkOStreamWrapper::UseEndl(endl);                                            \
570     vtkOStrStreamWrapper vtkmsg;                                                 \
571     vtkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n";               \
572     if (_object)                                                                 \
573     {                                                                            \
574       vtkmsg << _object->GetClassName() << " (" << _object << "): ";             \
575     }                                                                            \
576     vtkmsg << "" x << "\n\n";                                                    \
577     vtkOutputWindowDisplayDebugText(vtkmsg.str());                               \
578     vtkmsg.rdbuf()->freeze(0);                                                   \
579   }                                                                              \
580 }
581 #endif
582 
583 //
584 // This macro is used to quiet compiler warnings about unused parameters
585 // to methods. Only use it when the parameter really shouldn't be used.
586 // Don't use it as a way to shut up the compiler while you take your
587 // sweet time getting around to implementing the method.
588 //
589 #define vtkNotUsed(x)
590 
591 //
592 // This macro is used for functions which may not be used in a translation unit
593 // due to different paths taken based on template types. Please give a reason
594 // why the function may be considered unused (within a translation unit). For
595 // example, a template specialization might not be used in compiles of sources
596 // which use different template types.
597 //
598 #ifdef __GNUC__
599 #define vtkMaybeUnused(reason) __attribute__((unused))
600 #else
601 #define vtkMaybeUnused(reason)
602 #endif
603 
604 #define vtkWorldCoordinateMacro(name) \
605 virtual vtkCoordinate *Get##name##Coordinate () \
606 { \
607     vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " #name "Coordinate address " << this->name##Coordinate ); \
608     return this->name##Coordinate; \
609 } \
610 virtual void Set##name(double x[3]) {this->Set##name(x[0],x[1],x[2]);} \
611 virtual void Set##name(double x, double y, double z) \
612 { \
613     this->name##Coordinate->SetValue(x,y,z); \
614 } \
615 virtual double *Get##name() VTK_SIZEHINT(3)\
616 { \
617     return this->name##Coordinate->GetValue(); \
618 }
619 
620 #define vtkViewportCoordinateMacro(name) \
621 virtual vtkCoordinate *Get##name##Coordinate () \
622 { \
623     vtkDebugMacro(<< this->GetClassName() << " (" << this << "): returning " #name "Coordinate address " << this->name##Coordinate ); \
624     return this->name##Coordinate; \
625 } \
626 virtual void Set##name(double x[2]) {this->Set##name(x[0],x[1]);} \
627 virtual void Set##name(double x, double y) \
628 { \
629     this->name##Coordinate->SetValue(x,y); \
630 } \
631 virtual double *Get##name() VTK_SIZEHINT(2)\
632 { \
633     return this->name##Coordinate->GetValue(); \
634 }
635 
636 // Allows definition of vtkObject API such that NewInstance may return a
637 // superclass of thisClass.
638 #define vtkAbstractTypeMacroWithNewInstanceType(thisClass,superclass,instanceType,thisClassName) \
639   protected: \
640   const char* GetClassNameInternal() const override \
641   { \
642     return thisClassName; \
643   } \
644   public: \
645   typedef superclass Superclass; \
646   static vtkTypeBool IsTypeOf(const char *type) \
647   { \
648     if ( !strcmp(thisClassName,type) ) \
649     { \
650       return 1; \
651     } \
652     return superclass::IsTypeOf(type); \
653   } \
654   vtkTypeBool IsA(const char *type) override \
655   { \
656     return this->thisClass::IsTypeOf(type); \
657   } \
658   static thisClass* SafeDownCast(vtkObjectBase *o) \
659   { \
660     if ( o && o->IsA(thisClassName) ) \
661     { \
662       return static_cast<thisClass *>(o); \
663     } \
664     return nullptr;\
665   } \
666   VTK_NEWINSTANCE instanceType *NewInstance() const \
667   { \
668     return instanceType::SafeDownCast(this->NewInstanceInternal()); \
669   }
670 
671 // Same as vtkTypeMacro, but adapted for cases where thisClass is abstract.
672 #define vtkAbstractTypeMacro(thisClass,superclass) \
673   vtkAbstractTypeMacroWithNewInstanceType(thisClass, superclass, thisClass, #thisClass) \
674   public:
675 
676 // Macro used to determine whether a class is the same class or
677 // a subclass of the named class.
678 #define vtkTypeMacro(thisClass,superclass) \
679   vtkAbstractTypeMacro(thisClass, superclass) \
680   protected: \
681   vtkObjectBase *NewInstanceInternal() const override \
682   { \
683     return thisClass::New(); \
684   } \
685   public:
686 
687 // Macro to use when you are a direct child class of vtkObjectBase, instead
688 // of vtkTypeMacro. This is required to properly specify NewInstanceInternal
689 // as a virtual method.
690 // It is used to determine whether a class is the same class or a subclass
691 // of the named class.
692 
693 #define vtkBaseTypeMacro(thisClass,superclass) \
694   vtkAbstractTypeMacro(thisClass, superclass) \
695   protected: \
696   virtual vtkObjectBase *NewInstanceInternal() const \
697   { \
698     return thisClass::New(); \
699   } \
700   public:
701 
702 // Version of vtkAbstractTypeMacro for when thisClass is templated.
703 // For templates, we use the compiler generated typeid(...).name() identifier
704 // to distinguish classes. Otherwise, the template parameter names would appear
705 // in the class name, rather than the actual parameters. The resulting name may
706 // not be human readable on some platforms, but it will at least be unique. On
707 // GCC 4.9.2 release builds, this ends up being the same performance-wise as
708 // returning a string literal as the name() string is resolved at compile time.
709 //
710 // If either class has multiple template parameters, the commas will interfere
711 // with the macro call. In this case, create a typedef to the multi-parameter
712 // template class and pass that into the macro instead.
713 #define vtkAbstractTemplateTypeMacro(thisClass,superclass) \
714   vtkAbstractTypeMacroWithNewInstanceType(thisClass, superclass, thisClass, typeid(thisClass).name()) \
715   public:
716 
717 // Version of vtkTypeMacro for when thisClass is templated.
718 // See vtkAbstractTemplateTypeMacro for more info.
719 #define vtkTemplateTypeMacro(thisClass,superclass) \
720   vtkAbstractTemplateTypeMacro(thisClass, superclass) \
721   protected: \
722   vtkObjectBase *NewInstanceInternal() const override \
723   { \
724     return thisClass::New(); \
725   } \
726   public:
727 
728 // NOTE: This is no longer the prefer method for dispatching an array to a
729 // worker template. See vtkArrayDispatch for the new approach.
730 //
731 // The vtkTemplateMacro is used to centralize the set of types
732 // supported by Execute methods.  It also avoids duplication of long
733 // switch statement case lists.
734 //
735 // This version of the macro allows the template to take any number of
736 // arguments.  Example usage:
737 // switch(array->GetDataType())
738 //   {
739 //   vtkTemplateMacro(myFunc(static_cast<VTK_TT*>(data), arg2));
740 //   }
741 #define vtkTemplateMacroCase(typeN, type, call)     \
742   case typeN: { typedef type VTK_TT; call; }; break
743 #define vtkTemplateMacro(call)                                              \
744   vtkTemplateMacroCase(VTK_DOUBLE, double, call);                           \
745   vtkTemplateMacroCase(VTK_FLOAT, float, call);                             \
746   vtkTemplateMacroCase(VTK_LONG_LONG, long long, call);                     \
747   vtkTemplateMacroCase(VTK_UNSIGNED_LONG_LONG, unsigned long long, call);   \
748   vtkTemplateMacroCase(VTK_ID_TYPE, vtkIdType, call);                       \
749   vtkTemplateMacroCase(VTK_LONG, long, call);                               \
750   vtkTemplateMacroCase(VTK_UNSIGNED_LONG, unsigned long, call);             \
751   vtkTemplateMacroCase(VTK_INT, int, call);                                 \
752   vtkTemplateMacroCase(VTK_UNSIGNED_INT, unsigned int, call);               \
753   vtkTemplateMacroCase(VTK_SHORT, short, call);                             \
754   vtkTemplateMacroCase(VTK_UNSIGNED_SHORT, unsigned short, call);           \
755   vtkTemplateMacroCase(VTK_CHAR, char, call);                               \
756   vtkTemplateMacroCase(VTK_SIGNED_CHAR, signed char, call);                 \
757   vtkTemplateMacroCase(VTK_UNSIGNED_CHAR, unsigned char, call)
758 
759 // This is same as Template macro with additional case for VTK_STRING.
760 #define vtkExtendedTemplateMacro(call)                                 \
761   vtkTemplateMacro(call);                                                   \
762   vtkTemplateMacroCase(VTK_STRING, vtkStdString, call)
763 
764 // The vtkTemplate2Macro is used to dispatch like vtkTemplateMacro but
765 // over two template arguments instead of one.
766 //
767 // Example usage:
768 // switch(vtkTemplate2PackMacro(array1->GetDataType(),
769 //                              array2->GetDataType()))
770 //   {
771 //   vtkTemplateMacro(myFunc(static_cast<VTK_T1*>(data1),
772 //                           static_cast<VTK_T2*>(data2),
773 //                           otherArg));
774 //   }
775 #define vtkTemplate2Macro(call) \
776   vtkTemplate2MacroCase1(VTK_DOUBLE, double, call);                           \
777   vtkTemplate2MacroCase1(VTK_FLOAT, float, call);                             \
778   vtkTemplate2MacroCase1(VTK_LONG_LONG, long long, call);                     \
779   vtkTemplate2MacroCase1(VTK_UNSIGNED_LONG_LONG, unsigned long long, call);   \
780   vtkTemplate2MacroCase1(VTK_ID_TYPE, vtkIdType, call);                       \
781   vtkTemplate2MacroCase1(VTK_LONG, long, call);                               \
782   vtkTemplate2MacroCase1(VTK_UNSIGNED_LONG, unsigned long, call);             \
783   vtkTemplate2MacroCase1(VTK_INT, int, call);                                 \
784   vtkTemplate2MacroCase1(VTK_UNSIGNED_INT, unsigned int, call);               \
785   vtkTemplate2MacroCase1(VTK_SHORT, short, call);                             \
786   vtkTemplate2MacroCase1(VTK_UNSIGNED_SHORT, unsigned short, call);           \
787   vtkTemplate2MacroCase1(VTK_CHAR, char, call);                               \
788   vtkTemplate2MacroCase1(VTK_SIGNED_CHAR, signed char, call);                 \
789   vtkTemplate2MacroCase1(VTK_UNSIGNED_CHAR, unsigned char, call)
790 #define vtkTemplate2MacroCase1(type1N, type1, call) \
791   vtkTemplate2MacroCase2(type1N, type1, VTK_DOUBLE, double, call);                 \
792   vtkTemplate2MacroCase2(type1N, type1, VTK_FLOAT, float, call);                   \
793   vtkTemplate2MacroCase2(type1N, type1, VTK_LONG_LONG, long long, call);                  \
794   vtkTemplate2MacroCase2(type1N, type1, VTK_UNSIGNED_LONG_LONG, unsigned long long, call); \
795   vtkTemplate2MacroCase2(type1N, type1, VTK_ID_TYPE, vtkIdType, call);             \
796   vtkTemplate2MacroCase2(type1N, type1, VTK_LONG, long, call);                     \
797   vtkTemplate2MacroCase2(type1N, type1, VTK_UNSIGNED_LONG, unsigned long, call);   \
798   vtkTemplate2MacroCase2(type1N, type1, VTK_INT, int, call);                       \
799   vtkTemplate2MacroCase2(type1N, type1, VTK_UNSIGNED_INT, unsigned int, call);     \
800   vtkTemplate2MacroCase2(type1N, type1, VTK_SHORT, short, call);                   \
801   vtkTemplate2MacroCase2(type1N, type1, VTK_UNSIGNED_SHORT, unsigned short, call); \
802   vtkTemplate2MacroCase2(type1N, type1, VTK_CHAR, char, call);                     \
803   vtkTemplate2MacroCase2(type1N, type1, VTK_SIGNED_CHAR, signed char, call);       \
804   vtkTemplate2MacroCase2(type1N, type1, VTK_UNSIGNED_CHAR, unsigned char, call)
805 #define vtkTemplate2MacroCase2(type1N, type1, type2N, type2, call) \
806   case vtkTemplate2PackMacro(type1N, type2N): { \
807     typedef type1 VTK_T1; \
808     typedef type2 VTK_T2; \
809     call; \
810   }; break
811 #define vtkTemplate2PackMacro(type1N, type2N) \
812   ((((type1N) & 0xFF) << 8) | \
813     ((type2N) & 0xFF))
814 
815 // The vtkArrayIteratorTemplateMacro is used to centralize the set of types
816 // supported by Execute methods.  It also avoids duplication of long
817 // switch statement case lists.
818 //
819 // This version of the macro allows the template to take any number of
820 // arguments.
821 //
822 // Note that in this macro VTK_TT is defined to be the type of the iterator
823 // for the given type of array. One must include the
824 // vtkArrayIteratorIncludes.h header file to provide for extending of this macro
825 // by addition of new iterators.
826 //
827 // Example usage:
828 // vtkArrayIter* iter = array->NewIterator();
829 // switch(array->GetDataType())
830 //   {
831 //   vtkArrayIteratorTemplateMacro(myFunc(static_cast<VTK_TT*>(iter), arg2));
832 //   }
833 // iter->Delete();
834 //
835 #define vtkArrayIteratorTemplateMacroCase(typeN, type, call)  \
836   vtkTemplateMacroCase(typeN, vtkArrayIteratorTemplate<type>, call)
837 #define vtkArrayIteratorTemplateMacro(call)                                 \
838   vtkArrayIteratorTemplateMacroCase(VTK_DOUBLE, double, call);              \
839   vtkArrayIteratorTemplateMacroCase(VTK_FLOAT, float, call);                             \
840   vtkArrayIteratorTemplateMacroCase(VTK_LONG_LONG, long long, call);                     \
841   vtkArrayIteratorTemplateMacroCase(VTK_UNSIGNED_LONG_LONG, unsigned long long, call);   \
842   vtkArrayIteratorTemplateMacroCase(VTK_ID_TYPE, vtkIdType, call);                       \
843   vtkArrayIteratorTemplateMacroCase(VTK_LONG, long, call);                               \
844   vtkArrayIteratorTemplateMacroCase(VTK_UNSIGNED_LONG, unsigned long, call);             \
845   vtkArrayIteratorTemplateMacroCase(VTK_INT, int, call);                                 \
846   vtkArrayIteratorTemplateMacroCase(VTK_UNSIGNED_INT, unsigned int, call);               \
847   vtkArrayIteratorTemplateMacroCase(VTK_SHORT, short, call);                             \
848   vtkArrayIteratorTemplateMacroCase(VTK_UNSIGNED_SHORT, unsigned short, call);           \
849   vtkArrayIteratorTemplateMacroCase(VTK_CHAR, char, call);                               \
850   vtkArrayIteratorTemplateMacroCase(VTK_SIGNED_CHAR, signed char, call);                 \
851   vtkArrayIteratorTemplateMacroCase(VTK_UNSIGNED_CHAR, unsigned char, call);             \
852   vtkArrayIteratorTemplateMacroCase(VTK_STRING, vtkStdString, call);                     \
853   vtkTemplateMacroCase(VTK_BIT, vtkBitArrayIterator, call);
854 
855 //----------------------------------------------------------------------------
856 // Setup legacy code policy.
857 
858 // Define VTK_LEGACY macro to mark legacy methods where they are
859 // declared in their class.  Example usage:
860 //
861 //   // @deprecated Replaced by MyOtherMethod() as of VTK 5.0.
862 //   VTK_LEGACY(void MyMethod());
863 #if defined(VTK_LEGACY_REMOVE)
864   // Remove legacy methods completely.  Put a bogus declaration in
865   // place to avoid stray semicolons because this is an error for some
866   // compilers.  Using a class forward declaration allows any number
867   // of repeats in any context without generating unique names.
868 
869 # define VTK_LEGACY(method)         VTK_LEGACY__0(method,__LINE__)
870 # define VTK_LEGACY__0(method,line) VTK_LEGACY__1(method,line)
871 # define VTK_LEGACY__1(method,line) class vtkLegacyMethodRemoved##line
872 
873 #elif defined(VTK_LEGACY_SILENT) || defined(VTK_WRAPPING_CXX)
874   // Provide legacy methods with no warnings.
875 # define VTK_LEGACY(method) method
876 #else
877   // Setup compile-time warnings for uses of deprecated methods if
878   // possible on this compiler.
879 # if defined(__GNUC__) && !defined(__INTEL_COMPILER)
880 #  define VTK_LEGACY(method) method __attribute__((deprecated))
881 # elif defined(_MSC_VER)
882 #  define VTK_LEGACY(method) __declspec(deprecated) method
883 # else
884 #  define VTK_LEGACY(method) method
885 # endif
886 #endif
887 
888 // Macros to create runtime deprecation warning messages in function
889 // bodies.  Example usage:
890 //
891 //   #if !defined(VTK_LEGACY_REMOVE)
892 //   void vtkMyClass::MyOldMethod()
893 //   {
894 //     VTK_LEGACY_BODY(vtkMyClass::MyOldMethod, "VTK 5.0");
895 //   }
896 //   #endif
897 //
898 //   #if !defined(VTK_LEGACY_REMOVE)
899 //   void vtkMyClass::MyMethod()
900 //   {
901 //     VTK_LEGACY_REPLACED_BODY(vtkMyClass::MyMethod, "VTK 5.0",
902 //                              vtkMyClass::MyOtherMethod);
903 //   }
904 //   #endif
905 #if defined(VTK_LEGACY_REMOVE) || defined(VTK_LEGACY_SILENT)
906 # define VTK_LEGACY_BODY(method, version)
907 # define VTK_LEGACY_REPLACED_BODY(method, version, replace)
908 #else
909 # define VTK_LEGACY_BODY(method, version) \
910   vtkGenericWarningMacro(#method " was deprecated for " version " and will be removed in a future version.")
911 # define VTK_LEGACY_REPLACED_BODY(method, version, replace) \
912   vtkGenericWarningMacro(#method " was deprecated for " version " and will be removed in a future version.  Use " #replace " instead.")
913 #endif
914 
915 // Qualifiers used for function arguments and return types indicating that the
916 // class is wrapped externally.
917 #define VTK_WRAP_EXTERN
918 
919 //----------------------------------------------------------------------------
920 // Switch case fall-through policy.
921 
922 // Use "VTK_FALLTHROUGH;" to annotate deliberate fall-through in switches,
923 // use it analogously to "break;".  The trailing semi-colon is required.
924 #if !defined(VTK_FALLTHROUGH) && defined(__has_cpp_attribute)
925 # if __cplusplus >= 201703L && __has_cpp_attribute(fallthrough)
926 #  define VTK_FALLTHROUGH [[fallthrough]]
927 # elif __cplusplus >= 201103L && __has_cpp_attribute(gnu::fallthrough)
928 #  define VTK_FALLTHROUGH [[gnu::fallthrough]]
929 # elif __cplusplus >= 201103L && __has_cpp_attribute(clang::fallthrough)
930 #  define VTK_FALLTHROUGH [[clang::fallthrough]]
931 # endif
932 #endif
933 
934 #ifndef VTK_FALLTHROUGH
935 # define VTK_FALLTHROUGH ((void)0)
936 #endif
937 
938 #endif
939 // VTK-HeaderTest-Exclude: vtkSetGet.h
940