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 "vtkStdString.h"
39 #include "vtkUnicodeString.h"
40 
41 //
42 // The following should be eventually placed in vtkSetGet.h
43 //
44 
45 // This is same as extended template macro with an additional case for VTK_VARIANT
46 #define vtkExtraExtendedTemplateMacro(call) \
47  vtkExtendedTemplateMacro(call); \
48  vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
49 
50 // This is same as Iterator Template macro with an additional case for VTK_VARIANT
51 #define vtkExtendedArrayIteratorTemplateMacro(call) \
52  vtkArrayIteratorTemplateMacro(call); \
53  vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call);
54 
55 class vtkStdString;
56 class vtkUnicodeString;
57 class vtkObjectBase;
58 class vtkAbstractArray;
59 // workaround clang bug, needs export on forward declaration
60 #ifdef __clang__
61 class VTKCOMMONCORE_EXPORT vtkVariant;
62 #else
63 class vtkVariant;
64 #endif
65 struct vtkVariantLessThan;
66 
67 VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
68 
69 class VTKCOMMONCORE_EXPORT vtkVariant
70 {
71 public:
72 
76  vtkVariant();
77 
81  ~vtkVariant();
82 
86  vtkVariant(const vtkVariant & other);
87 
91  vtkVariant(bool value);
92 
96  vtkVariant(char value);
97 
101  vtkVariant(unsigned char value);
102 
106  vtkVariant(signed char value);
107 
111  vtkVariant(short value);
112 
116  vtkVariant(unsigned short value);
117 
121  vtkVariant(int value);
122 
126  vtkVariant(unsigned int value);
127 
131  vtkVariant(long value);
132 
136  vtkVariant(unsigned long value);
137 
141  vtkVariant(long long value);
142 
146  vtkVariant(unsigned long long value);
147 
151  vtkVariant(float value);
152 
156  vtkVariant(double value);
157 
161  vtkVariant(const char* value);
162 
166  vtkVariant(vtkStdString value);
167 
171  vtkVariant(const vtkUnicodeString& value);
172 
176  vtkVariant(vtkObjectBase* value);
177 
181  vtkVariant(const vtkVariant &other, unsigned int type);
182 
186  const vtkVariant & operator= (const vtkVariant & other);
187 
191  bool IsValid() const;
192 
196  bool IsString() const;
197 
201  bool IsUnicodeString() const;
202 
206  bool IsNumeric() const;
207 
211  bool IsFloat() const;
212 
216  bool IsDouble() const;
217 
221  bool IsChar() const;
222 
226  bool IsUnsignedChar() const;
227 
231  bool IsSignedChar() const;
232 
236  bool IsShort() const;
237 
241  bool IsUnsignedShort() const;
242 
246  bool IsInt() const;
247 
251  bool IsUnsignedInt() const;
252 
256  bool IsLong() const;
257 
261  bool IsUnsignedLong() const;
262 
266  bool Is__Int64() const;
267 
271  bool IsUnsigned__Int64() const;
272 
276  bool IsLongLong() const;
277 
281  bool IsUnsignedLongLong() const;
282 
286  bool IsVTKObject() const;
287 
291  bool IsArray() const;
292 
296  unsigned int GetType() const;
297 
301  const char* GetTypeAsString() const;
302 
306  vtkStdString ToString() const;
307 
311  vtkUnicodeString ToUnicodeString() const;
312 
314 
323  float ToFloat(bool *valid) const;
324  float ToFloat() const {
325  return this->ToFloat(0); };
326  double ToDouble(bool *valid) const;
327  double ToDouble() const {
328  return this->ToDouble(0); };
329  char ToChar(bool *valid) const;
330  char ToChar() const {
331  return this->ToChar(0); };
332  unsigned char ToUnsignedChar(bool *valid) const;
333  unsigned char ToUnsignedChar() const {
334  return this->ToUnsignedChar(0); };
335  signed char ToSignedChar(bool *valid) const;
336  signed char ToSignedChar() const {
337  return this->ToSignedChar(0); };
338  short ToShort(bool *valid) const;
339  short ToShort() const {
340  return this->ToShort(0); };
341  unsigned short ToUnsignedShort(bool *valid) const;
342  unsigned short ToUnsignedShort() const {
343  return this->ToUnsignedShort(0); };
344  int ToInt(bool *valid) const;
345  int ToInt() const {
346  return this->ToInt(0); };
347  unsigned int ToUnsignedInt(bool *valid) const;
348  unsigned int ToUnsignedInt() const {
349  return this->ToUnsignedInt(0); };
350  long ToLong(bool *valid) const;
351  long ToLong() const {
352  return this->ToLong(0); };
353  unsigned long ToUnsignedLong(bool *valid) const;
354  unsigned long ToUnsignedLong() const {
355  return this->ToUnsignedLong(0); };
356  long long ToLongLong(bool *valid) const;
357  long long ToLongLong() const {
358  return this->ToLongLong(0); };
359  unsigned long long ToUnsignedLongLong(bool *valid) const;
360  unsigned long long ToUnsignedLongLong() const {
361  return this->ToUnsignedLongLong(0); };
362  vtkTypeInt64 ToTypeInt64(bool *valid) const;
363  vtkTypeInt64 ToTypeInt64() const {
364  return this->ToTypeInt64(0); };
365  vtkTypeUInt64 ToTypeUInt64(bool *valid) const;
366  vtkTypeUInt64 ToTypeUInt64() const {
367  return this->ToTypeUInt64(0); };
369 
373  vtkObjectBase* ToVTKObject() const;
374 
378  vtkAbstractArray* ToArray() const;
379 
390  bool IsEqual(const vtkVariant& other) const;
391 
393 
423  bool operator==(const vtkVariant &other) const;
424  bool operator!=(const vtkVariant &other) const;
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;
430 
431  friend VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
432 
433 private:
434 
435  template <typename T>
436  T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const;
437 
438  union
439  {
442  float Float;
443  double Double;
444  char Char;
445  unsigned char UnsignedChar;
446  signed char SignedChar;
447  short Short;
448  unsigned short UnsignedShort;
449  int Int;
450  unsigned int UnsignedInt;
451  long Long;
452  unsigned long UnsignedLong;
453  long long LongLong;
454  unsigned long long UnsignedLongLong;
456  } Data;
457 
458  unsigned char Valid;
459  unsigned char Type;
460 
461  friend struct vtkVariantLessThan;
462  friend struct vtkVariantEqual;
465 
466 };
467 
468 #include "vtkVariantInlineOperators.h" // needed for operator== and company
469 
470 // A STL-style function object so you can compare two variants using
471 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
472 // This is a faster version of operator< that makes no attempt to
473 // compare values. It satisfies the STL requirement for a comparison
474 // function for ordered containers like map and set.
475 
476 struct VTKCOMMONCORE_EXPORT vtkVariantLessThan
477 {
478 public:
479  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
480 };
481 
482 struct VTKCOMMONCORE_EXPORT vtkVariantEqual
483 {
484 public:
485  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
486 };
487 
488 struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder
489 {
490 public:
491  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
492 };
493 
494 // Similarly, this is a fast version of operator== that requires that
495 // the types AND the values be equal in order to admit equality.
496 
497 struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality
498 {
499 public:
500  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
501 };
502 
503 #endif
504 // VTK-HeaderTest-Exclude: vtkVariant.h
short Short
Definition: vtkVariant.h:447
signed char ToSignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:336
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:41
int ToInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:345
float ToFloat() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:324
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:342
signed char SignedChar
Definition: vtkVariant.h:446
vtkTypeInt64 ToTypeInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:363
unsigned int UnsignedInt
Definition: vtkVariant.h:450
short ToShort() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:339
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:445
A atomic type representing the union of many types.
Definition: vtkVariant.h:69
vtkObjectBase * VTKObject
Definition: vtkVariant.h:455
const std::string & ToString(TransportMethod)
long long LongLong
Definition: vtkVariant.h:453
unsigned short UnsignedShort
Definition: vtkVariant.h:448
long ToLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:351
long long ToLongLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:357
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:360
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:441
unsigned long UnsignedLong
Definition: vtkVariant.h:452
abstract base class for most VTK objects
Definition: vtkObjectBase.h:62
double Double
Definition: vtkVariant.h:443
float Float
Definition: vtkVariant.h:442
unsigned int ToUnsignedInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:348
double ToDouble() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:327
vtkStdString * String
Definition: vtkVariant.h:440
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:454
unsigned long ToUnsignedLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:354
vtkTypeUInt64 ToTypeUInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:366
char ToChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:330
unsigned char ToUnsignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:333
String class that stores Unicode text.