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 class vtkVariant;
66 struct vtkVariantLessThan;
67 
68 VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
69 
70 class VTKCOMMONCORE_EXPORT vtkVariant
71 {
72 public:
73 
77  vtkVariant();
78 
82  ~vtkVariant();
83 
87  vtkVariant(const vtkVariant & other);
88 
92  vtkVariant(bool value);
93 
97  vtkVariant(char value);
98 
102  vtkVariant(unsigned char value);
103 
107  vtkVariant(signed char value);
108 
112  vtkVariant(short value);
113 
117  vtkVariant(unsigned short value);
118 
122  vtkVariant(int value);
123 
127  vtkVariant(unsigned int value);
128 
132  vtkVariant(long value);
133 
137  vtkVariant(unsigned long value);
138 
142  vtkVariant(long long value);
143 
147  vtkVariant(unsigned long long value);
148 
152  vtkVariant(float value);
153 
157  vtkVariant(double value);
158 
162  vtkVariant(const char* value);
163 
168 
173 
178 
182  vtkVariant(const vtkVariant &other, unsigned int type);
183 
187  const vtkVariant & operator= (const vtkVariant & other);
188 
192  bool IsValid() const;
193 
197  bool IsString() const;
198 
202  bool IsUnicodeString() const;
203 
207  bool IsNumeric() const;
208 
212  bool IsFloat() const;
213 
217  bool IsDouble() const;
218 
222  bool IsChar() const;
223 
227  bool IsUnsignedChar() const;
228 
232  bool IsSignedChar() const;
233 
237  bool IsShort() const;
238 
242  bool IsUnsignedShort() const;
243 
247  bool IsInt() const;
248 
252  bool IsUnsignedInt() const;
253 
257  bool IsLong() const;
258 
262  bool IsUnsignedLong() const;
263 
267  bool Is__Int64() const;
268 
272  bool IsUnsigned__Int64() const;
273 
277  bool IsLongLong() const;
278 
282  bool IsUnsignedLongLong() const;
283 
287  bool IsVTKObject() const;
288 
292  bool IsArray() const;
293 
297  unsigned int GetType() const;
298 
302  const char* GetTypeAsString() const;
303 
307  vtkStdString ToString() const;
308 
312  vtkUnicodeString ToUnicodeString() const;
313 
315 
324  float ToFloat(bool *valid) const;
325  float ToFloat() const {
326  return this->ToFloat(nullptr); };
327  double ToDouble(bool *valid) const;
328  double ToDouble() const {
329  return this->ToDouble(nullptr); };
330  char ToChar(bool *valid) const;
331  char ToChar() const {
332  return this->ToChar(nullptr); };
333  unsigned char ToUnsignedChar(bool *valid) const;
334  unsigned char ToUnsignedChar() const {
335  return this->ToUnsignedChar(nullptr); };
336  signed char ToSignedChar(bool *valid) const;
337  signed char ToSignedChar() const {
338  return this->ToSignedChar(nullptr); };
339  short ToShort(bool *valid) const;
340  short ToShort() const {
341  return this->ToShort(nullptr); };
342  unsigned short ToUnsignedShort(bool *valid) const;
343  unsigned short ToUnsignedShort() const {
344  return this->ToUnsignedShort(nullptr); };
345  int ToInt(bool *valid) const;
346  int ToInt() const {
347  return this->ToInt(nullptr); };
348  unsigned int ToUnsignedInt(bool *valid) const;
349  unsigned int ToUnsignedInt() const {
350  return this->ToUnsignedInt(nullptr); };
351  long ToLong(bool *valid) const;
352  long ToLong() const {
353  return this->ToLong(nullptr); };
354  unsigned long ToUnsignedLong(bool *valid) const;
355  unsigned long ToUnsignedLong() const {
356  return this->ToUnsignedLong(nullptr); };
357  long long ToLongLong(bool *valid) const;
358  long long ToLongLong() const {
359  return this->ToLongLong(nullptr); };
360  unsigned long long ToUnsignedLongLong(bool *valid) const;
361  unsigned long long ToUnsignedLongLong() const {
362  return this->ToUnsignedLongLong(nullptr); };
363  vtkTypeInt64 ToTypeInt64(bool *valid) const;
364  vtkTypeInt64 ToTypeInt64() const {
365  return this->ToTypeInt64(nullptr); };
366  vtkTypeUInt64 ToTypeUInt64(bool *valid) const;
367  vtkTypeUInt64 ToTypeUInt64() const {
368  return this->ToTypeUInt64(nullptr); };
370 
374  vtkObjectBase* ToVTKObject() const;
375 
379  vtkAbstractArray* ToArray() const;
380 
391  bool IsEqual(const vtkVariant& other) const;
392 
394 
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;
429  bool operator>=(const vtkVariant &other) const;
431 
432  friend VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
433 
434 private:
435 
436  template <typename T>
437  T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const;
438 
439  union
440  {
443  float Float;
444  double Double;
445  char Char;
446  unsigned char UnsignedChar;
447  signed char SignedChar;
448  short Short;
449  unsigned short UnsignedShort;
450  int Int;
451  unsigned int UnsignedInt;
452  long Long;
453  unsigned long UnsignedLong;
454  long long LongLong;
455  unsigned long long UnsignedLongLong;
457  } Data;
458 
459  unsigned char Valid;
460  unsigned char Type;
461 
462  friend struct vtkVariantLessThan;
463  friend struct vtkVariantEqual;
466 
467 };
468 
469 #include "vtkVariantInlineOperators.h" // needed for operator== and company
470 
471 // A STL-style function object so you can compare two variants using
472 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
473 // This is a faster version of operator< that makes no attempt to
474 // compare values. It satisfies the STL requirement for a comparison
475 // function for ordered containers like map and set.
476 
477 struct VTKCOMMONCORE_EXPORT vtkVariantLessThan
478 {
479 public:
480  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
481 };
482 
483 struct VTKCOMMONCORE_EXPORT vtkVariantEqual
484 {
485 public:
486  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
487 };
488 
489 struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder
490 {
491 public:
492  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
493 };
494 
495 // Similarly, this is a fast version of operator== that requires that
496 // the types AND the values be equal in order to admit equality.
497 
498 struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality
499 {
500 public:
501  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
502 };
503 
504 #endif
505 // VTK-HeaderTest-Exclude: vtkVariant.h
short Short
Definition: vtkVariant.h:448
signed char ToSignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:337
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
int ToInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:346
float ToFloat() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:325
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:343
signed char SignedChar
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:364
unsigned int UnsignedInt
Definition: vtkVariant.h:451
short ToShort() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:340
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:446
A atomic type representing the union of many types.
Definition: vtkVariant.h:70
vtkObjectBase * VTKObject
Definition: vtkVariant.h:456
const std::string & ToString(TransportMethod)
long long LongLong
Definition: vtkVariant.h:454
unsigned short UnsignedShort
Definition: vtkVariant.h:449
long ToLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:352
long long ToLongLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:358
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:361
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:442
unsigned long UnsignedLong
Definition: vtkVariant.h:453
abstract base class for most VTK objects
Definition: vtkObjectBase.h:68
double Double
Definition: vtkVariant.h:444
float Float
Definition: vtkVariant.h:443
unsigned int ToUnsignedInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:349
double ToDouble() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:328
vtkStdString * String
Definition: vtkVariant.h:441
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:455
unsigned long ToUnsignedLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:355
vtkTypeUInt64 ToTypeUInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:367
char ToChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:331
unsigned char ToUnsignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:334
String class that stores Unicode text.