VTK  9.1.0
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 "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_1_0
36#include "vtkObject.h" // For vtkObject's warning support
37#include "vtkSetGet.h" // For vtkNotUsed macro
38#include "vtkStdString.h"
39#include "vtkSystemIncludes.h" // To define ostream
40#include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags
41
42//
43// The following should be eventually placed in vtkSetGet.h
44//
45
46// This is same as extended template macro with an additional case for VTK_VARIANT
47#define vtkExtraExtendedTemplateMacro(call) \
48 vtkExtendedTemplateMacro(call); \
49 vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
50
51// This is same as Iterator Template macro with an additional case for VTK_VARIANT
52#define vtkExtendedArrayIteratorTemplateMacro(call) \
53 vtkArrayIteratorTemplateMacro(call); \
54 vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
55
56class vtkStdString;
58class vtkObjectBase;
60class vtkVariant;
62
63VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkVariant& val);
64
65class VTKCOMMONCORE_EXPORT vtkVariant
66{
67public:
72
77
81 vtkVariant(const vtkVariant& other);
82
86 vtkVariant(bool value);
87
91 vtkVariant(char value);
92
96 vtkVariant(unsigned char value);
97
101 vtkVariant(signed char value);
102
106 vtkVariant(short value);
107
111 vtkVariant(unsigned short value);
112
116 vtkVariant(int value);
117
121 vtkVariant(unsigned int value);
122
126 vtkVariant(long value);
127
131 vtkVariant(unsigned long value);
132
136 vtkVariant(long long value);
137
141 vtkVariant(unsigned long long value);
142
146 vtkVariant(float value);
147
151 vtkVariant(double value);
152
156 vtkVariant(const char* value);
157
162
166 VTK_DEPRECATED_IN_9_1_0("Use vtkVariant(vtkStdString value)")
168
173
177 vtkVariant(const vtkVariant& other, unsigned int type);
178
182 vtkVariant& operator=(const vtkVariant& other);
183
187 bool IsValid() const;
188
192 bool IsString() const;
193
197 VTK_DEPRECATED_IN_9_1_0("Use bool IsString() const")
198 bool IsUnicodeString() const;
199
203 bool IsNumeric() const;
204
208 bool IsFloat() const;
209
213 bool IsDouble() const;
214
218 bool IsChar() const;
219
223 bool IsUnsignedChar() const;
224
228 bool IsSignedChar() const;
229
233 bool IsShort() const;
234
238 bool IsUnsignedShort() const;
239
243 bool IsInt() const;
244
248 bool IsUnsignedInt() const;
249
253 bool IsLong() const;
254
258 bool IsUnsignedLong() const;
259
263 VTK_DEPRECATED_IN_9_1_0("Legacy. Returns false. The variant is never an __int64")
264 bool Is__Int64() const;
265
269 VTK_DEPRECATED_IN_9_1_0("Legacy. Returns false. The variant is never an unsigned __int64")
270 bool IsUnsigned__Int64() const;
271
275 bool IsLongLong() const;
276
280 bool IsUnsignedLongLong() const;
281
285 bool IsVTKObject() const;
286
290 bool IsArray() const;
291
295 unsigned int GetType() const;
296
300 const char* GetTypeAsString() const;
301
303 {
304 DEFAULT_FORMATTING = 0,
305 FIXED_FORMATTING = 1,
306 SCIENTIFIC_FORMATTING = 2
307 };
308
317 vtkStdString ToString(int formatting = DEFAULT_FORMATTING, int precision = 6) const;
318
328 "Use vtkStdString ToString(int formatting = DEFAULT_FORMATTING, int precision = 6)")
329 vtkUnicodeString ToUnicodeString(int formatting = DEFAULT_FORMATTING, int precision = 6) const;
330
332
341 float ToFloat(bool* valid) const;
342 float ToFloat() const { return this->ToFloat(nullptr); }
343 double ToDouble(bool* valid) const;
344 double ToDouble() const { return this->ToDouble(nullptr); }
345 char ToChar(bool* valid) const;
346 char ToChar() const { return this->ToChar(nullptr); }
347 unsigned char ToUnsignedChar(bool* valid) const;
348 unsigned char ToUnsignedChar() const { return this->ToUnsignedChar(nullptr); }
349 signed char ToSignedChar(bool* valid) const;
350 signed char ToSignedChar() const { return this->ToSignedChar(nullptr); }
351 short ToShort(bool* valid) const;
352 short ToShort() const { return this->ToShort(nullptr); }
353 unsigned short ToUnsignedShort(bool* valid) const;
354 unsigned short ToUnsignedShort() const { return this->ToUnsignedShort(nullptr); }
355 int ToInt(bool* valid) const;
356 int ToInt() const { return this->ToInt(nullptr); }
357 unsigned int ToUnsignedInt(bool* valid) const;
358 unsigned int ToUnsignedInt() const { return this->ToUnsignedInt(nullptr); }
359 long ToLong(bool* valid) const;
360 long ToLong() const { return this->ToLong(nullptr); }
361 unsigned long ToUnsignedLong(bool* valid) const;
362 unsigned long ToUnsignedLong() const { return this->ToUnsignedLong(nullptr); }
363 long long ToLongLong(bool* valid) const;
364 long long ToLongLong() const { return this->ToLongLong(nullptr); }
365 unsigned long long ToUnsignedLongLong(bool* valid) const;
366 unsigned long long ToUnsignedLongLong() const { return this->ToUnsignedLongLong(nullptr); }
367 vtkTypeInt64 ToTypeInt64(bool* valid) const;
368 vtkTypeInt64 ToTypeInt64() const { return this->ToTypeInt64(nullptr); }
369 vtkTypeUInt64 ToTypeUInt64(bool* valid) const;
370 vtkTypeUInt64 ToTypeUInt64() const { return this->ToTypeUInt64(nullptr); }
372
377
382
393 bool IsEqual(const vtkVariant& other) const;
394
396
426 bool operator==(const vtkVariant& other) const;
427 bool operator!=(const vtkVariant& other) const;
428 bool operator<(const vtkVariant& other) const;
429 bool operator>(const vtkVariant& other) const;
430 bool operator<=(const vtkVariant& other) const;
431 bool operator>=(const vtkVariant& other) const;
433
434 friend VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkVariant& val);
435
436private:
437 template <typename T>
438 T ToNumeric(bool* valid, T* vtkNotUsed(ignored)) const;
439
440 union {
443 float Float;
444 double Double;
445 char Char;
446 unsigned char UnsignedChar;
447 signed char SignedChar;
448 short Short;
449 unsigned short UnsignedShort;
450 int Int;
451 unsigned int UnsignedInt;
452 long Long;
453 unsigned long UnsignedLong;
454 long long LongLong;
455 unsigned long long UnsignedLongLong;
457 } Data;
458
459 // XXX(9.1): Remove with VTK_DEPRECATED_IN_9_1_0().
460 bool CheckUnicodeStringEqual(const vtkVariant& other) const;
461 bool CheckUnicodeStringLessThan(const vtkVariant& other) const;
462
463 unsigned char Valid;
464 unsigned char Type;
465
466 friend struct vtkVariantLessThan;
467 friend struct vtkVariantEqual;
470};
471
472#include "vtkVariantInlineOperators.h" // needed for operator== and company
473
474// A STL-style function object so you can compare two variants using
475// comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
476// This is a faster version of operator< that makes no attempt to
477// compare values. It satisfies the STL requirement for a comparison
478// function for ordered containers like map and set.
479
480struct VTKCOMMONCORE_EXPORT vtkVariantLessThan
481{
482public:
483 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
484};
485
486struct VTKCOMMONCORE_EXPORT vtkVariantEqual
487{
488public:
489 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
490};
491
492struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder
493{
494public:
495 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
496};
497
498// Similarly, this is a fast version of operator== that requires that
499// the types AND the values be equal in order to admit equality.
500
501struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality
502{
503public:
504 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
505};
506
507#endif
508// VTK-HeaderTest-Exclude: vtkVariant.h
Abstract superclass for all arrays.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:70
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:36
String class that stores Unicode text.
A atomic type representing the union of many types.
Definition: vtkVariant.h:66
vtkTypeInt64 ToTypeInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:368
vtkVariant(float value)
Create a float variant.
long long ToLongLong(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
~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:346
unsigned long long UnsignedLongLong
Definition: vtkVariant.h:455
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:364
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.
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:348
vtkVariant(unsigned int value)
Create an unsigned integer variant.
vtkVariant(char value)
Create a char variant.
unsigned short UnsignedShort
Definition: vtkVariant.h:449
char ToChar(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:442
short Short
Definition: vtkVariant.h:448
vtkVariant(int value)
Create an integer variant.
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:360
signed char ToSignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:350
double ToDouble() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:344
float Float
Definition: vtkVariant.h:443
vtkObjectBase * ToVTKObject() const
Return the VTK object, or nullptr if not of that type.
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)
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:342
long long LongLong
Definition: vtkVariant.h:454
vtkVariant(signed char value)
Create a signed char variant.
vtkStdString ToString(int formatting=DEFAULT_FORMATTING, int precision=6) const
Convert the variant to a string.
short ToShort() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:352
vtkStdString * String
Definition: vtkVariant.h:441
vtkVariant(long long value)
Create a long long variant.
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:358
unsigned int UnsignedInt
Definition: vtkVariant.h:451
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:366
long ToLong(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
vtkTypeInt64 ToTypeInt64(bool *valid) const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
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.
unsigned long ToUnsignedLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:362
vtkVariant(unsigned char value)
Create an unsigned char variant.
unsigned long UnsignedLong
Definition: vtkVariant.h:453
unsigned char UnsignedChar
Definition: vtkVariant.h:446
vtkVariant(short value)
Create a short variant.
vtkVariant(unsigned short value)
Create an unsigned short variant.
vtkVariant()
Create an invalid variant.
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:354
bool IsEqual(const vtkVariant &other) const
Determines whether two variants have the same value.
double Double
Definition: vtkVariant.h:444
vtkObjectBase * VTKObject
Definition: vtkVariant.h:456
signed char SignedChar
Definition: vtkVariant.h:447
int ToInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:356
vtkTypeUInt64 ToTypeUInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:370
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 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
#define VTK_DEPRECATED_IN_9_1_0(reason)
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator>(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator>=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator<=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkVariant &val)