VTK  9.2.6
vtkVariant.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkVariant.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 Copyright 2008 Sandia Corporation.
17 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18 the U.S. Government retains certain rights in this software.
19-------------------------------------------------------------------------*/
31#ifndef vtkVariant_h
32#define vtkVariant_h
33
34#include "vtkCommonCoreModule.h" // For export macro
35#include "vtkObject.h" // For vtkObject's warning support
36#include "vtkSetGet.h" // For vtkNotUsed macro
37#include "vtkStdString.h"
38#include "vtkSystemIncludes.h" // To define ostream
39#include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags
40
41//
42// The following should be eventually placed in vtkSetGet.h
43//
44
45// This is same as extended template macro with an additional case for VTK_VARIANT
46#define vtkExtraExtendedTemplateMacro(call) \
47 vtkExtendedTemplateMacro(call); \
48 vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
49
50// This is same as Iterator Template macro with an additional case for VTK_VARIANT
51#define vtkExtendedArrayIteratorTemplateMacro(call) \
52 vtkArrayIteratorTemplateMacro(call); \
53 vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
54
55class vtkStdString;
56class vtkObjectBase;
58class vtkVariant;
60
61VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkVariant& val);
62
63class VTKCOMMONCORE_EXPORT vtkVariant
64{
65public:
70
75
79 vtkVariant(const vtkVariant& other);
80
84 vtkVariant(bool value);
85
89 vtkVariant(char value);
90
94 vtkVariant(unsigned char value);
95
99 vtkVariant(signed char value);
100
104 vtkVariant(short value);
105
109 vtkVariant(unsigned short value);
110
114 vtkVariant(int value);
115
119 vtkVariant(unsigned int value);
120
124 vtkVariant(long value);
125
129 vtkVariant(unsigned long value);
130
134 vtkVariant(long long value);
135
139 vtkVariant(unsigned long long value);
140
144 vtkVariant(float value);
145
149 vtkVariant(double value);
150
154 vtkVariant(const char* value);
155
160
165
169 vtkVariant(const vtkVariant& other, unsigned int type);
170
175
179 bool IsValid() const;
180
184 bool IsString() const;
185
189 bool IsNumeric() const;
190
194 bool IsFloat() const;
195
199 bool IsDouble() const;
200
204 bool IsChar() const;
205
209 bool IsUnsignedChar() const;
210
214 bool IsSignedChar() const;
215
219 bool IsShort() const;
220
224 bool IsUnsignedShort() const;
225
229 bool IsInt() const;
230
234 bool IsUnsignedInt() const;
235
239 bool IsLong() const;
240
244 bool IsUnsignedLong() const;
245
249 bool IsLongLong() const;
250
254 bool IsUnsignedLongLong() const;
255
259 bool IsVTKObject() const;
260
264 bool IsArray() const;
265
269 unsigned int GetType() const;
270
274 const char* GetTypeAsString() const;
275
277 {
278 DEFAULT_FORMATTING = 0,
279 FIXED_FORMATTING = 1,
280 SCIENTIFIC_FORMATTING = 2
281 };
282
291 vtkStdString ToString(int formatting = DEFAULT_FORMATTING, int precision = 6) const;
292
294
303 float ToFloat(bool* valid) const;
304 float ToFloat() const { return this->ToFloat(nullptr); }
305 double ToDouble(bool* valid) const;
306 double ToDouble() const { return this->ToDouble(nullptr); }
307 char ToChar(bool* valid) const;
308 char ToChar() const { return this->ToChar(nullptr); }
309 unsigned char ToUnsignedChar(bool* valid) const;
310 unsigned char ToUnsignedChar() const { return this->ToUnsignedChar(nullptr); }
311 signed char ToSignedChar(bool* valid) const;
312 signed char ToSignedChar() const { return this->ToSignedChar(nullptr); }
313 short ToShort(bool* valid) const;
314 short ToShort() const { return this->ToShort(nullptr); }
315 unsigned short ToUnsignedShort(bool* valid) const;
316 unsigned short ToUnsignedShort() const { return this->ToUnsignedShort(nullptr); }
317 int ToInt(bool* valid) const;
318 int ToInt() const { return this->ToInt(nullptr); }
319 unsigned int ToUnsignedInt(bool* valid) const;
320 unsigned int ToUnsignedInt() const { return this->ToUnsignedInt(nullptr); }
321 long ToLong(bool* valid) const;
322 long ToLong() const { return this->ToLong(nullptr); }
323 unsigned long ToUnsignedLong(bool* valid) const;
324 unsigned long ToUnsignedLong() const { return this->ToUnsignedLong(nullptr); }
325 long long ToLongLong(bool* valid) const;
326 long long ToLongLong() const { return this->ToLongLong(nullptr); }
327 unsigned long long ToUnsignedLongLong(bool* valid) const;
328 unsigned long long ToUnsignedLongLong() const { return this->ToUnsignedLongLong(nullptr); }
329 vtkTypeInt64 ToTypeInt64(bool* valid) const;
330 vtkTypeInt64 ToTypeInt64() const { return this->ToTypeInt64(nullptr); }
331 vtkTypeUInt64 ToTypeUInt64(bool* valid) const;
332 vtkTypeUInt64 ToTypeUInt64() const { return this->ToTypeUInt64(nullptr); }
334
339
344
355 bool IsEqual(const vtkVariant& other) const;
356
358
388 bool operator==(const vtkVariant& other) const;
389 bool operator!=(const vtkVariant& other) const;
390 bool operator<(const vtkVariant& other) const;
391 bool operator>(const vtkVariant& other) const;
392 bool operator<=(const vtkVariant& other) const;
393 bool operator>=(const vtkVariant& other) const;
395
396 friend VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkVariant& val);
397
398private:
399 template <typename T>
400 T ToNumeric(bool* valid, T* vtkNotUsed(ignored)) const;
401
402 union {
404 float Float;
405 double Double;
406 char Char;
407 unsigned char UnsignedChar;
408 signed char SignedChar;
409 short Short;
410 unsigned short UnsignedShort;
411 int Int;
412 unsigned int UnsignedInt;
413 long Long;
414 unsigned long UnsignedLong;
415 long long LongLong;
416 unsigned long long UnsignedLongLong;
418 } Data;
419
420 unsigned char Valid;
421 unsigned char Type;
422
423 friend struct vtkVariantLessThan;
424 friend struct vtkVariantEqual;
427};
428
429#include "vtkVariantInlineOperators.h" // needed for operator== and company
430
431// A STL-style function object so you can compare two variants using
432// comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
433// This is a faster version of operator< that makes no attempt to
434// compare values. It satisfies the STL requirement for a comparison
435// function for ordered containers like map and set.
436
437struct VTKCOMMONCORE_EXPORT vtkVariantLessThan
438{
439public:
440 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
441};
442
443struct VTKCOMMONCORE_EXPORT vtkVariantEqual
444{
445public:
446 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
447};
448
449struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder
450{
451public:
452 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
453};
454
455// Similarly, this is a fast version of operator== that requires that
456// the types AND the values be equal in order to admit equality.
457
458struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality
459{
460public:
461 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
462};
463
464#endif
465// VTK-HeaderTest-Exclude: vtkVariant.h
Abstract superclass for all arrays.
abstract base class for most VTK objects
Wrapper around std::string to keep symbols short.
A atomic type representing the union of many types.
Definition vtkVariant.h:64
vtkTypeInt64 ToTypeInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:330
vtkVariant(float value)
Create a float variant.
bool IsArray() const
Get whether the variant is a VTK array (i.e.
long long ToLongLong(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
vtkVariant & operator=(const vtkVariant &other)
Copy the value of one variant into another.
~vtkVariant()
Destruct the variant.
char ToChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:308
unsigned long long UnsignedLongLong
Definition vtkVariant.h:416
double ToDouble(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
long long ToLongLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:326
vtkTypeUInt64 ToTypeUInt64(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
unsigned short ToUnsignedShort(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
vtkVariant(unsigned long value)
Create an unsigned long variant.
bool IsUnsignedChar() const
Get whether the variant is an unsigned char.
unsigned int GetType() const
Get the type of the variant.
unsigned char ToUnsignedChar(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
unsigned char ToUnsignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:310
vtkVariant(unsigned int value)
Create an unsigned integer variant.
vtkVariant(char value)
Create a char variant.
unsigned short UnsignedShort
Definition vtkVariant.h:410
char ToChar(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
bool IsUnsignedLong() const
Get whether the variant is an unsigned long.
short Short
Definition vtkVariant.h:409
vtkVariant(int value)
Create an integer variant.
bool IsDouble() const
Get whether the variant is a double.
vtkVariant(vtkStdString value)
Create a string variant from a std string.
vtkVariant(unsigned long long value)
Create an unsigned long long variant.
long ToLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:322
const char * GetTypeAsString() const
Get the type of the variant as a string.
signed char ToSignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:312
double ToDouble() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:306
bool IsInt() const
Get whether the variant is an int.
float Float
Definition vtkVariant.h:404
vtkObjectBase * ToVTKObject() const
Return the VTK object, or nullptr if not of that type.
bool IsUnsignedInt() const
Get whether the variant is an unsigned int.
unsigned long ToUnsignedLong(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkVariant &val)
bool IsFloat() const
Get whether the variant is a float.
bool IsUnsignedShort() const
Get whether the variant is an unsigned short.
vtkVariant(long value)
Create an long variant.
float ToFloat() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:304
long long LongLong
Definition vtkVariant.h:415
vtkVariant(signed char value)
Create a signed char variant.
vtkVariant(vtkObjectBase *value)
Create a vtkObjectBase variant.
vtkStdString ToString(int formatting=DEFAULT_FORMATTING, int precision=6) const
Convert the variant to a string.
bool IsChar() const
Get whether the variant is an char.
bool IsVTKObject() const
Get whether the variant is a VTK object pointer.
short ToShort() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:314
vtkStdString * String
Definition vtkVariant.h:403
vtkVariant(long long value)
Create a long long variant.
bool IsLongLong() const
Get whether the variant is long long.
signed char ToSignedChar(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
unsigned int ToUnsignedInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:320
unsigned int UnsignedInt
Definition vtkVariant.h:412
float ToFloat(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
bool IsValid() const
Get whether the variant value is valid.
int ToInt(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
vtkVariant(bool value)
Create a bool variant.
vtkAbstractArray * ToArray() const
Return the array, or nullptr if not of that type.
unsigned long long ToUnsignedLongLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:328
long ToLong(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
bool IsSignedChar() const
Get whether the variant is an signed char.
vtkTypeInt64 ToTypeInt64(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
bool IsString() const
Get whether the variant is a string.
unsigned int ToUnsignedInt(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
vtkVariant(const vtkVariant &other)
Copy constructor.
vtkVariant(const vtkVariant &other, unsigned int type)
Create a variant of a specific type.
unsigned long ToUnsignedLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:324
vtkVariant(unsigned char value)
Create an unsigned char variant.
unsigned long UnsignedLong
Definition vtkVariant.h:414
unsigned char UnsignedChar
Definition vtkVariant.h:407
vtkVariant(short value)
Create a short variant.
vtkVariant(unsigned short value)
Create an unsigned short variant.
vtkVariant()
Create an invalid variant.
bool IsLong() const
Get whether the variant is an long.
vtkVariant(double value)
Create a double variant.
unsigned short ToUnsignedShort() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:316
bool IsEqual(const vtkVariant &other) const
Determines whether two variants have the same value.
double Double
Definition vtkVariant.h:405
vtkObjectBase * VTKObject
Definition vtkVariant.h:417
signed char SignedChar
Definition vtkVariant.h:408
bool IsNumeric() const
Get whether the variant is any numeric type.
int ToInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:318
bool IsShort() const
Get whether the variant is an short.
vtkTypeUInt64 ToTypeUInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition vtkVariant.h:332
short ToShort(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
vtkVariant(const char *value)
Create a string variant from a const char*.
unsigned long long ToUnsignedLongLong(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
bool IsUnsignedLongLong() const
Get whether the variant is unsigned long long.
bool operator()(const vtkVariant &s1, const vtkVariant &s2) const
bool operator()(const vtkVariant &s1, const vtkVariant &s2) const
bool operator()(const vtkVariant &s1, const vtkVariant &s2) const
bool operator()(const vtkVariant &s1, const vtkVariant &s2) const
bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2)
bool VTKCOMMONDATAMODEL_EXPORT operator!=(vtkEdgeBase e1, vtkEdgeBase e2)
bool operator<(const vtkPixelExtent &l, const vtkPixelExtent &r)
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkVariant &val)