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 -------------------------------------------------------------------------*/
31 #ifndef vtkVariant_h
32 #define vtkVariant_h
33 
34 #include "vtkCommonCoreModule.h" // For export macro
35 #include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags
36 #include "vtkSystemIncludes.h" // To define ostream
37 #include "vtkSetGet.h" // For vtkNotUsed macro
38 #include "vtkObject.h" // For vtkObject's warning support
39 #include "vtkStdString.h"
40 #include "vtkUnicodeString.h"
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 
56 class vtkStdString;
57 class vtkUnicodeString;
58 class vtkObjectBase;
59 class vtkAbstractArray;
60 class vtkVariant;
61 struct vtkVariantLessThan;
62 
63 VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
64 
65 class VTKCOMMONCORE_EXPORT vtkVariant
66 {
67 public:
68 
72  vtkVariant();
73 
77  ~vtkVariant();
78 
82  vtkVariant(const vtkVariant & other);
83 
87  vtkVariant(bool value);
88 
92  vtkVariant(char value);
93 
97  vtkVariant(unsigned char value);
98 
102  vtkVariant(signed char value);
103 
107  vtkVariant(short value);
108 
112  vtkVariant(unsigned short value);
113 
117  vtkVariant(int value);
118 
122  vtkVariant(unsigned int value);
123 
127  vtkVariant(long value);
128 
132  vtkVariant(unsigned long value);
133 
137  vtkVariant(long long value);
138 
142  vtkVariant(unsigned long long value);
143 
147  vtkVariant(float value);
148 
152  vtkVariant(double value);
153 
157  vtkVariant(const char* value);
158 
163 
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  bool IsUnicodeString() const;
198 
202  bool IsNumeric() const;
203 
207  bool IsFloat() const;
208 
212  bool IsDouble() const;
213 
217  bool IsChar() const;
218 
222  bool IsUnsignedChar() const;
223 
227  bool IsSignedChar() const;
228 
232  bool IsShort() const;
233 
237  bool IsUnsignedShort() const;
238 
242  bool IsInt() const;
243 
247  bool IsUnsignedInt() const;
248 
252  bool IsLong() const;
253 
257  bool IsUnsignedLong() const;
258 
262  bool Is__Int64() const;
263 
267  bool IsUnsigned__Int64() const;
268 
272  bool IsLongLong() const;
273 
277  bool IsUnsignedLongLong() const;
278 
282  bool IsVTKObject() const;
283 
287  bool IsArray() const;
288 
292  unsigned int GetType() const;
293 
297  const char* GetTypeAsString() const;
298 
302  vtkStdString ToString() const;
303 
307  vtkUnicodeString ToUnicodeString() const;
308 
310 
319  float ToFloat(bool *valid) const;
320  float ToFloat() const {
321  return this->ToFloat(nullptr); };
322  double ToDouble(bool *valid) const;
323  double ToDouble() const {
324  return this->ToDouble(nullptr); };
325  char ToChar(bool *valid) const;
326  char ToChar() const {
327  return this->ToChar(nullptr); };
328  unsigned char ToUnsignedChar(bool *valid) const;
329  unsigned char ToUnsignedChar() const {
330  return this->ToUnsignedChar(nullptr); };
331  signed char ToSignedChar(bool *valid) const;
332  signed char ToSignedChar() const {
333  return this->ToSignedChar(nullptr); };
334  short ToShort(bool *valid) const;
335  short ToShort() const {
336  return this->ToShort(nullptr); };
337  unsigned short ToUnsignedShort(bool *valid) const;
338  unsigned short ToUnsignedShort() const {
339  return this->ToUnsignedShort(nullptr); };
340  int ToInt(bool *valid) const;
341  int ToInt() const {
342  return this->ToInt(nullptr); };
343  unsigned int ToUnsignedInt(bool *valid) const;
344  unsigned int ToUnsignedInt() const {
345  return this->ToUnsignedInt(nullptr); };
346  long ToLong(bool *valid) const;
347  long ToLong() const {
348  return this->ToLong(nullptr); };
349  unsigned long ToUnsignedLong(bool *valid) const;
350  unsigned long ToUnsignedLong() const {
351  return this->ToUnsignedLong(nullptr); };
352  long long ToLongLong(bool *valid) const;
353  long long ToLongLong() const {
354  return this->ToLongLong(nullptr); };
355  unsigned long long ToUnsignedLongLong(bool *valid) const;
356  unsigned long long ToUnsignedLongLong() const {
357  return this->ToUnsignedLongLong(nullptr); };
358  vtkTypeInt64 ToTypeInt64(bool *valid) const;
359  vtkTypeInt64 ToTypeInt64() const {
360  return this->ToTypeInt64(nullptr); };
361  vtkTypeUInt64 ToTypeUInt64(bool *valid) const;
362  vtkTypeUInt64 ToTypeUInt64() const {
363  return this->ToTypeUInt64(nullptr); };
365 
369  vtkObjectBase* ToVTKObject() const;
370 
374  vtkAbstractArray* ToArray() const;
375 
386  bool IsEqual(const vtkVariant& other) const;
387 
389 
419  bool operator==(const vtkVariant &other) const;
420  bool operator!=(const vtkVariant &other) const;
421  bool operator<(const vtkVariant &other) const;
422  bool operator>(const vtkVariant &other) const;
423  bool operator<=(const vtkVariant &other) const;
424  bool operator>=(const vtkVariant &other) const;
426 
427  friend VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
428 
429 private:
430 
431  template <typename T>
432  T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const;
433 
434  union
435  {
438  float Float;
439  double Double;
440  char Char;
441  unsigned char UnsignedChar;
442  signed char SignedChar;
443  short Short;
444  unsigned short UnsignedShort;
445  int Int;
446  unsigned int UnsignedInt;
447  long Long;
448  unsigned long UnsignedLong;
449  long long LongLong;
450  unsigned long long UnsignedLongLong;
452  } Data;
453 
454  unsigned char Valid;
455  unsigned char Type;
456 
457  friend struct vtkVariantLessThan;
458  friend struct vtkVariantEqual;
461 
462 };
463 
464 #include "vtkVariantInlineOperators.h" // needed for operator== and company
465 
466 // A STL-style function object so you can compare two variants using
467 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
468 // This is a faster version of operator< that makes no attempt to
469 // compare values. It satisfies the STL requirement for a comparison
470 // function for ordered containers like map and set.
471 
472 struct VTKCOMMONCORE_EXPORT vtkVariantLessThan
473 {
474 public:
475  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
476 };
477 
478 struct VTKCOMMONCORE_EXPORT vtkVariantEqual
479 {
480 public:
481  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
482 };
483 
484 struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder
485 {
486 public:
487  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
488 };
489 
490 // Similarly, this is a fast version of operator== that requires that
491 // the types AND the values be equal in order to admit equality.
492 
493 struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality
494 {
495 public:
496  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
497 };
498 
499 #endif
500 // VTK-HeaderTest-Exclude: vtkVariant.h
short Short
Definition: vtkVariant.h:443
signed char ToSignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:332
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
int ToInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:341
float ToFloat() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:320
VTKCOMMONCORE_EXPORT bool operator>=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
bool IsInt(ADIOS_DATATYPES ta)
VTKCOMMONCORE_EXPORT bool operator<=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
Abstract superclass for all arrays.
unsigned short ToUnsignedShort() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:338
signed char SignedChar
Definition: vtkVariant.h:442
vtkTypeInt64 ToTypeInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:359
unsigned int UnsignedInt
Definition: vtkVariant.h:446
short ToShort() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:335
VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, const vtkVariant &val)
VTKCOMMONCORE_EXPORT bool operator>(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
unsigned char UnsignedChar
Definition: vtkVariant.h:441
A atomic type representing the union of many types.
Definition: vtkVariant.h:65
vtkObjectBase * VTKObject
Definition: vtkVariant.h:451
const std::string & ToString(TransportMethod)
long long LongLong
Definition: vtkVariant.h:449
unsigned short UnsignedShort
Definition: vtkVariant.h:444
long ToLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:347
long long ToLongLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:353
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:356
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:437
unsigned long UnsignedLong
Definition: vtkVariant.h:448
abstract base class for most VTK objects
Definition: vtkObjectBase.h:62
double Double
Definition: vtkVariant.h:439
float Float
Definition: vtkVariant.h:438
unsigned int ToUnsignedInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:344
double ToDouble() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:323
vtkStdString * String
Definition: vtkVariant.h:436
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
unsigned long long UnsignedLongLong
Definition: vtkVariant.h:450
unsigned long ToUnsignedLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:350
vtkTypeUInt64 ToTypeUInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:362
char ToChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:326
unsigned char ToUnsignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type.
Definition: vtkVariant.h:329
String class that stores Unicode text.