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 -------------------------------------------------------------------------*/
36 #ifndef vtkVariant_h
37 #define vtkVariant_h
38 
39 #include "vtkCommonCoreModule.h" // For export macro
40 #include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags
41 #include "vtkSystemIncludes.h" // To define ostream
42 #include "vtkSetGet.h" // For vtkNotUsed macro
43 #include "vtkStdString.h"
44 #include "vtkUnicodeString.h"
45 
46 //
47 // The following should be eventually placed in vtkSetGet.h
48 //
49 
50 //BTX
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 //ETX
61 
62 class vtkStdString;
63 class vtkUnicodeString;
64 class vtkObjectBase;
65 class vtkAbstractArray;
66 // workaround clang bug, needs export on forward declaration
67 #ifdef __clang__
69 #else
70 class vtkVariant;
71 #endif
72 struct vtkVariantLessThan;
73 
74 //BTX
75 VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
76 //ETX
77 
79 {
80 public:
81 
83  vtkVariant();
84 
86  ~vtkVariant();
87 
89  vtkVariant(const vtkVariant & other);
90 
92  vtkVariant(bool value);
93 
95  vtkVariant(char value);
96 
98  vtkVariant(unsigned char value);
99 
101  vtkVariant(signed char value);
102 
104  vtkVariant(short value);
105 
107  vtkVariant(unsigned short value);
108 
110  vtkVariant(int value);
111 
113  vtkVariant(unsigned int value);
114 
116  vtkVariant(long value);
117 
119  vtkVariant(unsigned long value);
120 
122  vtkVariant(long long value);
123 
125  vtkVariant(unsigned long long value);
126 
128  vtkVariant(float value);
129 
131  vtkVariant(double value);
132 
134  vtkVariant(const char* value);
135 
137  vtkVariant(vtkStdString value);
138 
140  vtkVariant(const vtkUnicodeString& value);
141 
143  vtkVariant(vtkObjectBase* value);
144 
146  vtkVariant(const vtkVariant &other, unsigned int type);
147 
149  const vtkVariant & operator= (const vtkVariant & other);
150 
152  bool IsValid() const;
153 
155  bool IsString() const;
156 
158  bool IsUnicodeString() const;
159 
161  bool IsNumeric() const;
162 
164  bool IsFloat() const;
165 
167  bool IsDouble() const;
168 
170  bool IsChar() const;
171 
173  bool IsUnsignedChar() const;
174 
176  bool IsSignedChar() const;
177 
179  bool IsShort() const;
180 
182  bool IsUnsignedShort() const;
183 
185  bool IsInt() const;
186 
188  bool IsUnsignedInt() const;
189 
191  bool IsLong() const;
192 
194  bool IsUnsignedLong() const;
195 
197  bool Is__Int64() const;
198 
200  bool IsUnsigned__Int64() const;
201 
203  bool IsLongLong() const;
204 
206  bool IsUnsignedLongLong() const;
207 
209  bool IsVTKObject() const;
210 
213  bool IsArray() const;
214 
216  unsigned int GetType() const;
217 
219  const char* GetTypeAsString() const;
220 
222  vtkStdString ToString() const;
223 
225  vtkUnicodeString ToUnicodeString() const;
226 
228 
234  float ToFloat(bool *valid) const;
235  float ToFloat() const {
236  return this->ToFloat(0); };
237  double ToDouble(bool *valid) const;
238  double ToDouble() const {
239  return this->ToDouble(0); };
240  char ToChar(bool *valid) const;
241  char ToChar() const {
242  return this->ToChar(0); };
243  unsigned char ToUnsignedChar(bool *valid) const;
244  unsigned char ToUnsignedChar() const {
245  return this->ToUnsignedChar(0); };
246  signed char ToSignedChar(bool *valid) const;
247  signed char ToSignedChar() const {
248  return this->ToSignedChar(0); };
249  short ToShort(bool *valid) const;
250  short ToShort() const {
251  return this->ToShort(0); };
252  unsigned short ToUnsignedShort(bool *valid) const;
253  unsigned short ToUnsignedShort() const {
254  return this->ToUnsignedShort(0); };
255  int ToInt(bool *valid) const;
256  int ToInt() const {
257  return this->ToInt(0); };
258  unsigned int ToUnsignedInt(bool *valid) const;
259  unsigned int ToUnsignedInt() const {
260  return this->ToUnsignedInt(0); };
261  long ToLong(bool *valid) const;
262  long ToLong() const {
263  return this->ToLong(0); };
264  unsigned long ToUnsignedLong(bool *valid) const;
265  unsigned long ToUnsignedLong() const {
266  return this->ToUnsignedLong(0); };
267  long long ToLongLong(bool *valid) const;
268  long long ToLongLong() const {
269  return this->ToLongLong(0); };
270  unsigned long long ToUnsignedLongLong(bool *valid) const;
271  unsigned long long ToUnsignedLongLong() const {
272  return this->ToUnsignedLongLong(0); };
273  vtkTypeInt64 ToTypeInt64(bool *valid) const;
274  vtkTypeInt64 ToTypeInt64() const {
275  return this->ToTypeInt64(0); };
276  vtkTypeUInt64 ToTypeUInt64(bool *valid) const;
277  vtkTypeUInt64 ToTypeUInt64() const {
278  return this->ToTypeUInt64(0); };
280 
282  vtkObjectBase* ToVTKObject() const;
283 
285  vtkAbstractArray* ToArray() const;
286 
293  bool IsEqual(const vtkVariant& other) const;
294 
296 
316  bool operator==(const vtkVariant &other) const;
317  bool operator!=(const vtkVariant &other) const;
318  bool operator<(const vtkVariant &other) const;
319  bool operator>(const vtkVariant &other) const;
320  bool operator<=(const vtkVariant &other) const;
321  bool operator>=(const vtkVariant &other) const;
323 
324 //BTX
325  friend VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
326 //ETX
327 
328 private:
329 //BTX
330  template <typename T>
331  T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const;
332 
333  union
334  {
337  float Float;
338  double Double;
339  char Char;
340  unsigned char UnsignedChar;
341  signed char SignedChar;
342  short Short;
343  unsigned short UnsignedShort;
344  int Int;
345  unsigned int UnsignedInt;
346  long Long;
347  unsigned long UnsignedLong;
348  long long LongLong;
349  unsigned long long UnsignedLongLong;
351  } Data;
352 
353  unsigned char Valid;
354  unsigned char Type;
355 
356  friend struct vtkVariantLessThan;
357  friend struct vtkVariantEqual;
360 //ETX
361 };
362 
363 //BTX
364 
365 #include "vtkVariantInlineOperators.h" // needed for operator== and company
366 
367 // A STL-style function object so you can compare two variants using
368 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
369 // This is a faster version of operator< that makes no attempt to
370 // compare values. It satisfies the STL requirement for a comparison
371 // function for ordered containers like map and set.
372 
374 {
375 public:
376  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
377 };
378 
380 {
381 public:
382  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
383 };
384 
386 {
387 public:
388  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
389 };
390 
391 // Similarly, this is a fast version of operator== that requires that
392 // the types AND the values be equal in order to admit equality.
393 
395 {
396 public:
397  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
398 };
399 
400 //ETX
401 
402 #endif
403 // VTK-HeaderTest-Exclude: vtkVariant.h
short Short
Definition: vtkVariant.h:342
unsigned int ToUnsignedInt() const
Definition: vtkVariant.h:259
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:46
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.
#define VTKCOMMONCORE_EXPORT
signed char SignedChar
Definition: vtkVariant.h:341
unsigned int UnsignedInt
Definition: vtkVariant.h:345
unsigned long long ToUnsignedLongLong() const
Definition: vtkVariant.h:271
float ToFloat() const
Definition: vtkVariant.h:235
char ToChar() const
Definition: vtkVariant.h:241
double ToDouble() const
Definition: vtkVariant.h:238
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:340
A atomic type representing the union of many types.
Definition: vtkVariant.h:78
unsigned char ToUnsignedChar() const
Definition: vtkVariant.h:244
vtkObjectBase * VTKObject
Definition: vtkVariant.h:350
long long LongLong
Definition: vtkVariant.h:348
unsigned short UnsignedShort
Definition: vtkVariant.h:343
short ToShort() const
Definition: vtkVariant.h:250
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:336
vtkTypeInt64 ToTypeInt64() const
Definition: vtkVariant.h:274
unsigned long UnsignedLong
Definition: vtkVariant.h:347
abstract base class for most VTK objects
Definition: vtkObjectBase.h:59
double Double
Definition: vtkVariant.h:338
float Float
Definition: vtkVariant.h:337
vtkTypeUInt64 ToTypeUInt64() const
Definition: vtkVariant.h:277
vtkStdString * String
Definition: vtkVariant.h:335
int ToInt() const
Definition: vtkVariant.h:256
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:349
unsigned long ToUnsignedLong() const
Definition: vtkVariant.h:265
unsigned short ToUnsignedShort() const
Definition: vtkVariant.h:253
signed char ToSignedChar() const
Definition: vtkVariant.h:247
long long ToLongLong() const
Definition: vtkVariant.h:268
long ToLong() const
Definition: vtkVariant.h:262
String class that stores Unicode text.