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