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 
82  vtkVariant();
83 
87  ~vtkVariant();
88 
92  vtkVariant(const vtkVariant & other);
93 
97  vtkVariant(bool value);
98 
102  vtkVariant(char value);
103 
107  vtkVariant(unsigned char value);
108 
112  vtkVariant(signed char value);
113 
117  vtkVariant(short value);
118 
122  vtkVariant(unsigned short value);
123 
127  vtkVariant(int value);
128 
132  vtkVariant(unsigned int value);
133 
137  vtkVariant(long value);
138 
142  vtkVariant(unsigned long value);
143 
147  vtkVariant(long long value);
148 
152  vtkVariant(unsigned long long value);
153 
157  vtkVariant(float value);
158 
162  vtkVariant(double value);
163 
167  vtkVariant(const char* value);
168 
172  vtkVariant(vtkStdString value);
173 
177  vtkVariant(const vtkUnicodeString& value);
178 
182  vtkVariant(vtkObjectBase* value);
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 
312  vtkStdString ToString() const;
313 
317  vtkUnicodeString ToUnicodeString() const;
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 
379  vtkObjectBase* ToVTKObject() const;
380 
384  vtkAbstractArray* ToArray() const;
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
short Short
Definition: vtkVariant.h:453
unsigned int ToUnsignedInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:354
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:47
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.
signed char SignedChar
Definition: vtkVariant.h:452
unsigned int UnsignedInt
Definition: vtkVariant.h:456
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:366
float ToFloat() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:330
char ToChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:336
double ToDouble() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:333
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:451
A atomic type representing the union of many types.
Definition: vtkVariant.h:75
unsigned char ToUnsignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:339
vtkObjectBase * VTKObject
Definition: vtkVariant.h:461
const std::string & ToString(TransportMethod)
long long LongLong
Definition: vtkVariant.h:459
unsigned short UnsignedShort
Definition: vtkVariant.h:454
short ToShort() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:345
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:447
vtkTypeInt64 ToTypeInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:369
unsigned long UnsignedLong
Definition: vtkVariant.h:458
abstract base class for most VTK objects
Definition: vtkObjectBase.h:65
double Double
Definition: vtkVariant.h:449
float Float
Definition: vtkVariant.h:448
vtkTypeUInt64 ToTypeUInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:372
vtkStdString * String
Definition: vtkVariant.h:446
int ToInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:351
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:460
unsigned long ToUnsignedLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:360
unsigned short ToUnsignedShort() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:348
signed char ToSignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:342
long long ToLongLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:363
long ToLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:357
String class that stores Unicode text.