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 "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags
40 #include "vtkSystemIncludes.h" // To define ostream
41 #include "vtkSetGet.h" // For vtkNotUsed macro
42 #include "vtkStdString.h"
43 #include "vtkUnicodeString.h"
44 
45 //
46 // The following should be eventually placed in vtkSetGet.h
47 //
48 
49 //BTX
50 // This is same as extended template macro with an additional case for VTK_VARIANT
51 #define vtkExtraExtendedTemplateMacro(call) \
52  vtkExtendedTemplateMacro(call); \
53  vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call)
54 
55 // This is same as Iterator Template macro with an additional case for VTK_VARIANT
56 #define vtkExtendedArrayIteratorTemplateMacro(call) \
57  vtkArrayIteratorTemplateMacro(call); \
58  vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call);
59 //ETX
60 
61 class vtkStdString;
62 class vtkUnicodeString;
63 class vtkObjectBase;
64 class vtkAbstractArray;
65 class vtkVariant;
66 struct vtkVariantLessThan;
67 
68 //BTX
69 VTK_COMMON_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
70 //ETX
71 
73 {
74 public:
75 
77  vtkVariant();
78 
80  ~vtkVariant();
81 
83  vtkVariant(const vtkVariant & other);
84 
86  vtkVariant(bool value);
87 
89  vtkVariant(char value);
90 
92  vtkVariant(unsigned char value);
93 
95  vtkVariant(signed char value);
96 
98  vtkVariant(short value);
99 
101  vtkVariant(unsigned short value);
102 
104  vtkVariant(int value);
105 
107  vtkVariant(unsigned int value);
108 
110  vtkVariant(long value);
111 
113  vtkVariant(unsigned long value);
114 
115 #if defined(VTK_TYPE_USE___INT64)
116 
117  vtkVariant(__int64 value);
118 
120 
121  vtkVariant(unsigned __int64 value);
122 #endif
123 #if defined(VTK_TYPE_USE_LONG_LONG)
124  // Description:
125  // Create a long long variant.
126  vtkVariant(long long value);
128 
130 
131  vtkVariant(unsigned long long value);
132 #endif
133 
134 
136  vtkVariant(float value);
137 
139  vtkVariant(double value);
140 
142  vtkVariant(const char* value);
143 
145  vtkVariant(vtkStdString value);
146 
148  vtkVariant(const vtkUnicodeString& value);
149 
151  vtkVariant(vtkObjectBase* value);
152 
154  vtkVariant(const vtkVariant &other, unsigned int type);
155 
157  const vtkVariant & operator= (const vtkVariant & other);
158 
160  bool IsValid() const;
161 
163  bool IsString() const;
164 
166  bool IsUnicodeString() const;
167 
169  bool IsNumeric() const;
170 
172  bool IsFloat() const;
173 
175  bool IsDouble() const;
176 
178  bool IsChar() const;
179 
181  bool IsUnsignedChar() const;
182 
184  bool IsSignedChar() const;
185 
187  bool IsShort() const;
188 
190  bool IsUnsignedShort() const;
191 
193  bool IsInt() const;
194 
196  bool IsUnsignedInt() const;
197 
199  bool IsLong() const;
200 
202  bool IsUnsignedLong() const;
203 
205  bool Is__Int64() const;
206 
208  bool IsUnsigned__Int64() const;
209 
211  bool IsLongLong() const;
212 
214  bool IsUnsignedLongLong() const;
215 
217  bool IsVTKObject() const;
218 
221  bool IsArray() const;
222 
224  unsigned int GetType() const;
225 
227  const char* GetTypeAsString() const;
228 
230  vtkStdString ToString() const;
231 
233  vtkUnicodeString ToUnicodeString() const;
234 
236 
242  float ToFloat(bool *valid) const;
243  float ToFloat() const {
244  return this->ToFloat(0); };
245  double ToDouble(bool *valid) const;
246  double ToDouble() const {
247  return this->ToDouble(0); };
248  char ToChar(bool *valid) const;
249  char ToChar() const {
250  return this->ToChar(0); };
251  unsigned char ToUnsignedChar(bool *valid) const;
252  unsigned char ToUnsignedChar() const {
253  return this->ToUnsignedChar(0); };
254  signed char ToSignedChar(bool *valid) const;
255  signed char ToSignedChar() const {
256  return this->ToSignedChar(0); };
257  short ToShort(bool *valid) const;
258  short ToShort() const {
259  return this->ToShort(0); };
260  unsigned short ToUnsignedShort(bool *valid) const;
261  unsigned short ToUnsignedShort() const {
262  return this->ToUnsignedShort(0); };
263  int ToInt(bool *valid) const;
264  int ToInt() const {
265  return this->ToInt(0); };
266  unsigned int ToUnsignedInt(bool *valid) const;
267  unsigned int ToUnsignedInt() const {
268  return this->ToUnsignedInt(0); };
269  long ToLong(bool *valid) const;
270  long ToLong() const {
271  return this->ToLong(0); };
272  unsigned long ToUnsignedLong(bool *valid) const;
273  unsigned long ToUnsignedLong() const {
274  return this->ToUnsignedLong(0); };
275 #if defined(VTK_TYPE_USE___INT64)
276  __int64 To__Int64(bool *valid) const;
277  __int64 To__Int64() const {
278  return this->To__Int64(0); };
279  unsigned __int64 ToUnsigned__Int64(bool *valid) const;
280  unsigned __int64 ToUnsigned__Int64() const {
281  return this->ToUnsigned__Int64(0); };
282 #endif
283 #if defined(VTK_TYPE_USE_LONG_LONG)
284  long long ToLongLong(bool *valid) const;
285  long long ToLongLong() const {
286  return this->ToLongLong(0); };
287  unsigned long long ToUnsignedLongLong(bool *valid) const;
288  unsigned long long ToUnsignedLongLong() const {
289  return this->ToUnsignedLongLong(0); };
290 #endif
291  vtkTypeInt64 ToTypeInt64(bool *valid) const;
292  vtkTypeInt64 ToTypeInt64() const {
293  return this->ToTypeInt64(0); };
294  vtkTypeUInt64 ToTypeUInt64(bool *valid) const;
295  vtkTypeUInt64 ToTypeUInt64() const {
296  return this->ToTypeUInt64(0); };
298 
300  vtkObjectBase* ToVTKObject() const;
301 
303  vtkAbstractArray* ToArray() const;
304 
305 //BTX
306  template <typename T>
307  T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const;
308 //ETX
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 VTK_COMMON_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
349 //ETX
350 
351 private:
352 //BTX
353  union
354  {
357  float Float;
358  double Double;
359  char Char;
360  unsigned char UnsignedChar;
361  signed char SignedChar;
362  short Short;
363  unsigned short UnsignedShort;
364  int Int;
365  unsigned int UnsignedInt;
366  long Long;
367  unsigned long UnsignedLong;
368 #if defined(VTK_TYPE_USE___INT64)
369  __int64 __Int64;
370  unsigned __int64 Unsigned__Int64;
371 #endif
372 #if defined(VTK_TYPE_USE_LONG_LONG)
373  long long LongLong;
374  unsigned long long UnsignedLongLong;
375 #endif
377  } Data;
378 
379  unsigned char Valid;
380  unsigned char Type;
381 
382  friend struct vtkVariantLessThan;
383  friend struct vtkVariantEqual;
386 //ETX
387 };
388 
389 //BTX
390 
391 #include "vtkVariantInlineOperators.h" // needed for operator== and company
392 
393 // A STL-style function object so you can compare two variants using
394 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
395 // This is a faster version of operator< that makes no attempt to
396 // compare values. It satisfies the STL requirement for a comparison
397 // function for ordered containers like map and set.
398 
400 {
401 public:
402  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
403 };
404 
406 {
407 public:
408  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
409 };
410 
412 {
413 public:
414  bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
415 };
416 
417 // Similarly, this is a fast version of operator== that requires that
418 // the types AND the values be equal in order to admit equality.
419 
421 {
422 public:
423  bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
424 };
425 
426 //ETX
427 
428 #endif
short Short
Definition: vtkVariant.h:362
unsigned int ToUnsignedInt() const
Definition: vtkVariant.h:267
Wrapper around vtkstd::string to keep symbols short.
Definition: vtkStdString.h:45
VTK_COMMON_EXPORT ostream & operator<<(ostream &os, const vtkVariant &val)
Abstract superclass for all arrays.
signed char SignedChar
Definition: vtkVariant.h:361
unsigned int UnsignedInt
Definition: vtkVariant.h:365
float ToFloat() const
Definition: vtkVariant.h:243
char ToChar() const
Definition: vtkVariant.h:249
double ToDouble() const
Definition: vtkVariant.h:246
unsigned char UnsignedChar
Definition: vtkVariant.h:360
A atomic type representing the union of many types.
Definition: vtkVariant.h:72
unsigned char ToUnsignedChar() const
Definition: vtkVariant.h:252
vtkObjectBase * VTKObject
Definition: vtkVariant.h:376
unsigned short UnsignedShort
Definition: vtkVariant.h:363
VTK_COMMON_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
short ToShort() const
Definition: vtkVariant.h:258
VTK_COMMON_EXPORT bool operator>(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTK_COMMON_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTK_COMMON_EXPORT bool operator>=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTK_COMMON_EXPORT bool operator<=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
#define VTK_COMMON_EXPORT
vtkUnicodeString * UnicodeString
Definition: vtkVariant.h:356
vtkTypeInt64 ToTypeInt64() const
Definition: vtkVariant.h:292
unsigned long UnsignedLong
Definition: vtkVariant.h:367
abstract base class for most VTK objects
Definition: vtkObjectBase.h:59
double Double
Definition: vtkVariant.h:358
float Float
Definition: vtkVariant.h:357
vtkTypeUInt64 ToTypeUInt64() const
Definition: vtkVariant.h:295
vtkStdString * String
Definition: vtkVariant.h:355
int ToInt() const
Definition: vtkVariant.h:264
VTK_COMMON_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
unsigned long ToUnsignedLong() const
Definition: vtkVariant.h:273
unsigned short ToUnsignedShort() const
Definition: vtkVariant.h:261
signed char ToSignedChar() const
Definition: vtkVariant.h:255
long ToLong() const
Definition: vtkVariant.h:270
String class that stores Unicode text.