VTK
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 -------------------------------------------------------------------------*/
37 #ifndef vtkVariant_h
38 #define vtkVariant_h
39 
40 #include "vtkCommonCoreModule.h" // For export macro
41 #include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags
42 #include "vtkSystemIncludes.h" // To define ostream
43 #include "vtkSetGet.h" // For vtkNotUsed macro
44 #include "vtkStdString.h"
45 #include "vtkUnicodeString.h"
46 
47 //
48 // The following should be eventually placed in vtkSetGet.h
49 //
50 
51 // This is same as extended template macro with an additional case for VTK_VARIANT
52 #define vtkExtraExtendedTemplateMacro(call) \
53  vtkExtendedTemplateMacro(call); \
54  vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
55 
56 // This is same as Iterator Template macro with an additional case for VTK_VARIANT
57 #define vtkExtendedArrayIteratorTemplateMacro(call) \
58  vtkArrayIteratorTemplateMacro(call); \
59  vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call);
60 
61 class vtkStdString;
62 class vtkUnicodeString;
63 class vtkObjectBase;
64 class vtkAbstractArray;
65 // workaround clang bug, needs export on forward declaration
66 #ifdef __clang__
67 class VTKCOMMONCORE_EXPORT vtkVariant;
68 #else
69 class vtkVariant;
70 #endif
71 struct vtkVariantLessThan;
72 
73 VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
74 
75 class VTKCOMMONCORE_EXPORT vtkVariant
76 {
77 public:
78 
83 
88 
92  vtkVariant(const vtkVariant & other);
93 
98 
103 
107  vtkVariant(unsigned char value);
108 
112  vtkVariant(signed char value);
113 
118 
122  vtkVariant(unsigned short value);
123 
128 
132  vtkVariant(unsigned int value);
133 
138 
142  vtkVariant(unsigned long value);
143 
147  vtkVariant(long long value);
148 
152  vtkVariant(unsigned long long value);
153 
158 
162  vtkVariant(double value);
163 
167  vtkVariant(const char* value);
168 
173 
178 
183 
187  vtkVariant(const vtkVariant &other, unsigned int type);
188 
192  const vtkVariant & operator= (const vtkVariant & other);
193 
197  bool IsValid() const;
198 
202  bool IsString() const;
203 
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  bool Is__Int64() const;
273 
277  bool IsUnsigned__Int64() const;
278 
282  bool IsLongLong() const;
283 
287  bool IsUnsignedLongLong() const;
288 
292  bool IsVTKObject() const;
293 
297  bool IsArray() const;
298 
302  unsigned int GetType() const;
303 
307  const char* GetTypeAsString() const;
308 
313 
318 
320 
329  float ToFloat(bool *valid) const;
330  float ToFloat() const {
331  return this->ToFloat(0); };
332  double ToDouble(bool *valid) const;
333  double ToDouble() const {
334  return this->ToDouble(0); };
335  char ToChar(bool *valid) const;
336  char ToChar() const {
337  return this->ToChar(0); };
338  unsigned char ToUnsignedChar(bool *valid) const;
339  unsigned char ToUnsignedChar() const {
340  return this->ToUnsignedChar(0); };
341  signed char ToSignedChar(bool *valid) const;
342  signed char ToSignedChar() const {
343  return this->ToSignedChar(0); };
344  short ToShort(bool *valid) const;
345  short ToShort() const {
346  return this->ToShort(0); };
347  unsigned short ToUnsignedShort(bool *valid) const;
348  unsigned short ToUnsignedShort() const {
349  return this->ToUnsignedShort(0); };
350  int ToInt(bool *valid) const;
351  int ToInt() const {
352  return this->ToInt(0); };
353  unsigned int ToUnsignedInt(bool *valid) const;
354  unsigned int ToUnsignedInt() const {
355  return this->ToUnsignedInt(0); };
356  long ToLong(bool *valid) const;
357  long ToLong() const {
358  return this->ToLong(0); };
359  unsigned long ToUnsignedLong(bool *valid) const;
360  unsigned long ToUnsignedLong() const {
361  return this->ToUnsignedLong(0); };
362  long long ToLongLong(bool *valid) const;
363  long long ToLongLong() const {
364  return this->ToLongLong(0); };
365  unsigned long long ToUnsignedLongLong(bool *valid) const;
366  unsigned long long ToUnsignedLongLong() const {
367  return this->ToUnsignedLongLong(0); };
368  vtkTypeInt64 ToTypeInt64(bool *valid) const;
369  vtkTypeInt64 ToTypeInt64() const {
370  return this->ToTypeInt64(0); };
371  vtkTypeUInt64 ToTypeUInt64(bool *valid) const;
372  vtkTypeUInt64 ToTypeUInt64() const {
373  return this->ToTypeUInt64(0); };
375 
380 
385 
396  bool IsEqual(const vtkVariant& other) const;
397 
399 
429  bool operator==(const vtkVariant &other) const;
430  bool operator!=(const vtkVariant &other) const;
431  bool operator<(const vtkVariant &other) const;
432  bool operator>(const vtkVariant &other) const;
433  bool operator<=(const vtkVariant &other) const;
434  bool operator>=(const vtkVariant &other) const;
436 
437  friend VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
438 
439 private:
440 
441  template <typename T>
442  T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const;
443 
444  union
445  {
448  float Float;
449  double Double;
450  char Char;
451  unsigned char UnsignedChar;
452  signed char SignedChar;
453  short Short;
454  unsigned short UnsignedShort;
455  int Int;
456  unsigned int UnsignedInt;
457  long Long;
458  unsigned long UnsignedLong;
459  long long LongLong;
460  unsigned long long UnsignedLongLong;
462  } Data;
463 
464  unsigned char Valid;
465  unsigned char Type;
466 
467  friend struct vtkVariantLessThan;
468  friend struct vtkVariantEqual;
471 
472 };
473 
474 #include "vtkVariantInlineOperators.h" // needed for operator== and company
475 
476 // A STL-style function object so you can compare two variants using
477 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
478 // This is a faster version of operator< that makes no attempt to
479 // compare values. It satisfies the STL requirement for a comparison
480 // function for ordered containers like map and set.
481 
482 struct VTKCOMMONCORE_EXPORT vtkVariantLessThan
483 {
484 public:
485  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
486 };
487 
488 struct VTKCOMMONCORE_EXPORT vtkVariantEqual
489 {
490 public:
491  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
492 };
493 
494 struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder
495 {
496 public:
497  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
498 };
499 
500 // Similarly, this is a fast version of operator== that requires that
501 // the types AND the values be equal in order to admit equality.
502 
503 struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality
504 {
505 public:
506  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
507 };
508 
509 #endif
510 // VTK-HeaderTest-Exclude: vtkVariant.h
Abstract superclass for all arrays.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:66
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:49
String class that stores Unicode text.
A atomic type representing the union of many types.
Definition: vtkVariant.h:76
bool Is__Int64() const
Legacy.
vtkTypeInt64 ToTypeInt64() const
Definition: vtkVariant.h:369
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
~vtkVariant()
Destruct the variant.
char ToChar() const
Definition: vtkVariant.h:336
unsigned long long UnsignedLongLong
Definition: vtkVariant.h:460
double ToDouble(bool *valid) const
long long ToLongLong() const
Definition: vtkVariant.h:363
vtkTypeUInt64 ToTypeUInt64(bool *valid) const
unsigned short ToUnsignedShort(bool *valid) const
vtkUnicodeString ToUnicodeString() const
convert the variant to a Unicode string.
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
unsigned char ToUnsignedChar() const
Definition: vtkVariant.h:339
vtkVariant(unsigned int value)
Create an unsigned integer variant.
vtkVariant(char value)
Create a char variant.
unsigned short UnsignedShort
Definition: vtkVariant.h:454
char ToChar(bool *valid) const
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:447
bool IsUnsignedLong() const
Get whether the variant is an unsigned long.
short Short
Definition: vtkVariant.h:453
vtkVariant(int value)
Create an integer variant.
bool IsDouble() const
Get whether the variant is a double.
bool IsUnicodeString() const
Get whether the variant is a Unicode string.
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
Definition: vtkVariant.h:357
signed char ToSignedChar() const
Definition: vtkVariant.h:342
double ToDouble() const
Definition: vtkVariant.h:333
bool IsInt() const
Get whether the variant is an int.
float Float
Definition: vtkVariant.h:448
bool IsUnsignedInt() const
Get whether the variant is an unsigned int.
unsigned long ToUnsignedLong(bool *valid) const
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
Definition: vtkVariant.h:330
long long LongLong
Definition: vtkVariant.h:459
vtkVariant(signed char value)
Create a signed char variant.
vtkVariant(vtkObjectBase *value)
Create a vtkObjectBase variant.
vtkVariant(const vtkUnicodeString &value)
Create a Unicode string variant.
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
Definition: vtkVariant.h:345
vtkStdString * String
Definition: vtkVariant.h:446
vtkVariant(long long value)
Create a long long variant.
bool IsLongLong() const
Get whether the variant is long long.
vtkObjectBase * ToVTKObject() const
Return the VTK object, or NULL if not of that type.
signed char ToSignedChar(bool *valid) const
unsigned int ToUnsignedInt() const
Definition: vtkVariant.h:354
unsigned int UnsignedInt
Definition: vtkVariant.h:456
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
vtkVariant(bool value)
Create a bool variant.
unsigned long long ToUnsignedLongLong() const
Definition: vtkVariant.h:366
long ToLong(bool *valid) const
bool IsSignedChar() const
Get whether the variant is an signed char.
vtkAbstractArray * ToArray() const
Return the array, or NULL if not of that type.
vtkTypeInt64 ToTypeInt64(bool *valid) const
const char * GetTypeAsString() const
Get the type of the variant as a string.
bool IsString() const
Get whether the variant is a string.
unsigned int ToUnsignedInt(bool *valid) const
vtkVariant(const vtkVariant &other)
Copy constructor.
vtkVariant(const vtkVariant &other, unsigned int type)
Create a variant of a specific type.
unsigned long ToUnsignedLong() const
Definition: vtkVariant.h:360
vtkVariant(unsigned char value)
Create an unsigned char variant.
vtkStdString ToString() const
Convert the variant to a string.
unsigned long UnsignedLong
Definition: vtkVariant.h:458
unsigned char UnsignedChar
Definition: vtkVariant.h:451
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
Definition: vtkVariant.h:348
bool IsEqual(const vtkVariant &other) const
Determines whether two variants have the same value.
double Double
Definition: vtkVariant.h:449
vtkObjectBase * VTKObject
Definition: vtkVariant.h:461
signed char SignedChar
Definition: vtkVariant.h:452
bool IsNumeric() const
Get whether the variant is any numeric type.
int ToInt() const
Definition: vtkVariant.h:351
bool IsShort() const
Get whether the variant is an short.
bool IsUnsigned__Int64() const
Legacy.
vtkTypeUInt64 ToTypeUInt64() const
Definition: vtkVariant.h:372
short ToShort(bool *valid) const
vtkVariant(const char *value)
Create a string variant from a const char*.
unsigned long long ToUnsignedLongLong(bool *valid) const
bool IsUnsignedLongLong() const
Get whether the variant is unsigned long long.
@ value
Definition: vtkX3D.h:220
@ type
Definition: vtkX3D.h:516
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
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)