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-------------------------------------------------------------------------*/
40#ifndef vtkVariant_h
41#define vtkVariant_h
42
43#include "vtkCommonCoreModule.h" // For export macro
44#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_1_0
45#include "vtkObject.h" // For vtkObject's warning support
46#include "vtkSetGet.h" // For vtkNotUsed macro
47#include "vtkStdString.h"
48#include "vtkSystemIncludes.h" // To define ostream
49#include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags
50
51//
52// The following should be eventually placed in vtkSetGet.h
53//
54
55// This is same as extended template macro with an additional case for VTK_VARIANT
56#define vtkExtraExtendedTemplateMacro(call) \
57 vtkExtendedTemplateMacro(call); \
58 vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
59
60// This is same as Iterator Template macro with an additional case for VTK_VARIANT
61#define vtkExtendedArrayIteratorTemplateMacro(call) \
62 vtkArrayIteratorTemplateMacro(call); \
63 vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
64
65class vtkStdString;
67class vtkObjectBase;
69class vtkVariant;
71
72VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkVariant& val);
73
74class VTKCOMMONCORE_EXPORT vtkVariant
75{
76public:
81
86
90 vtkVariant(const vtkVariant& other);
91
96
101
105 vtkVariant(unsigned char value);
106
110 vtkVariant(signed char value);
111
116
120 vtkVariant(unsigned short value);
121
126
130 vtkVariant(unsigned int value);
131
136
140 vtkVariant(unsigned long value);
141
145 vtkVariant(long long value);
146
150 vtkVariant(unsigned long long value);
151
156
161
165 vtkVariant(const char* value);
166
171
175 VTK_DEPRECATED_IN_9_1_0("Use vtkVariant(vtkStdString value)")
177
182
186 vtkVariant(const vtkVariant& other, unsigned int type);
187
191 vtkVariant& operator=(const vtkVariant& other);
192
196 bool IsValid() const;
197
201 bool IsString() const;
202
206 VTK_DEPRECATED_IN_9_1_0("Use bool IsString() const")
207 bool IsUnicodeString() const;
208
212 bool IsNumeric() const;
213
217 bool IsFloat() const;
218
222 bool IsDouble() const;
223
227 bool IsChar() const;
228
232 bool IsUnsignedChar() const;
233
237 bool IsSignedChar() const;
238
242 bool IsShort() const;
243
247 bool IsUnsignedShort() const;
248
252 bool IsInt() const;
253
257 bool IsUnsignedInt() const;
258
262 bool IsLong() const;
263
267 bool IsUnsignedLong() const;
268
272 VTK_DEPRECATED_IN_9_1_0("Legacy. Returns false. The variant is never an __int64")
273 bool Is__Int64() const;
274
278 VTK_DEPRECATED_IN_9_1_0("Legacy. Returns false. The variant is never an unsigned __int64")
279 bool IsUnsigned__Int64() const;
280
284 bool IsLongLong() const;
285
289 bool IsUnsignedLongLong() const;
290
294 bool IsVTKObject() const;
295
299 bool IsArray() const;
300
304 unsigned int GetType() const;
305
309 const char* GetTypeAsString() const;
310
312 {
313 DEFAULT_FORMATTING = 0,
314 FIXED_FORMATTING = 1,
315 SCIENTIFIC_FORMATTING = 2
316 };
317
326 vtkStdString ToString(int formatting = DEFAULT_FORMATTING, int precision = 6) const;
327
337 "Use vtkStdString ToString(int formatting = DEFAULT_FORMATTING, int precision = 6)")
338 vtkUnicodeString ToUnicodeString(int formatting = DEFAULT_FORMATTING, int precision = 6) const;
339
341
350 float ToFloat(bool* valid) const;
351 float ToFloat() const { return this->ToFloat(nullptr); }
352 double ToDouble(bool* valid) const;
353 double ToDouble() const { return this->ToDouble(nullptr); }
354 char ToChar(bool* valid) const;
355 char ToChar() const { return this->ToChar(nullptr); }
356 unsigned char ToUnsignedChar(bool* valid) const;
357 unsigned char ToUnsignedChar() const { return this->ToUnsignedChar(nullptr); }
358 signed char ToSignedChar(bool* valid) const;
359 signed char ToSignedChar() const { return this->ToSignedChar(nullptr); }
360 short ToShort(bool* valid) const;
361 short ToShort() const { return this->ToShort(nullptr); }
362 unsigned short ToUnsignedShort(bool* valid) const;
363 unsigned short ToUnsignedShort() const { return this->ToUnsignedShort(nullptr); }
364 int ToInt(bool* valid) const;
365 int ToInt() const { return this->ToInt(nullptr); }
366 unsigned int ToUnsignedInt(bool* valid) const;
367 unsigned int ToUnsignedInt() const { return this->ToUnsignedInt(nullptr); }
368 long ToLong(bool* valid) const;
369 long ToLong() const { return this->ToLong(nullptr); }
370 unsigned long ToUnsignedLong(bool* valid) const;
371 unsigned long ToUnsignedLong() const { return this->ToUnsignedLong(nullptr); }
372 long long ToLongLong(bool* valid) const;
373 long long ToLongLong() const { return this->ToLongLong(nullptr); }
374 unsigned long long ToUnsignedLongLong(bool* valid) const;
375 unsigned long long ToUnsignedLongLong() const { return this->ToUnsignedLongLong(nullptr); }
376 vtkTypeInt64 ToTypeInt64(bool* valid) const;
377 vtkTypeInt64 ToTypeInt64() const { return this->ToTypeInt64(nullptr); }
378 vtkTypeUInt64 ToTypeUInt64(bool* valid) const;
379 vtkTypeUInt64 ToTypeUInt64() const { return this->ToTypeUInt64(nullptr); }
381
386
391
402 bool IsEqual(const vtkVariant& other) const;
403
405
435 bool operator==(const vtkVariant& other) const;
436 bool operator!=(const vtkVariant& other) const;
437 bool operator<(const vtkVariant& other) const;
438 bool operator>(const vtkVariant& other) const;
439 bool operator<=(const vtkVariant& other) const;
440 bool operator>=(const vtkVariant& other) const;
442
443 friend VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkVariant& val);
444
445private:
446 template <typename T>
447 T ToNumeric(bool* valid, T* vtkNotUsed(ignored)) const;
448
449 union {
452 float Float;
453 double Double;
454 char Char;
455 unsigned char UnsignedChar;
456 signed char SignedChar;
457 short Short;
458 unsigned short UnsignedShort;
459 int Int;
460 unsigned int UnsignedInt;
461 long Long;
462 unsigned long UnsignedLong;
463 long long LongLong;
464 unsigned long long UnsignedLongLong;
466 } Data;
467
468 // XXX(9.1): Remove with VTK_DEPRECATED_IN_9_1_0().
469 bool CheckUnicodeStringEqual(const vtkVariant& other) const;
470 bool CheckUnicodeStringLessThan(const vtkVariant& other) const;
471
472 unsigned char Valid;
473 unsigned char Type;
474
475 friend struct vtkVariantLessThan;
476 friend struct vtkVariantEqual;
479};
480
481#include "vtkVariantInlineOperators.h" // needed for operator== and company
482
483// A STL-style function object so you can compare two variants using
484// comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
485// This is a faster version of operator< that makes no attempt to
486// compare values. It satisfies the STL requirement for a comparison
487// function for ordered containers like map and set.
488
489struct VTKCOMMONCORE_EXPORT vtkVariantLessThan
490{
491public:
492 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
493};
494
495struct VTKCOMMONCORE_EXPORT vtkVariantEqual
496{
497public:
498 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
499};
500
501struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder
502{
503public:
504 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
505};
506
507// Similarly, this is a fast version of operator== that requires that
508// the types AND the values be equal in order to admit equality.
509
510struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality
511{
512public:
513 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
514};
515
516#endif
517// VTK-HeaderTest-Exclude: vtkVariant.h
Abstract superclass for all arrays.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:79
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:45
String class that stores Unicode text.
A atomic type representing the union of many types.
Definition: vtkVariant.h:75
vtkTypeInt64 ToTypeInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:377
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:355
unsigned long long UnsignedLongLong
Definition: vtkVariant.h:464
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:373
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:357
vtkVariant(unsigned int value)
Create an unsigned integer variant.
vtkVariant(char value)
Create a char variant.
unsigned short UnsignedShort
Definition: vtkVariant.h:458
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:451
short Short
Definition: vtkVariant.h:457
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:369
signed char ToSignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:359
double ToDouble() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:353
float Float
Definition: vtkVariant.h:452
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:351
long long LongLong
Definition: vtkVariant.h:463
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:361
vtkStdString * String
Definition: vtkVariant.h:450
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:367
unsigned int UnsignedInt
Definition: vtkVariant.h:460
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:375
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:371
vtkVariant(unsigned char value)
Create an unsigned char variant.
unsigned long UnsignedLong
Definition: vtkVariant.h:462
unsigned char UnsignedChar
Definition: vtkVariant.h:455
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:363
bool IsEqual(const vtkVariant &other) const
Determines whether two variants have the same value.
double Double
Definition: vtkVariant.h:453
vtkObjectBase * VTKObject
Definition: vtkVariant.h:465
signed char SignedChar
Definition: vtkVariant.h:456
int ToInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:365
vtkTypeUInt64 ToTypeUInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:379
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.
@ value
Definition: vtkX3D.h:226
@ type
Definition: vtkX3D.h:522
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)