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 "vtkCommonCoreModule.h" // For export macro 00040 #include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags 00041 #include "vtkSystemIncludes.h" // To define ostream 00042 #include "vtkSetGet.h" // For vtkNotUsed macro 00043 #include "vtkStdString.h" 00044 #include "vtkUnicodeString.h" 00045 00046 // 00047 // The following should be eventually placed in vtkSetGet.h 00048 // 00049 00050 //BTX 00051 // This is same as extended template macro with an additional case for VTK_VARIANT 00052 #define vtkExtraExtendedTemplateMacro(call) \ 00053 vtkExtendedTemplateMacro(call); \ 00054 vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call) 00055 00056 // This is same as Iterator Template macro with an additional case for VTK_VARIANT 00057 #define vtkExtendedArrayIteratorTemplateMacro(call) \ 00058 vtkArrayIteratorTemplateMacro(call); \ 00059 vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call); 00060 //ETX 00061 00062 class vtkStdString; 00063 class vtkUnicodeString; 00064 class vtkObjectBase; 00065 class vtkAbstractArray; 00066 // workaround clang bug, needs export on forward declaration 00067 #ifdef __clang__ 00068 class VTKCOMMONCORE_EXPORT vtkVariant; 00069 #else 00070 class vtkVariant; 00071 #endif 00072 struct vtkVariantLessThan; 00073 00074 //BTX 00075 VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val ); 00076 //ETX 00077 00078 class VTKCOMMONCORE_EXPORT vtkVariant 00079 { 00080 public: 00081 00083 vtkVariant(); 00084 00086 ~vtkVariant(); 00087 00089 vtkVariant(const vtkVariant & other); 00090 00092 vtkVariant(bool value); 00093 00095 vtkVariant(char value); 00096 00098 vtkVariant(unsigned char value); 00099 00101 vtkVariant(signed char value); 00102 00104 vtkVariant(short value); 00105 00107 vtkVariant(unsigned short value); 00108 00110 vtkVariant(int value); 00111 00113 vtkVariant(unsigned int value); 00114 00116 vtkVariant(long value); 00117 00119 vtkVariant(unsigned long value); 00120 00121 #if defined(VTK_TYPE_USE___INT64) 00122 00123 vtkVariant(__int64 value); 00124 00126 00127 vtkVariant(unsigned __int64 value); 00128 #endif 00129 #if defined(VTK_TYPE_USE_LONG_LONG) 00130 00131 00132 vtkVariant(long long value); 00133 00135 00136 vtkVariant(unsigned long long value); 00137 #endif 00138 00139 00141 vtkVariant(float value); 00142 00144 vtkVariant(double value); 00145 00147 vtkVariant(const char* value); 00148 00150 vtkVariant(vtkStdString value); 00151 00153 vtkVariant(const vtkUnicodeString& value); 00154 00156 vtkVariant(vtkObjectBase* value); 00157 00159 vtkVariant(const vtkVariant &other, unsigned int type); 00160 00162 const vtkVariant & operator= (const vtkVariant & other); 00163 00165 bool IsValid() const; 00166 00168 bool IsString() const; 00169 00171 bool IsUnicodeString() const; 00172 00174 bool IsNumeric() const; 00175 00177 bool IsFloat() const; 00178 00180 bool IsDouble() const; 00181 00183 bool IsChar() const; 00184 00186 bool IsUnsignedChar() const; 00187 00189 bool IsSignedChar() const; 00190 00192 bool IsShort() const; 00193 00195 bool IsUnsignedShort() const; 00196 00198 bool IsInt() const; 00199 00201 bool IsUnsignedInt() const; 00202 00204 bool IsLong() const; 00205 00207 bool IsUnsignedLong() const; 00208 00210 bool Is__Int64() const; 00211 00213 bool IsUnsigned__Int64() const; 00214 00216 bool IsLongLong() const; 00217 00219 bool IsUnsignedLongLong() const; 00220 00222 bool IsVTKObject() const; 00223 00226 bool IsArray() const; 00227 00229 unsigned int GetType() const; 00230 00232 const char* GetTypeAsString() const; 00233 00235 vtkStdString ToString() const; 00236 00238 vtkUnicodeString ToUnicodeString() const; 00239 00241 00247 float ToFloat(bool *valid) const; 00248 float ToFloat() const { 00249 return this->ToFloat(0); }; 00250 double ToDouble(bool *valid) const; 00251 double ToDouble() const { 00252 return this->ToDouble(0); }; 00253 char ToChar(bool *valid) const; 00254 char ToChar() const { 00255 return this->ToChar(0); }; 00256 unsigned char ToUnsignedChar(bool *valid) const; 00257 unsigned char ToUnsignedChar() const { 00258 return this->ToUnsignedChar(0); }; 00259 signed char ToSignedChar(bool *valid) const; 00260 signed char ToSignedChar() const { 00261 return this->ToSignedChar(0); }; 00262 short ToShort(bool *valid) const; 00263 short ToShort() const { 00264 return this->ToShort(0); }; 00265 unsigned short ToUnsignedShort(bool *valid) const; 00266 unsigned short ToUnsignedShort() const { 00267 return this->ToUnsignedShort(0); }; 00268 int ToInt(bool *valid) const; 00269 int ToInt() const { 00270 return this->ToInt(0); }; 00271 unsigned int ToUnsignedInt(bool *valid) const; 00272 unsigned int ToUnsignedInt() const { 00273 return this->ToUnsignedInt(0); }; 00274 long ToLong(bool *valid) const; 00275 long ToLong() const { 00276 return this->ToLong(0); }; 00277 unsigned long ToUnsignedLong(bool *valid) const; 00278 unsigned long ToUnsignedLong() const { 00279 return this->ToUnsignedLong(0); }; 00280 #if defined(VTK_TYPE_USE___INT64) 00281 __int64 To__Int64(bool *valid) const; 00282 __int64 To__Int64() const { 00283 return this->To__Int64(0); }; 00284 unsigned __int64 ToUnsigned__Int64(bool *valid) const; 00285 unsigned __int64 ToUnsigned__Int64() const { 00286 return this->ToUnsigned__Int64(0); }; 00287 #endif 00288 #if defined(VTK_TYPE_USE_LONG_LONG) 00289 long long ToLongLong(bool *valid) const; 00290 long long ToLongLong() const { 00291 return this->ToLongLong(0); }; 00292 unsigned long long ToUnsignedLongLong(bool *valid) const; 00293 unsigned long long ToUnsignedLongLong() const { 00294 return this->ToUnsignedLongLong(0); }; 00295 #endif 00296 vtkTypeInt64 ToTypeInt64(bool *valid) const; 00297 vtkTypeInt64 ToTypeInt64() const { 00298 return this->ToTypeInt64(0); }; 00299 vtkTypeUInt64 ToTypeUInt64(bool *valid) const; 00300 vtkTypeUInt64 ToTypeUInt64() const { 00301 return this->ToTypeUInt64(0); }; 00303 00305 vtkObjectBase* ToVTKObject() const; 00306 00308 vtkAbstractArray* ToArray() const; 00309 00316 bool IsEqual(const vtkVariant& other) const; 00317 00319 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; 00344 bool operator>=(const vtkVariant &other) const; 00346 00347 //BTX 00348 friend VTKCOMMONCORE_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val ); 00349 //ETX 00350 00351 private: 00352 //BTX 00353 template <typename T> 00354 T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const; 00355 00356 union 00357 { 00358 vtkStdString* String; 00359 vtkUnicodeString* UnicodeString; 00360 float Float; 00361 double Double; 00362 char Char; 00363 unsigned char UnsignedChar; 00364 signed char SignedChar; 00365 short Short; 00366 unsigned short UnsignedShort; 00367 int Int; 00368 unsigned int UnsignedInt; 00369 long Long; 00370 unsigned long UnsignedLong; 00371 #if defined(VTK_TYPE_USE___INT64) 00372 __int64 __Int64; 00373 unsigned __int64 Unsigned__Int64; 00374 #endif 00375 #if defined(VTK_TYPE_USE_LONG_LONG) 00376 long long LongLong; 00377 unsigned long long UnsignedLongLong; 00378 #endif 00379 vtkObjectBase* VTKObject; 00380 } Data; 00381 00382 unsigned char Valid; 00383 unsigned char Type; 00384 00385 friend struct vtkVariantLessThan; 00386 friend struct vtkVariantEqual; 00387 friend struct vtkVariantStrictWeakOrder; 00388 friend struct vtkVariantStrictEquality; 00389 //ETX 00390 }; 00391 00392 //BTX 00393 00394 #include "vtkVariantInlineOperators.h" // needed for operator== and company 00395 00396 // A STL-style function object so you can compare two variants using 00397 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder. 00398 // This is a faster version of operator< that makes no attempt to 00399 // compare values. It satisfies the STL requirement for a comparison 00400 // function for ordered containers like map and set. 00401 00402 struct VTKCOMMONCORE_EXPORT vtkVariantLessThan 00403 { 00404 public: 00405 bool operator()(const vtkVariant &s1, const vtkVariant &s2) const; 00406 }; 00407 00408 struct VTKCOMMONCORE_EXPORT vtkVariantEqual 00409 { 00410 public: 00411 bool operator()(const vtkVariant &s1, const vtkVariant &s2) const; 00412 }; 00413 00414 struct VTKCOMMONCORE_EXPORT vtkVariantStrictWeakOrder 00415 { 00416 public: 00417 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const; 00418 }; 00419 00420 // Similarly, this is a fast version of operator== that requires that 00421 // the types AND the values be equal in order to admit equality. 00422 00423 struct VTKCOMMONCORE_EXPORT vtkVariantStrictEquality 00424 { 00425 public: 00426 bool operator()(const vtkVariant &s1, const vtkVariant &s2) const; 00427 }; 00428 00429 //ETX 00430 00431 #endif 00432 // VTK-HeaderTest-Exclude: vtkVariant.h