VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkVariant.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 /*------------------------------------------------------------------------- 00016 Copyright 2008 Sandia Corporation. 00017 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00018 the U.S. Government retains certain rights in this software. 00019 -------------------------------------------------------------------------*/ 00036 #ifndef __vtkVariant_h 00037 #define __vtkVariant_h 00038 00039 #include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags 00040 #include "vtkSystemIncludes.h" // To define ostream 00041 #include "vtkSetGet.h" // For vtkNotUsed macro 00042 #include "vtkStdString.h" 00043 #include "vtkUnicodeString.h" 00044 00045 // 00046 // The following should be eventually placed in vtkSetGet.h 00047 // 00048 00049 //BTX 00050 // This is same as extended template macro with an additional case for VTK_VARIANT 00051 #define vtkExtraExtendedTemplateMacro(call) \ 00052 vtkExtendedTemplateMacro(call); \ 00053 vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call) 00054 00055 // This is same as Iterator Template macro with an additional case for VTK_VARIANT 00056 #define vtkExtendedArrayIteratorTemplateMacro(call) \ 00057 vtkArrayIteratorTemplateMacro(call); \ 00058 vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call); 00059 //ETX 00060 00061 class vtkStdString; 00062 class vtkUnicodeString; 00063 class vtkObjectBase; 00064 class vtkAbstractArray; 00065 class vtkVariant; 00066 struct vtkVariantLessThan; 00067 00068 //BTX 00069 VTK_COMMON_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val ); 00070 //ETX 00071 00072 class VTK_COMMON_EXPORT vtkVariant 00073 { 00074 public: 00075 00077 vtkVariant(); 00078 00080 ~vtkVariant(); 00081 00083 vtkVariant(const vtkVariant & other); 00084 00086 vtkVariant(bool value); 00087 00089 vtkVariant(char value); 00090 00092 vtkVariant(unsigned char value); 00093 00095 vtkVariant(signed char value); 00096 00098 vtkVariant(short value); 00099 00101 vtkVariant(unsigned short value); 00102 00104 vtkVariant(int value); 00105 00107 vtkVariant(unsigned int value); 00108 00110 vtkVariant(long value); 00111 00113 vtkVariant(unsigned long value); 00114 00115 #if defined(VTK_TYPE_USE___INT64) 00116 00117 vtkVariant(__int64 value); 00118 00120 00121 vtkVariant(unsigned __int64 value); 00122 #endif 00123 #if defined(VTK_TYPE_USE_LONG_LONG) 00124 00125 00126 vtkVariant(long long value); 00127 00129 00130 vtkVariant(unsigned long long value); 00131 #endif 00132 00133 00135 vtkVariant(float value); 00136 00138 vtkVariant(double value); 00139 00141 vtkVariant(const char* value); 00142 00144 vtkVariant(vtkStdString value); 00145 00147 vtkVariant(const vtkUnicodeString& value); 00148 00150 vtkVariant(vtkObjectBase* value); 00151 00153 vtkVariant(const vtkVariant &other, unsigned int type); 00154 00156 const vtkVariant & operator= (const vtkVariant & other); 00157 00159 bool IsValid() const; 00160 00162 bool IsString() const; 00163 00165 bool IsUnicodeString() const; 00166 00168 bool IsNumeric() const; 00169 00171 bool IsFloat() const; 00172 00174 bool IsDouble() const; 00175 00177 bool IsChar() const; 00178 00180 bool IsUnsignedChar() const; 00181 00183 bool IsSignedChar() const; 00184 00186 bool IsShort() const; 00187 00189 bool IsUnsignedShort() const; 00190 00192 bool IsInt() const; 00193 00195 bool IsUnsignedInt() const; 00196 00198 bool IsLong() const; 00199 00201 bool IsUnsignedLong() const; 00202 00204 bool Is__Int64() const; 00205 00207 bool IsUnsigned__Int64() const; 00208 00210 bool IsLongLong() const; 00211 00213 bool IsUnsignedLongLong() const; 00214 00216 bool IsVTKObject() const; 00217 00220 bool IsArray() const; 00221 00223 unsigned int GetType() const; 00224 00226 const char* GetTypeAsString() const; 00227 00229 vtkStdString ToString() const; 00230 00232 vtkUnicodeString ToUnicodeString() const; 00233 00235 00241 float ToFloat(bool *valid) const; 00242 float ToFloat() const { 00243 return this->ToFloat(0); }; 00244 double ToDouble(bool *valid) const; 00245 double ToDouble() const { 00246 return this->ToDouble(0); }; 00247 char ToChar(bool *valid) const; 00248 char ToChar() const { 00249 return this->ToChar(0); }; 00250 unsigned char ToUnsignedChar(bool *valid) const; 00251 unsigned char ToUnsignedChar() const { 00252 return this->ToUnsignedChar(0); }; 00253 signed char ToSignedChar(bool *valid) const; 00254 signed char ToSignedChar() const { 00255 return this->ToSignedChar(0); }; 00256 short ToShort(bool *valid) const; 00257 short ToShort() const { 00258 return this->ToShort(0); }; 00259 unsigned short ToUnsignedShort(bool *valid) const; 00260 unsigned short ToUnsignedShort() const { 00261 return this->ToUnsignedShort(0); }; 00262 int ToInt(bool *valid) const; 00263 int ToInt() const { 00264 return this->ToInt(0); }; 00265 unsigned int ToUnsignedInt(bool *valid) const; 00266 unsigned int ToUnsignedInt() const { 00267 return this->ToUnsignedInt(0); }; 00268 long ToLong(bool *valid) const; 00269 long ToLong() const { 00270 return this->ToLong(0); }; 00271 unsigned long ToUnsignedLong(bool *valid) const; 00272 unsigned long ToUnsignedLong() const { 00273 return this->ToUnsignedLong(0); }; 00274 #if defined(VTK_TYPE_USE___INT64) 00275 __int64 To__Int64(bool *valid) const; 00276 __int64 To__Int64() const { 00277 return this->To__Int64(0); }; 00278 unsigned __int64 ToUnsigned__Int64(bool *valid) const; 00279 unsigned __int64 ToUnsigned__Int64() const { 00280 return this->ToUnsigned__Int64(0); }; 00281 #endif 00282 #if defined(VTK_TYPE_USE_LONG_LONG) 00283 long long ToLongLong(bool *valid) const; 00284 long long ToLongLong() const { 00285 return this->ToLongLong(0); }; 00286 unsigned long long ToUnsignedLongLong(bool *valid) const; 00287 unsigned long long ToUnsignedLongLong() const { 00288 return this->ToUnsignedLongLong(0); }; 00289 #endif 00290 vtkTypeInt64 ToTypeInt64(bool *valid) const; 00291 vtkTypeInt64 ToTypeInt64() const { 00292 return this->ToTypeInt64(0); }; 00293 vtkTypeUInt64 ToTypeUInt64(bool *valid) const; 00294 vtkTypeUInt64 ToTypeUInt64() const { 00295 return this->ToTypeUInt64(0); }; 00297 00299 vtkObjectBase* ToVTKObject() const; 00300 00302 vtkAbstractArray* ToArray() const; 00303 00304 //BTX 00305 template <typename T> 00306 T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const; 00307 //ETX 00308 00315 bool IsEqual(const vtkVariant& other) const; 00316 00318 00338 bool operator==(const vtkVariant &other) const; 00339 bool operator!=(const vtkVariant &other) const; 00340 bool operator<(const vtkVariant &other) const; 00341 bool operator>(const vtkVariant &other) const; 00342 bool operator<=(const vtkVariant &other) const; 00343 bool operator>=(const vtkVariant &other) const; 00345 00346 //BTX 00347 friend VTK_COMMON_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val ); 00348 //ETX 00349 00350 private: 00351 //BTX 00352 union 00353 { 00354 vtkStdString* String; 00355 vtkUnicodeString* UnicodeString; 00356 float Float; 00357 double Double; 00358 char Char; 00359 unsigned char UnsignedChar; 00360 signed char SignedChar; 00361 short Short; 00362 unsigned short UnsignedShort; 00363 int Int; 00364 unsigned int UnsignedInt; 00365 long Long; 00366 unsigned long UnsignedLong; 00367 #if defined(VTK_TYPE_USE___INT64) 00368 __int64 __Int64; 00369 unsigned __int64 Unsigned__Int64; 00370 #endif 00371 #if defined(VTK_TYPE_USE_LONG_LONG) 00372 long long LongLong; 00373 unsigned long long UnsignedLongLong; 00374 #endif 00375 vtkObjectBase* VTKObject; 00376 } Data; 00377 00378 unsigned char Valid; 00379 unsigned char Type; 00380 00381 friend struct vtkVariantLessThan; 00382 friend struct vtkVariantEqual; 00383 friend struct vtkVariantStrictWeakOrder; 00384 friend struct vtkVariantStrictEquality; 00385 //ETX 00386 }; 00387 00388 //BTX 00389 00390 #include "vtkVariantInlineOperators.h" // needed for operator== and company 00391 00392 // A STL-style function object so you can compare two variants using 00393 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder. 00394 // This is a faster version of operator< that makes no attempt to 00395 // compare values. It satisfies the STL requirement for a comparison 00396 // function for ordered containers like map and set. 00397 00398 struct VTK_COMMON_EXPORT vtkVariantLessThan 00399 { 00400 public: 00401 bool operator()(const vtkVariant &s1, const vtkVariant &s2) const; 00402 }; 00403 00404 struct VTK_COMMON_EXPORT vtkVariantEqual 00405 { 00406 public: 00407 bool operator()(const vtkVariant &s1, const vtkVariant &s2) const; 00408 }; 00409 00410 struct VTK_COMMON_EXPORT vtkVariantStrictWeakOrder 00411 { 00412 public: 00413 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const; 00414 }; 00415 00416 // Similarly, this is a fast version of operator== that requires that 00417 // the types AND the values be equal in order to admit equality. 00418 00419 struct VTK_COMMON_EXPORT vtkVariantStrictEquality 00420 { 00421 public: 00422 bool operator()(const vtkVariant &s1, const vtkVariant &s2) const; 00423 }; 00424 00425 //ETX 00426 00427 #endif