VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkVariant.h,v $ 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 -------------------------------------------------------------------------*/ 00033 #ifndef __vtkVariant_h 00034 #define __vtkVariant_h 00035 00036 #include "vtkType.h" // To define type IDs and VTK_TYPE_USE_* flags 00037 #include "vtkSystemIncludes.h" // To define ostream 00038 #include "vtkSetGet.h" // For vtkNotUsed macro 00039 #include "vtkStdString.h" 00040 00041 // 00042 // The following should be eventually placed in vtkSetGet.h 00043 // 00044 00045 // This is same as extended template macro with an additional case for VTK_VARIANT 00046 #define vtkExtraExtendedTemplateMacro(call) \ 00047 vtkExtendedTemplateMacro(call); \ 00048 vtkTemplateMacroCase(VTK_VARIANT, vtkVariant, call) 00049 00050 // This is same as Iterator Template macro with an additional case for VTK_VARIANT 00051 #define vtkExtendedArrayIteratorTemplateMacro(call) \ 00052 vtkArrayIteratorTemplateMacro(call); \ 00053 vtkArrayIteratorTemplateMacroCase(VTK_VARIANT, vtkVariant, call); 00054 00055 class vtkStdString; 00056 class vtkObjectBase; 00057 class vtkAbstractArray; 00058 struct vtkVariantLessThan; 00059 00060 class VTK_COMMON_EXPORT vtkVariant 00061 { 00062 public: 00063 00065 vtkVariant(); 00066 00068 ~vtkVariant(); 00069 00071 vtkVariant(const vtkVariant & other); 00072 00074 vtkVariant(char value); 00075 00077 vtkVariant(unsigned char value); 00078 00080 vtkVariant(signed char value); 00081 00083 vtkVariant(short value); 00084 00086 vtkVariant(unsigned short value); 00087 00089 vtkVariant(int value); 00090 00092 vtkVariant(unsigned int value); 00093 00095 vtkVariant(long value); 00096 00098 vtkVariant(unsigned long value); 00099 00100 #if defined(VTK_TYPE_USE___INT64) 00101 00102 vtkVariant(__int64 value); 00103 00105 vtkVariant(unsigned __int64 value); 00106 #endif 00107 #if defined(VTK_TYPE_USE_LONG_LONG) 00108 00109 vtkVariant(long long value); 00110 00112 vtkVariant(unsigned long long value); 00113 #endif 00114 00116 vtkVariant(float value); 00117 00119 vtkVariant(double value); 00120 00122 vtkVariant(const char* value); 00123 00125 vtkVariant(vtkStdString value); 00126 00128 vtkVariant(vtkObjectBase* value); 00129 00131 const vtkVariant & operator= (const vtkVariant & other); 00132 00134 bool IsValid() const; 00135 00137 bool IsString() const; 00138 00140 bool IsNumeric() const; 00141 00143 bool IsFloat() const; 00144 00146 bool IsDouble() const; 00147 00149 bool IsChar() const; 00150 00152 bool IsUnsignedChar() const; 00153 00155 bool IsSignedChar() const; 00156 00158 bool IsShort() const; 00159 00161 bool IsUnsignedShort() const; 00162 00164 bool IsInt() const; 00165 00167 bool IsUnsignedInt() const; 00168 00170 bool IsLong() const; 00171 00173 bool IsUnsignedLong() const; 00174 00176 bool Is__Int64() const; 00177 00179 bool IsUnsigned__Int64() const; 00180 00182 bool IsLongLong() const; 00183 00185 bool IsUnsignedLongLong() const; 00186 00188 bool IsVTKObject() const; 00189 00192 bool IsArray() const; 00193 00195 unsigned int GetType() const; 00196 00198 const char* GetTypeAsString() const; 00199 00201 vtkStdString ToString() const; 00202 00204 00210 float ToFloat(bool* valid = 0) const; 00211 double ToDouble(bool* valid = 0) const; 00212 char ToChar(bool* valid = 0) const; 00213 unsigned char ToUnsignedChar(bool* valid = 0) const; 00214 signed char ToSignedChar(bool* valid = 0) const; 00215 short ToShort(bool* valid = 0) const; 00216 unsigned short ToUnsignedShort(bool* valid = 0) const; 00217 int ToInt(bool* valid = 0) const; 00218 unsigned int ToUnsignedInt(bool* valid = 0) const; 00219 long ToLong(bool* valid = 0) const; 00220 unsigned long ToUnsignedLong(bool* valid = 0) const; 00221 #if defined(VTK_TYPE_USE___INT64) 00222 __int64 To__Int64(bool* valid = 0) const; 00223 unsigned __int64 ToUnsigned__Int64(bool* valid = 0) const; 00225 #endif 00226 #if defined(VTK_TYPE_USE_LONG_LONG) 00227 long long ToLongLong(bool* valid = 0) const; 00228 unsigned long long ToUnsignedLongLong(bool* valid = 0) const; 00229 #endif 00230 vtkTypeInt64 ToTypeInt64(bool* valid = 0) const; 00231 vtkTypeUInt64 ToTypeUInt64(bool* valid = 0) const; 00232 00234 vtkObjectBase* ToVTKObject() const; 00235 00237 vtkAbstractArray* ToArray() const; 00238 00239 template <typename T> 00240 T ToNumeric(bool* valid, T* vtkNotUsed(ignored)) const; 00241 00248 bool IsEqual(const vtkVariant& other) const; 00249 00251 00271 bool operator==(const vtkVariant &other) const; 00272 bool operator!=(const vtkVariant &other) const; 00273 bool operator<(const vtkVariant &other) const; 00274 bool operator>(const vtkVariant &other) const; 00275 bool operator<=(const vtkVariant &other) const; 00276 bool operator>=(const vtkVariant &other) const; 00278 00279 00280 00281 00282 private: 00283 union 00284 { 00285 vtkStdString* String; 00286 float Float; 00287 double Double; 00288 char Char; 00289 unsigned char UnsignedChar; 00290 signed char SignedChar; 00291 short Short; 00292 unsigned short UnsignedShort; 00293 int Int; 00294 unsigned int UnsignedInt; 00295 long Long; 00296 unsigned long UnsignedLong; 00297 #if defined(VTK_TYPE_USE___INT64) 00298 __int64 __Int64; 00299 unsigned __int64 Unsigned__Int64; 00300 #endif 00301 #if defined(VTK_TYPE_USE_LONG_LONG) 00302 long long LongLong; 00303 unsigned long long UnsignedLongLong; 00304 #endif 00305 vtkObjectBase* VTKObject; 00306 } Data; 00307 00308 unsigned char Valid; 00309 unsigned char Type; 00310 00311 friend struct vtkVariantLessThan; 00312 friend struct vtkVariantEqual; 00313 friend struct vtkVariantStrictWeakOrder; 00314 friend struct vtkVariantStrictEquality; 00315 }; 00316 00317 #include "vtkVariantInlineOperators.h" // needed for operator== and company 00318 00319 // A STL-style function object so you can compare two variants using 00320 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder. 00321 // This is a faster version of operator< that makes no attempt to 00322 // compare values. It satisfies the STL requirement for a comparison 00323 // function for ordered containers like map and set. 00324 00325 struct VTK_COMMON_EXPORT vtkVariantLessThan 00326 { 00327 public: 00328 bool operator()(const vtkVariant &s1, const vtkVariant &s2) const; 00329 }; 00330 00331 struct VTK_COMMON_EXPORT vtkVariantEqual 00332 { 00333 public: 00334 bool operator()(const vtkVariant &s1, const vtkVariant &s2) const; 00335 }; 00336 00337 struct VTK_COMMON_EXPORT vtkVariantStrictWeakOrder 00338 { 00339 public: 00340 bool operator()(const vtkVariant& s1, const vtkVariant& s2) const; 00341 }; 00342 00343 // Similarly, this is a fast version of operator== that requires that 00344 // the types AND the values be equal in order to admit equality. 00345 00346 struct VTK_COMMON_EXPORT vtkVariantStrictEquality 00347 { 00348 public: 00349 bool operator()(const vtkVariant &s1, const vtkVariant &s2) const; 00350 }; 00351 00352 #endif