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 "vtkObject.h" // For vtkObject's warning support
45 #include "vtkStdString.h"
46 #include "vtkUnicodeString.h"
47 
48 //
49 // The following should be eventually placed in vtkSetGet.h
50 //
51 
52 // This is same as extended template macro with an additional case for VTK_VARIANT
53 #define vtkExtraExtendedTemplateMacro(call) \
54  vtkExtendedTemplateMacro(call); \
55  vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
56 
57 // This is same as Iterator Template macro with an additional case for VTK_VARIANT
58 #define vtkExtendedArrayIteratorTemplateMacro(call) \
59  vtkArrayIteratorTemplateMacro(call); \
60  vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call);
61 
62 class vtkStdString;
63 class vtkUnicodeString;
64 class vtkObjectBase;
65 class vtkAbstractArray;
66 class vtkVariant;
67 struct vtkVariantLessThan;
68 
69 VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
70 
71 class VTKCOMMONCORE_EXPORT vtkVariant
72 {
73 public:
74 
78  vtkVariant();
79 
83  ~vtkVariant();
84 
88  vtkVariant(const vtkVariant & other);
89 
93  vtkVariant(bool value);
94 
98  vtkVariant(char value);
99 
103  vtkVariant(unsigned char value);
104 
108  vtkVariant(signed char value);
109 
113  vtkVariant(short value);
114 
118  vtkVariant(unsigned short value);
119 
123  vtkVariant(int value);
124 
128  vtkVariant(unsigned int value);
129 
133  vtkVariant(long value);
134 
138  vtkVariant(unsigned long value);
139 
143  vtkVariant(long long value);
144 
148  vtkVariant(unsigned long long value);
149 
153  vtkVariant(float value);
154 
158  vtkVariant(double value);
159 
163  vtkVariant(const char* value);
164 
169 
174 
179 
183  vtkVariant(const vtkVariant &other, unsigned int type);
184 
188  vtkVariant & operator= (const vtkVariant & other);
189 
193  bool IsValid() const;
194 
198  bool IsString() const;
199 
203  bool IsUnicodeString() const;
204 
208  bool IsNumeric() const;
209 
213  bool IsFloat() const;
214 
218  bool IsDouble() const;
219 
223  bool IsChar() const;
224 
228  bool IsUnsignedChar() const;
229 
233  bool IsSignedChar() const;
234 
238  bool IsShort() const;
239 
243  bool IsUnsignedShort() const;
244 
248  bool IsInt() const;
249 
253  bool IsUnsignedInt() const;
254 
258  bool IsLong() const;
259 
263  bool IsUnsignedLong() const;
264 
268  bool Is__Int64() const;
269 
273  bool IsUnsigned__Int64() const;
274 
278  bool IsLongLong() const;
279 
283  bool IsUnsignedLongLong() const;
284 
288  bool IsVTKObject() const;
289 
293  bool IsArray() const;
294 
298  unsigned int GetType() const;
299 
303  const char* GetTypeAsString() const;
304 
308  vtkStdString ToString() const;
309 
313  vtkUnicodeString ToUnicodeString() const;
314 
316 
325  float ToFloat(bool *valid) const;
326  float ToFloat() const {
327  return this->ToFloat(nullptr); };
328  double ToDouble(bool *valid) const;
329  double ToDouble() const {
330  return this->ToDouble(nullptr); };
331  char ToChar(bool *valid) const;
332  char ToChar() const {
333  return this->ToChar(nullptr); };
334  unsigned char ToUnsignedChar(bool *valid) const;
335  unsigned char ToUnsignedChar() const {
336  return this->ToUnsignedChar(nullptr); };
337  signed char ToSignedChar(bool *valid) const;
338  signed char ToSignedChar() const {
339  return this->ToSignedChar(nullptr); };
340  short ToShort(bool *valid) const;
341  short ToShort() const {
342  return this->ToShort(nullptr); };
343  unsigned short ToUnsignedShort(bool *valid) const;
344  unsigned short ToUnsignedShort() const {
345  return this->ToUnsignedShort(nullptr); };
346  int ToInt(bool *valid) const;
347  int ToInt() const {
348  return this->ToInt(nullptr); };
349  unsigned int ToUnsignedInt(bool *valid) const;
350  unsigned int ToUnsignedInt() const {
351  return this->ToUnsignedInt(nullptr); };
352  long ToLong(bool *valid) const;
353  long ToLong() const {
354  return this->ToLong(nullptr); };
355  unsigned long ToUnsignedLong(bool *valid) const;
356  unsigned long ToUnsignedLong() const {
357  return this->ToUnsignedLong(nullptr); };
358  long long ToLongLong(bool *valid) const;
359  long long ToLongLong() const {
360  return this->ToLongLong(nullptr); };
361  unsigned long long ToUnsignedLongLong(bool *valid) const;
362  unsigned long long ToUnsignedLongLong() const {
363  return this->ToUnsignedLongLong(nullptr); };
364  vtkTypeInt64 ToTypeInt64(bool *valid) const;
365  vtkTypeInt64 ToTypeInt64() const {
366  return this->ToTypeInt64(nullptr); };
367  vtkTypeUInt64 ToTypeUInt64(bool *valid) const;
368  vtkTypeUInt64 ToTypeUInt64() const {
369  return this->ToTypeUInt64(nullptr); };
371 
375  vtkObjectBase* ToVTKObject() const;
376 
380  vtkAbstractArray* ToArray() const;
381 
392  bool IsEqual(const vtkVariant& other) const;
393 
395 
425  bool operator==(const vtkVariant &other) const;
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;
432 
433  friend VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
434 
435 private:
436 
437  template <typename T>
438  T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const;
439 
440  union
441  {
444  float Float;
445  double Double;
446  char Char;
447  unsigned char UnsignedChar;
448  signed char SignedChar;
449  short Short;
450  unsigned short UnsignedShort;
451  int Int;
452  unsigned int UnsignedInt;
453  long Long;
454  unsigned long UnsignedLong;
455  long long LongLong;
456  unsigned long long UnsignedLongLong;
458  } Data;
459 
460  unsigned char Valid;
461  unsigned char Type;
462 
463  friend struct vtkVariantLessThan;
464  friend struct vtkVariantEqual;
467 
468 };
469 
470 #include "vtkVariantInlineOperators.h" // needed for operator== and company
471 
472 // A STL-style function object so you can compare two variants using
473 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
474 // This is a faster version of operator< that makes no attempt to
475 // compare values. It satisfies the STL requirement for a comparison
476 // function for ordered containers like map and set.
477 
478 struct VTKCOMMONCORE_EXPORT vtkVariantLessThan
479 {
480 public:
481  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
482 };
483 
484 struct VTKCOMMONCORE_EXPORT vtkVariantEqual
485 {
486 public:
487  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
488 };
489 
490 struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder
491 {
492 public:
493  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
494 };
495 
496 // Similarly, this is a fast version of operator== that requires that
497 // the types AND the values be equal in order to admit equality.
498 
499 struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality
500 {
501 public:
502  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
503 };
504 
505 #endif
506 // VTK-HeaderTest-Exclude: vtkVariant.h
vtkVariant::ToUnsignedShort
unsigned short ToUnsignedShort() const
Definition: vtkVariant.h:344
vtkVariant::ToLong
long ToLong() const
Definition: vtkVariant.h:353
vtkStdString.h
vtkVariantStrictWeakOrder
Definition: vtkVariant.h:490
vtkVariant::ToUnsignedChar
unsigned char ToUnsignedChar() const
Definition: vtkVariant.h:335
vtkX3D::value
Definition: vtkX3D.h:220
vtkX3D::type
Definition: vtkX3D.h:516
vtkVariant::ToChar
char ToChar() const
Definition: vtkVariant.h:332
vtkVariant::Short
short Short
Definition: vtkVariant.h:449
vtkUnicodeString.h
vtkVariantInlineOperators.h
vtkVariant::ToUnsignedLong
unsigned long ToUnsignedLong() const
Definition: vtkVariant.h:356
vtkVariant::ToFloat
float ToFloat() const
Definition: vtkVariant.h:326
vtkVariant::ToShort
short ToShort() const
Definition: vtkVariant.h:341
operator<
VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
ADIOS::Type::IsInt
bool IsInt(ADIOS_DATATYPES ta)
vtkVariant::UnsignedChar
unsigned char UnsignedChar
Definition: vtkVariant.h:447
vtkVariant::LongLong
long long LongLong
Definition: vtkVariant.h:455
vtkType.h
vtkVariant::ToTypeInt64
vtkTypeInt64 ToTypeInt64() const
Definition: vtkVariant.h:365
vtkVariant::ToDouble
double ToDouble() const
Definition: vtkVariant.h:329
vtkVariant::SignedChar
signed char SignedChar
Definition: vtkVariant.h:448
vtkVariant::ToUnsignedInt
unsigned int ToUnsignedInt() const
Definition: vtkVariant.h:350
vtkVariant::UnsignedInt
unsigned int UnsignedInt
Definition: vtkVariant.h:452
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:65
vtkVariantStrictEquality
Definition: vtkVariant.h:499
vtkVariant::UnsignedShort
unsigned short UnsignedShort
Definition: vtkVariant.h:450
vtkUnicodeString
String class that stores Unicode text.
Definition: vtkUnicodeString.h:72
vtkVariant::Char
char Char
Definition: vtkVariant.h:446
vtkVariant::Double
double Double
Definition: vtkVariant.h:445
vtkVariant::Int
int Int
Definition: vtkVariant.h:451
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:71
vtkVariant::ToLongLong
long long ToLongLong() const
Definition: vtkVariant.h:359
operator==
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
operator<<
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkVariant &val)
vtkVariant::VTKObject
vtkObjectBase * VTKObject
Definition: vtkVariant.h:457
vtkVariantLessThan
Definition: vtkVariant.h:478
vtkObject.h
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:78
vtkVariantEqual
Definition: vtkVariant.h:484
vtkVariant::UnsignedLong
unsigned long UnsignedLong
Definition: vtkVariant.h:454
ADIOS::ToString
const std::string & ToString(TransportMethod)
vtkVariant::ToTypeUInt64
vtkTypeUInt64 ToTypeUInt64() const
Definition: vtkVariant.h:368
operator>=
VTKCOMMONCORE_EXPORT bool operator>=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
vtkVariant::Float
float Float
Definition: vtkVariant.h:444
vtkVariant::String
vtkStdString * String
Definition: vtkVariant.h:442
vtkVariant::Long
long Long
Definition: vtkVariant.h:453
vtkVariant::ToUnsignedLongLong
unsigned long long ToUnsignedLongLong() const
Definition: vtkVariant.h:362
vtkVariant::UnicodeString
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:443
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
operator!=
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
operator>
VTKCOMMONCORE_EXPORT bool operator>(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
operator<=
VTKCOMMONCORE_EXPORT bool operator<=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
vtkVariant::ToSignedChar
signed char ToSignedChar() const
Definition: vtkVariant.h:338
vtkVariant::UnsignedLongLong
unsigned long long UnsignedLongLong
Definition: vtkVariant.h:456
vtkSystemIncludes.h
vtkVariant::ToInt
int ToInt() const
Definition: vtkVariant.h:347