VTK
dox/Common/vtkVariant.h
Go to the documentation of this file.
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   // Description:
00125   // Create a long long variant.
00126   vtkVariant(long long value);
00128 
00130 
00131   vtkVariant(unsigned long long value);
00132 #endif
00133 
00134 
00136   vtkVariant(float value);
00137 
00139   vtkVariant(double value);
00140 
00142   vtkVariant(const char* value);
00143 
00145   vtkVariant(vtkStdString value);
00146 
00148   vtkVariant(const vtkUnicodeString& value);
00149 
00151   vtkVariant(vtkObjectBase* value);
00152 
00154   vtkVariant(const vtkVariant &other, unsigned int type);
00155 
00157   const vtkVariant & operator= (const vtkVariant & other);
00158 
00160   bool IsValid() const;
00161 
00163   bool IsString() const;
00164 
00166   bool IsUnicodeString() const;
00167 
00169   bool IsNumeric() const;
00170 
00172   bool IsFloat() const;
00173 
00175   bool IsDouble() const;
00176 
00178   bool IsChar() const;
00179 
00181   bool IsUnsignedChar() const;
00182 
00184   bool IsSignedChar() const;
00185 
00187   bool IsShort() const;
00188 
00190   bool IsUnsignedShort() const;
00191 
00193   bool IsInt() const;
00194 
00196   bool IsUnsignedInt() const;
00197 
00199   bool IsLong() const;
00200 
00202   bool IsUnsignedLong() const;
00203 
00205   bool Is__Int64() const;
00206 
00208   bool IsUnsigned__Int64() const;
00209 
00211   bool IsLongLong() const;
00212 
00214   bool IsUnsignedLongLong() const;
00215 
00217   bool IsVTKObject() const;
00218 
00221   bool IsArray() const;
00222 
00224   unsigned int GetType() const;
00225 
00227   const char* GetTypeAsString() const;
00228 
00230   vtkStdString ToString() const;
00231 
00233   vtkUnicodeString ToUnicodeString() const;
00234 
00236 
00242   float ToFloat(bool *valid) const;
00243   float ToFloat() const {
00244     return this->ToFloat(0); };
00245   double ToDouble(bool *valid) const;
00246   double ToDouble() const {
00247     return this->ToDouble(0); };
00248   char ToChar(bool *valid) const;
00249   char ToChar() const {
00250     return this->ToChar(0); };
00251   unsigned char ToUnsignedChar(bool *valid) const;
00252   unsigned char ToUnsignedChar() const {
00253     return this->ToUnsignedChar(0); };
00254   signed char ToSignedChar(bool *valid) const;
00255   signed char ToSignedChar() const {
00256     return this->ToSignedChar(0); };
00257   short ToShort(bool *valid) const;
00258   short ToShort() const {
00259     return this->ToShort(0); };
00260   unsigned short ToUnsignedShort(bool *valid) const;
00261   unsigned short ToUnsignedShort() const {
00262     return this->ToUnsignedShort(0); };
00263   int ToInt(bool *valid) const;
00264   int ToInt() const {
00265     return this->ToInt(0); };
00266   unsigned int ToUnsignedInt(bool *valid) const;
00267   unsigned int ToUnsignedInt() const {
00268     return this->ToUnsignedInt(0); };
00269   long ToLong(bool *valid) const;
00270   long ToLong() const {
00271     return this->ToLong(0); };
00272   unsigned long ToUnsignedLong(bool *valid) const;
00273   unsigned long ToUnsignedLong() const {
00274     return this->ToUnsignedLong(0); };
00275 #if defined(VTK_TYPE_USE___INT64)
00276   __int64 To__Int64(bool *valid) const;
00277   __int64 To__Int64() const {
00278     return this->To__Int64(0); };
00279   unsigned __int64 ToUnsigned__Int64(bool *valid) const;
00280   unsigned __int64 ToUnsigned__Int64() const {
00281     return this->ToUnsigned__Int64(0); };
00282 #endif
00283 #if defined(VTK_TYPE_USE_LONG_LONG)
00284   long long ToLongLong(bool *valid) const;
00285   long long ToLongLong() const {
00286     return this->ToLongLong(0); };
00287   unsigned long long ToUnsignedLongLong(bool *valid) const;
00288   unsigned long long ToUnsignedLongLong() const {
00289     return this->ToUnsignedLongLong(0); };
00290 #endif
00291   vtkTypeInt64 ToTypeInt64(bool *valid) const;
00292   vtkTypeInt64 ToTypeInt64() const {
00293     return this->ToTypeInt64(0); };
00294   vtkTypeUInt64 ToTypeUInt64(bool *valid) const;
00295   vtkTypeUInt64 ToTypeUInt64() const {
00296     return this->ToTypeUInt64(0); };
00298 
00300   vtkObjectBase* ToVTKObject() const;
00301 
00303   vtkAbstractArray* ToArray() const;
00304 
00305 //BTX
00306   template <typename T>
00307   T ToNumeric(bool *valid, T* vtkNotUsed(ignored)) const;
00308 //ETX
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 VTK_COMMON_EXPORT ostream& operator << ( ostream& os, const vtkVariant& val );
00349 //ETX
00350 
00351 private:
00352 //BTX
00353   union
00354   {
00355     vtkStdString* String;
00356     vtkUnicodeString* UnicodeString;
00357     float Float;
00358     double Double;
00359     char Char;
00360     unsigned char UnsignedChar;
00361     signed char SignedChar;
00362     short Short;
00363     unsigned short UnsignedShort;
00364     int Int;
00365     unsigned int UnsignedInt;
00366     long Long;
00367     unsigned long UnsignedLong;
00368 #if defined(VTK_TYPE_USE___INT64)
00369     __int64 __Int64;
00370     unsigned __int64 Unsigned__Int64;
00371 #endif
00372 #if defined(VTK_TYPE_USE_LONG_LONG)
00373     long long LongLong;
00374     unsigned long long UnsignedLongLong;
00375 #endif
00376     vtkObjectBase* VTKObject;
00377   } Data;
00378 
00379   unsigned char Valid;
00380   unsigned char Type;
00381 
00382   friend struct vtkVariantLessThan;
00383   friend struct vtkVariantEqual;
00384   friend struct vtkVariantStrictWeakOrder;
00385   friend struct vtkVariantStrictEquality;
00386 //ETX
00387 };
00388 
00389 //BTX
00390 
00391 #include "vtkVariantInlineOperators.h" // needed for operator== and company
00392 
00393 // A STL-style function object so you can compare two variants using
00394 // comp(s1,s2) where comp is an instance of vtkVariantStrictWeakOrder.
00395 // This is a faster version of operator< that makes no attempt to
00396 // compare values.  It satisfies the STL requirement for a comparison
00397 // function for ordered containers like map and set.
00398 
00399 struct VTK_COMMON_EXPORT vtkVariantLessThan
00400 {
00401 public:
00402   bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
00403 };
00404 
00405 struct VTK_COMMON_EXPORT vtkVariantEqual
00406 {
00407 public:
00408   bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
00409 };
00410 
00411 struct VTK_COMMON_EXPORT vtkVariantStrictWeakOrder
00412 {
00413 public:
00414   bool operator()(const vtkVariant& s1, const vtkVariant& s2) const;
00415 };
00416 
00417 // Similarly, this is a fast version of operator== that requires that
00418 // the types AND the values be equal in order to admit equality.
00419 
00420 struct VTK_COMMON_EXPORT vtkVariantStrictEquality
00421 {
00422 public:
00423   bool operator()(const vtkVariant &s1, const vtkVariant &s2) const;
00424 };
00425 
00426 //ETX
00427 
00428 #endif