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 
121 #if defined(VTK_TYPE_USE___INT64)
122 
123  vtkVariant(__int64 value);
124 
126 
127  vtkVariant(unsigned __int64 value);
128 #endif
129 #if defined(VTK_TYPE_USE_LONG_LONG)
130 
131 
132  vtkVariant(long long value);
133 
135 
136  vtkVariant(unsigned long long value);
137 #endif
138 
139 
141  vtkVariant(float value);
142 
144  vtkVariant(double value);
145 
147  vtkVariant(const char* value);
148 
150  vtkVariant(vtkStdString value);
151 
153  vtkVariant(const vtkUnicodeString& value);
154 
156  vtkVariant(vtkObjectBase* value);
157 
159  vtkVariant(const vtkVariant &other, unsigned int type);
160 
162  const vtkVariant & operator= (const vtkVariant & other);
163 
165  bool IsValid() const;
166 
168  bool IsString() const;
169 
171  bool IsUnicodeString() const;
172 
174  bool IsNumeric() const;
175 
177  bool IsFloat() const;
178 
180  bool IsDouble() const;
181 
183  bool IsChar() const;
184 
186  bool IsUnsignedChar() const;
187 
189  bool IsSignedChar() const;
190 
192  bool IsShort() const;
193 
195  bool IsUnsignedShort() const;
196 
198  bool IsInt() const;
199 
201  bool IsUnsignedInt() const;
202 
204  bool IsLong() const;
205 
207  bool IsUnsignedLong() const;
208 
210  bool Is__Int64() const;
211 
213  bool IsUnsigned__Int64() const;
214 
216  bool IsLongLong() const;
217 
219  bool IsUnsignedLongLong() const;
220 
222  bool IsVTKObject() const;
223 
226  bool IsArray() const;
227 
229  unsigned int GetType() const;
230 
232  const char* GetTypeAsString() const;
233 
235  vtkStdString ToString() const;
236 
238  vtkUnicodeString ToUnicodeString() const;
239 
241 
247  float ToFloat(bool *valid) const;
248  float ToFloat() const {
249  return this->ToFloat(0); };
250  double ToDouble(bool *valid) const;
251  double ToDouble() const {
252  return this->ToDouble(0); };
253  char ToChar(bool *valid) const;
254  char ToChar() const {
255  return this->ToChar(0); };
256  unsigned char ToUnsignedChar(bool *valid) const;
257  unsigned char ToUnsignedChar() const {
258  return this->ToUnsignedChar(0); };
259  signed char ToSignedChar(bool *valid) const;
260  signed char ToSignedChar() const {
261  return this->ToSignedChar(0); };
262  short ToShort(bool *valid) const;
263  short ToShort() const {
264  return this->ToShort(0); };
265  unsigned short ToUnsignedShort(bool *valid) const;
266  unsigned short ToUnsignedShort() const {
267  return this->ToUnsignedShort(0); };
268  int ToInt(bool *valid) const;
269  int ToInt() const {
270  return this->ToInt(0); };
271  unsigned int ToUnsignedInt(bool *valid) const;
272  unsigned int ToUnsignedInt() const {
273  return this->ToUnsignedInt(0); };
274  long ToLong(bool *valid) const;
275  long ToLong() const {
276  return this->ToLong(0); };
277  unsigned long ToUnsignedLong(bool *valid) const;
278  unsigned long ToUnsignedLong() const {
279  return this->ToUnsignedLong(0); };
280 #if defined(VTK_TYPE_USE___INT64)
281  __int64 To__Int64(bool *valid) const;
282  __int64 To__Int64() const {
283  return this->To__Int64(0); };
284  unsigned __int64 ToUnsigned__Int64(bool *valid) const;
285  unsigned __int64 ToUnsigned__Int64() const {
286  return this->ToUnsigned__Int64(0); };
287 #endif
288 #if defined(VTK_TYPE_USE_LONG_LONG)
289  long long ToLongLong(bool *valid) const;
290  long long ToLongLong() const {
291  return this->ToLongLong(0); };
292  unsigned long long ToUnsignedLongLong(bool *valid) const;
293  unsigned long long ToUnsignedLongLong() const {
294  return this->ToUnsignedLongLong(0); };
295 #endif
296  vtkTypeInt64 ToTypeInt64(bool *valid) const;
297  vtkTypeInt64 ToTypeInt64() const {
298  return this->ToTypeInt64(0); };
299  vtkTypeUInt64 ToTypeUInt64(bool *valid) const;
300  vtkTypeUInt64 ToTypeUInt64() const {
301  return this->ToTypeUInt64(0); };
303 
305  vtkObjectBase* ToVTKObject() const;
306 
308  vtkAbstractArray* ToArray() const;
309 
316  bool IsEqual(const vtkVariant& other) const;
317 
319 
339  bool operator==(const vtkVariant &other) const;
340  bool operator!=(const vtkVariant &other) const;
341  bool operator<(const vtkVariant &other) const;
342  bool operator>(const vtkVariant &other) const;
343  bool operator<=(const vtkVariant &other) const;
344  bool operator>=(const vtkVariant &other) const;
346 
347 //BTX
348  friend VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
349 //ETX
350 
351 private:
352 //BTX
353  template <typename T>
354  T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const;
355 
356  union
357  {
360  float Float;
361  double Double;
362  char Char;
363  unsigned char UnsignedChar;
364  signed char SignedChar;
365  short Short;
366  unsigned short UnsignedShort;
367  int Int;
368  unsigned int UnsignedInt;
369  long Long;
370  unsigned long UnsignedLong;
371 #if defined(VTK_TYPE_USE___INT64)
372  __int64 __Int64;
373  unsigned __int64 Unsigned__Int64;
374 #endif
375 #if defined(VTK_TYPE_USE_LONG_LONG)
376  long long LongLong;
377  unsigned long long UnsignedLongLong;
378 #endif
380  } Data;
381 
382  unsigned char Valid;
383  unsigned char Type;
384 
385  friend struct vtkVariantLessThan;
386  friend struct vtkVariantEqual;
389 //ETX
390 };
391 
392 //BTX
393 
394 #include "vtkVariantInlineOperators.h" // needed for operator== and company
395 
396 // A STL-style function object so you can compare two variants using
397 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
398 // This is a faster version of operator< that makes no attempt to
399 // compare values. It satisfies the STL requirement for a comparison
400 // function for ordered containers like map and set.
401 
403 {
404 public:
405  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
406 };
407 
409 {
410 public:
411  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
412 };
413 
415 {
416 public:
417  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
418 };
419 
420 // Similarly, this is a fast version of operator== that requires that
421 // the types AND the values be equal in order to admit equality.
422 
424 {
425 public:
426  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
427 };
428 
429 //ETX
430 
431 #endif
432 // VTK-HeaderTest-Exclude: vtkVariant.h
short Short
Definition: vtkVariant.h:365
unsigned int ToUnsignedInt() const
Definition: vtkVariant.h:272
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:364
unsigned int UnsignedInt
Definition: vtkVariant.h:368
float ToFloat() const
Definition: vtkVariant.h:248
char ToChar() const
Definition: vtkVariant.h:254
double ToDouble() const
Definition: vtkVariant.h:251
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:363
A atomic type representing the union of many types.
Definition: vtkVariant.h:78
unsigned char ToUnsignedChar() const
Definition: vtkVariant.h:257
vtkObjectBase * VTKObject
Definition: vtkVariant.h:379
unsigned short UnsignedShort
Definition: vtkVariant.h:366
short ToShort() const
Definition: vtkVariant.h:263
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:359
vtkTypeInt64 ToTypeInt64() const
Definition: vtkVariant.h:297
unsigned long UnsignedLong
Definition: vtkVariant.h:370
abstract base class for most VTK objects
Definition: vtkObjectBase.h:59
double Double
Definition: vtkVariant.h:361
float Float
Definition: vtkVariant.h:360
vtkTypeUInt64 ToTypeUInt64() const
Definition: vtkVariant.h:300
vtkStdString * String
Definition: vtkVariant.h:358
int ToInt() const
Definition: vtkVariant.h:269
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
unsigned long ToUnsignedLong() const
Definition: vtkVariant.h:278
unsigned short ToUnsignedShort() const
Definition: vtkVariant.h:266
signed char ToSignedChar() const
Definition: vtkVariant.h:260
long ToLong() const
Definition: vtkVariant.h:275
String class that stores Unicode text.