VTK  9.0.1
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 "vtkObject.h" // For vtkObject's warning support
36 #include "vtkSetGet.h" // For vtkNotUsed macro
37 #include "vtkStdString.h"
38 #include "vtkSystemIncludes.h" // To define ostream
39 #include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags
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:
71  vtkVariant();
72 
76  ~vtkVariant();
77 
81  vtkVariant(const vtkVariant& other);
82 
86  vtkVariant(bool value);
87 
91  vtkVariant(char value);
92 
96  vtkVariant(unsigned char value);
97 
101  vtkVariant(signed char value);
102 
106  vtkVariant(short value);
107 
111  vtkVariant(unsigned short value);
112 
116  vtkVariant(int value);
117 
121  vtkVariant(unsigned int value);
122 
126  vtkVariant(long value);
127 
131  vtkVariant(unsigned long value);
132 
136  vtkVariant(long long value);
137 
141  vtkVariant(unsigned long long value);
142 
146  vtkVariant(float value);
147 
151  vtkVariant(double value);
152 
156  vtkVariant(const char* value);
157 
162 
167 
172 
176  vtkVariant(const vtkVariant& other, unsigned int type);
177 
181  vtkVariant& operator=(const vtkVariant& other);
182 
186  bool IsValid() const;
187 
191  bool IsString() const;
192 
196  bool IsUnicodeString() const;
197 
201  bool IsNumeric() const;
202 
206  bool IsFloat() const;
207 
211  bool IsDouble() const;
212 
216  bool IsChar() const;
217 
221  bool IsUnsignedChar() const;
222 
226  bool IsSignedChar() const;
227 
231  bool IsShort() const;
232 
236  bool IsUnsignedShort() const;
237 
241  bool IsInt() const;
242 
246  bool IsUnsignedInt() const;
247 
251  bool IsLong() const;
252 
256  bool IsUnsignedLong() const;
257 
261  bool Is__Int64() const;
262 
266  bool IsUnsigned__Int64() const;
267 
271  bool IsLongLong() const;
272 
276  bool IsUnsignedLongLong() const;
277 
281  bool IsVTKObject() const;
282 
286  bool IsArray() const;
287 
291  unsigned int GetType() const;
292 
296  const char* GetTypeAsString() const;
297 
301  vtkStdString ToString() const;
302 
306  vtkUnicodeString ToUnicodeString() const;
307 
309 
318  float ToFloat(bool* valid) const;
319  float ToFloat() const { return this->ToFloat(nullptr); }
320  double ToDouble(bool* valid) const;
321  double ToDouble() const { return this->ToDouble(nullptr); }
322  char ToChar(bool* valid) const;
323  char ToChar() const { return this->ToChar(nullptr); }
324  unsigned char ToUnsignedChar(bool* valid) const;
325  unsigned char ToUnsignedChar() const { return this->ToUnsignedChar(nullptr); }
326  signed char ToSignedChar(bool* valid) const;
327  signed char ToSignedChar() const { return this->ToSignedChar(nullptr); }
328  short ToShort(bool* valid) const;
329  short ToShort() const { return this->ToShort(nullptr); }
330  unsigned short ToUnsignedShort(bool* valid) const;
331  unsigned short ToUnsignedShort() const { return this->ToUnsignedShort(nullptr); }
332  int ToInt(bool* valid) const;
333  int ToInt() const { return this->ToInt(nullptr); }
334  unsigned int ToUnsignedInt(bool* valid) const;
335  unsigned int ToUnsignedInt() const { return this->ToUnsignedInt(nullptr); }
336  long ToLong(bool* valid) const;
337  long ToLong() const { return this->ToLong(nullptr); }
338  unsigned long ToUnsignedLong(bool* valid) const;
339  unsigned long ToUnsignedLong() const { return this->ToUnsignedLong(nullptr); }
340  long long ToLongLong(bool* valid) const;
341  long long ToLongLong() const { return this->ToLongLong(nullptr); }
342  unsigned long long ToUnsignedLongLong(bool* valid) const;
343  unsigned long long ToUnsignedLongLong() const { return this->ToUnsignedLongLong(nullptr); }
344  vtkTypeInt64 ToTypeInt64(bool* valid) const;
345  vtkTypeInt64 ToTypeInt64() const { return this->ToTypeInt64(nullptr); }
346  vtkTypeUInt64 ToTypeUInt64(bool* valid) const;
347  vtkTypeUInt64 ToTypeUInt64() const { return this->ToTypeUInt64(nullptr); }
349 
353  vtkObjectBase* ToVTKObject() const;
354 
358  vtkAbstractArray* ToArray() const;
359 
370  bool IsEqual(const vtkVariant& other) const;
371 
373 
403  bool operator==(const vtkVariant& other) const;
404  bool operator!=(const vtkVariant& other) const;
405  bool operator<(const vtkVariant& other) const;
406  bool operator>(const vtkVariant& other) const;
407  bool operator<=(const vtkVariant& other) const;
408  bool operator>=(const vtkVariant& other) const;
410 
411  friend VTKCOMMONCORE_EXPORT ostream& operator<<(ostream& os, const vtkVariant& val);
412 
413 private:
414  template <typename T>
415  T ToNumeric(bool* valid, T* vtkNotUsed(ignored)) const;
416 
417  union {
420  float Float;
421  double Double;
422  char Char;
423  unsigned char UnsignedChar;
424  signed char SignedChar;
425  short Short;
426  unsigned short UnsignedShort;
427  int Int;
428  unsigned int UnsignedInt;
429  long Long;
430  unsigned long UnsignedLong;
431  long long LongLong;
432  unsigned long long UnsignedLongLong;
434  } Data;
435 
436  unsigned char Valid;
437  unsigned char Type;
438 
439  friend struct vtkVariantLessThan;
440  friend struct vtkVariantEqual;
443 };
444 
445 #include "vtkVariantInlineOperators.h" // needed for operator== and company
446 
447 // A STL-style function object so you can compare two variants using
448 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
449 // This is a faster version of operator< that makes no attempt to
450 // compare values. It satisfies the STL requirement for a comparison
451 // function for ordered containers like map and set.
452 
453 struct VTKCOMMONCORE_EXPORT vtkVariantLessThan
454 {
455 public:
456  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
457 };
458 
459 struct VTKCOMMONCORE_EXPORT vtkVariantEqual
460 {
461 public:
462  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
463 };
464 
465 struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder
466 {
467 public:
468  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
469 };
470 
471 // Similarly, this is a fast version of operator== that requires that
472 // the types AND the values be equal in order to admit equality.
473 
474 struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality
475 {
476 public:
477  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
478 };
479 
480 #endif
481 // VTK-HeaderTest-Exclude: vtkVariant.h
short Short
Definition: vtkVariant.h:425
signed char ToSignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:327
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:333
float ToFloat() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:319
VTKCOMMONCORE_EXPORT bool operator>=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
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:331
signed char SignedChar
Definition: vtkVariant.h:424
vtkTypeInt64 ToTypeInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:345
unsigned int UnsignedInt
Definition: vtkVariant.h:428
short ToShort() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:329
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:423
A atomic type representing the union of many types.
Definition: vtkVariant.h:65
vtkObjectBase * VTKObject
Definition: vtkVariant.h:433
long long LongLong
Definition: vtkVariant.h:431
unsigned short UnsignedShort
Definition: vtkVariant.h:426
long ToLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:337
long long ToLongLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:341
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:343
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:419
unsigned long UnsignedLong
Definition: vtkVariant.h:430
abstract base class for most VTK objects
Definition: vtkObjectBase.h:63
double Double
Definition: vtkVariant.h:421
float Float
Definition: vtkVariant.h:420
unsigned int ToUnsignedInt() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:335
double ToDouble() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:321
vtkStdString * String
Definition: vtkVariant.h:418
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:432
unsigned long ToUnsignedLong() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:339
vtkTypeUInt64 ToTypeUInt64() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:347
char ToChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:323
unsigned char ToUnsignedChar() const
Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type...
Definition: vtkVariant.h:325
String class that stores Unicode text.