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