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-------------------------------------------------------------------------*/
110#ifndef vtkVariant_h
111#define vtkVariant_h
112
113#include "vtkCommonCoreModule.h" // For export macro
114#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_1_0
115#include "vtkObject.h" // For vtkObject's warning support
116#include "vtkSetGet.h" // For vtkNotUsed macro
117#include "vtkStdString.h"
118#include "vtkSystemIncludes.h" // To define ostream
119#include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags
120
121//
122// The following should be eventually placed in vtkSetGet.h
123//
124
125// This is same as extended template macro with an additional case for VTK_VARIANT
126#define vtkExtraExtendedTemplateMacro(call) \
127 vtkExtendedTemplateMacro(call); \
128 vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
129
130// This is same as Iterator Template macro with an additional case for VTK_VARIANT
131#define vtkExtendedArrayIteratorTemplateMacro(call) \
132 vtkArrayIteratorTemplateMacro(call); \
133 vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
134
135class vtkStdString;
136class vtkUnicodeString;
137class vtkObjectBase;
138class vtkAbstractArray;
139class vtkVariant;
140struct vtkVariantLessThan;
141
142VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkVariant& val);
143
144class VTKCOMMONCORE_EXPORT vtkVariant
145{
146public:
151
156
160 vtkVariant(const vtkVariant& other);
161
166
171
175 vtkVariant(unsigned char value);
176
180 vtkVariant(signed char value);
181
186
190 vtkVariant(unsigned short value);
191
196
200 vtkVariant(unsigned int value);
201
206
210 vtkVariant(unsigned long value);
211
215 vtkVariant(long long value);
216
220 vtkVariant(unsigned long long value);
221
226
231
235 vtkVariant(const char* value);
236
241
245 VTK_DEPRECATED_IN_9_1_0("Use vtkVariant(vtkStdString value)")
247
252
256 vtkVariant(const vtkVariant& other, unsigned int type);
257
261 vtkVariant& operator=(const vtkVariant& other);
262
266 bool IsValid() const;
267
271 bool IsString() const;
272
276 VTK_DEPRECATED_IN_9_1_0("Use bool IsString() const")
277 bool IsUnicodeString() const;
278
282 bool IsNumeric() const;
283
287 bool IsFloat() const;
288
292 bool IsDouble() const;
293
297 bool IsChar() const;
298
302 bool IsUnsignedChar() const;
303
307 bool IsSignedChar() const;
308
312 bool IsShort() const;
313
317 bool IsUnsignedShort() const;
318
322 bool IsInt() const;
323
327 bool IsUnsignedInt() const;
328
332 bool IsLong() const;
333
337 bool IsUnsignedLong() const;
338
342 VTK_DEPRECATED_IN_9_1_0("Legacy. Returns false. The variant is never an __int64")
343 bool Is__Int64() const;
344
348 VTK_DEPRECATED_IN_9_1_0("Legacy. Returns false. The variant is never an unsigned __int64")
349 bool IsUnsigned__Int64() const;
350
354 bool IsLongLong() const;
355
359 bool IsUnsignedLongLong() const;
360
364 bool IsVTKObject() const;
365
369 bool IsArray() const;
370
374 unsigned int GetType() const;
375
379 const char* GetTypeAsString() const;
380
382 {
383 DEFAULT_FORMATTING = 0,
384 FIXED_FORMATTING = 1,
385 SCIENTIFIC_FORMATTING = 2
386 };
387
396 vtkStdString ToString(int formatting = DEFAULT_FORMATTING, int precision = 6) const;
397
407 "Use vtkStdString ToString(int formatting = DEFAULT_FORMATTING, int precision = 6)")
408 vtkUnicodeString ToUnicodeString(int formatting = DEFAULT_FORMATTING, int precision = 6) const;
409
411
420 float ToFloat(bool* valid) const;
421 float ToFloat() const { return this->ToFloat(nullptr); }
422 double ToDouble(bool* valid) const;
423 double ToDouble() const { return this->ToDouble(nullptr); }
424 char ToChar(bool* valid) const;
425 char ToChar() const { return this->ToChar(nullptr); }
426 unsigned char ToUnsignedChar(bool* valid) const;
427 unsigned char ToUnsignedChar() const { return this->ToUnsignedChar(nullptr); }
428 signed char ToSignedChar(bool* valid) const;
429 signed char ToSignedChar() const { return this->ToSignedChar(nullptr); }
430 short ToShort(bool* valid) const;
431 short ToShort() const { return this->ToShort(nullptr); }
432 unsigned short ToUnsignedShort(bool* valid) const;
433 unsigned short ToUnsignedShort() const { return this->ToUnsignedShort(nullptr); }
434 int ToInt(bool* valid) const;
435 int ToInt() const { return this->ToInt(nullptr); }
436 unsigned int ToUnsignedInt(bool* valid) const;
437 unsigned int ToUnsignedInt() const { return this->ToUnsignedInt(nullptr); }
438 long ToLong(bool* valid) const;
439 long ToLong() const { return this->ToLong(nullptr); }
440 unsigned long ToUnsignedLong(bool* valid) const;
441 unsigned long ToUnsignedLong() const { return this->ToUnsignedLong(nullptr); }
442 long long ToLongLong(bool* valid) const;
443 long long ToLongLong() const { return this->ToLongLong(nullptr); }
444 unsigned long long ToUnsignedLongLong(bool* valid) const;
445 unsigned long long ToUnsignedLongLong() const { return this->ToUnsignedLongLong(nullptr); }
446 vtkTypeInt64 ToTypeInt64(bool* valid) const;
447 vtkTypeInt64 ToTypeInt64() const { return this->ToTypeInt64(nullptr); }
448 vtkTypeUInt64 ToTypeUInt64(bool* valid) const;
449 vtkTypeUInt64 ToTypeUInt64() const { return this->ToTypeUInt64(nullptr); }
451
456
461
472 bool IsEqual(const vtkVariant& other) const;
473
475
505 bool operator==(const vtkVariant& other) const;
506 bool operator!=(const vtkVariant& other) const;
507 bool operator<(const vtkVariant& other) const;
508 bool operator>(const vtkVariant& other) const;
509 bool operator<=(const vtkVariant& other) const;
510 bool operator>=(const vtkVariant& other) const;
512
513 friend VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkVariant& val);
514
515private:
516 template <typename T>
517 T ToNumeric(bool* valid, T* vtkNotUsed(ignored)) const;
518
519 union {
522 float Float;
523 double Double;
524 char Char;
525 unsigned char UnsignedChar;
526 signed char SignedChar;
527 short Short;
528 unsigned short UnsignedShort;
529 int Int;
530 unsigned int UnsignedInt;
531 long Long;
532 unsigned long UnsignedLong;
533 long long LongLong;
534 unsigned long long UnsignedLongLong;
536 } Data;
537
538 // XXX(9.1): Remove with VTK_DEPRECATED_IN_9_1_0().
539 bool CheckUnicodeStringEqual(const vtkVariant& other) const;
540 bool CheckUnicodeStringLessThan(const vtkVariant& other) const;
541
542 unsigned char Valid;
543 unsigned char Type;
544
545 friend struct vtkVariantLessThan;
546 friend struct vtkVariantEqual;
549};
550
551#include "vtkVariantInlineOperators.h" // needed for operator== and company
552
553// A STL-style function object so you can compare two variants using
554// comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
555// This is a faster version of operator< that makes no attempt to
556// compare values. It satisfies the STL requirement for a comparison
557// function for ordered containers like map and set.
558
559struct VTKCOMMONCORE_EXPORT vtkVariantLessThan
560{
561public:
562 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
563};
564
565struct VTKCOMMONCORE_EXPORT vtkVariantEqual
566{
567public:
568 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
569};
570
571struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder
572{
573public:
574 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
575};
576
577// Similarly, this is a fast version of operator== that requires that
578// the types AND the values be equal in order to admit equality.
579
580struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality
581{
582public:
583 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
584};
585
586#endif
587// 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:105
String class that stores Unicode text.
A atomic type representing the union of many types.
Definition: vtkVariant.h:145
vtkTypeInt64 ToTypeInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:447
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:425
unsigned long long UnsignedLongLong
Definition: vtkVariant.h:534
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:443
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:427
vtkVariant(unsigned int value)
Create an unsigned integer variant.
vtkVariant(char value)
Create a char variant.
unsigned short UnsignedShort
Definition: vtkVariant.h:528
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:521
short Short
Definition: vtkVariant.h:527
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:439
signed char ToSignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:429
double ToDouble() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:423
float Float
Definition: vtkVariant.h:522
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:421
long long LongLong
Definition: vtkVariant.h:533
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:431
vtkStdString * String
Definition: vtkVariant.h:520
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:437
unsigned int UnsignedInt
Definition: vtkVariant.h:530
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:445
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:441
vtkVariant(unsigned char value)
Create an unsigned char variant.
unsigned long UnsignedLong
Definition: vtkVariant.h:532
unsigned char UnsignedChar
Definition: vtkVariant.h:525
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:433
bool IsEqual(const vtkVariant &other) const
Determines whether two variants have the same value.
double Double
Definition: vtkVariant.h:523
vtkObjectBase * VTKObject
Definition: vtkVariant.h:535
signed char SignedChar
Definition: vtkVariant.h:526
int ToInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:435
vtkTypeUInt64 ToTypeUInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:449
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)