VTK
Public Member Functions | Friends
vtkVariant Class Reference

A atomic type representing the union of many types. More...

#include <vtkVariant.h>

Collaboration diagram for vtkVariant:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 vtkVariant ()
 ~vtkVariant ()
 vtkVariant (const vtkVariant &other)
 vtkVariant (bool value)
 vtkVariant (char value)
 vtkVariant (unsigned char value)
 vtkVariant (signed char value)
 vtkVariant (short value)
 vtkVariant (unsigned short value)
 vtkVariant (int value)
 vtkVariant (unsigned int value)
 vtkVariant (long value)
 vtkVariant (unsigned long value)
 vtkVariant (float value)
 vtkVariant (double value)
 vtkVariant (const char *value)
 vtkVariant (vtkStdString value)
 vtkVariant (const vtkUnicodeString &value)
 vtkVariant (vtkObjectBase *value)
 vtkVariant (const vtkVariant &other, unsigned int type)
const vtkVariantoperator= (const vtkVariant &other)
bool IsValid () const
bool IsString () const
bool IsUnicodeString () const
bool IsNumeric () const
bool IsFloat () const
bool IsDouble () const
bool IsChar () const
bool IsUnsignedChar () const
bool IsSignedChar () const
bool IsShort () const
bool IsUnsignedShort () const
bool IsInt () const
bool IsUnsignedInt () const
bool IsLong () const
bool IsUnsignedLong () const
bool Is__Int64 () const
bool IsUnsigned__Int64 () const
bool IsLongLong () const
bool IsUnsignedLongLong () const
bool IsVTKObject () const
bool IsArray () const
unsigned int GetType () const
const char * GetTypeAsString () const
vtkStdString ToString () const
vtkUnicodeString ToUnicodeString () const
vtkObjectBaseToVTKObject () const
vtkAbstractArrayToArray () const
bool IsEqual (const vtkVariant &other) const
float ToFloat (bool *valid) const
float ToFloat () const
double ToDouble (bool *valid) const
double ToDouble () const
char ToChar (bool *valid) const
char ToChar () const
unsigned char ToUnsignedChar (bool *valid) const
unsigned char ToUnsignedChar () const
signed char ToSignedChar (bool *valid) const
signed char ToSignedChar () const
short ToShort (bool *valid) const
short ToShort () const
unsigned short ToUnsignedShort (bool *valid) const
unsigned short ToUnsignedShort () const
int ToInt (bool *valid) const
int ToInt () const
unsigned int ToUnsignedInt (bool *valid) const
unsigned int ToUnsignedInt () const
long ToLong (bool *valid) const
long ToLong () const
unsigned long ToUnsignedLong (bool *valid) const
unsigned long ToUnsignedLong () const
vtkTypeInt64 ToTypeInt64 (bool *valid) const
vtkTypeInt64 ToTypeInt64 () const
vtkTypeUInt64 ToTypeUInt64 (bool *valid) const
vtkTypeUInt64 ToTypeUInt64 () const
bool operator== (const vtkVariant &other) const
bool operator!= (const vtkVariant &other) const
bool operator< (const vtkVariant &other) const
bool operator> (const vtkVariant &other) const
bool operator<= (const vtkVariant &other) const
bool operator>= (const vtkVariant &other) const

Friends

struct vtkVariantLessThan
struct vtkVariantEqual
struct vtkVariantStrictWeakOrder
struct vtkVariantStrictEquality
VTKCOMMONCORE_EXPORT ostream & operator<< (ostream &os, const vtkVariant &val)

Detailed Description

A atomic type representing the union of many types.

Thanks:
Thanks to Patricia Crossno, Ken Moreland, Andrew Wilson and Brian Wylie from Sandia National Laboratories for their help in developing this class.
Examples:
vtkVariant (Examples)
Tests:
vtkVariant (Tests)

Definition at line 78 of file vtkVariant.h.


Constructor & Destructor Documentation

Create an invalid variant.

Destruct the variant.

vtkVariant::vtkVariant ( const vtkVariant other)

Copy constructor.

vtkVariant::vtkVariant ( bool  value)

Create a bool variant. Internally store it as char.

vtkVariant::vtkVariant ( char  value)

Create a char variant.

vtkVariant::vtkVariant ( unsigned char  value)

Create an unsigned char variant.

vtkVariant::vtkVariant ( signed char  value)

Create a signed char variant.

vtkVariant::vtkVariant ( short  value)

Create a short variant.

vtkVariant::vtkVariant ( unsigned short  value)

Create an unsigned short variant.

Create an integer variant.

vtkVariant::vtkVariant ( unsigned int  value)

Create an unsigned integer variant.

vtkVariant::vtkVariant ( long  value)

Create an long variant.

vtkVariant::vtkVariant ( unsigned long  value)

Create an unsigned long variant.

Create a float variant.

Create a double variant.

vtkVariant::vtkVariant ( const char *  value)

Create a string variant from a const char*.

Create a string variant from a std string.

Create a Unicode string variant

Create a vtkObjectBase variant.

vtkVariant::vtkVariant ( const vtkVariant other,
unsigned int  type 
)

Create a variant of a specific type.


Member Function Documentation

const vtkVariant& vtkVariant::operator= ( const vtkVariant other)

Copy the value of one variant into another.

bool vtkVariant::IsValid ( ) const

Get whether the variant value is valid.

bool vtkVariant::IsString ( ) const

Get whether the variant is a string.

Get whether the variant is a Unicode string.

bool vtkVariant::IsNumeric ( ) const

Get whether the variant is any numeric type.

bool vtkVariant::IsFloat ( ) const

Get whether the variant is a float.

bool vtkVariant::IsDouble ( ) const

Get whether the variant is a double.

bool vtkVariant::IsChar ( ) const

Get whether the variant is an char.

Get whether the variant is an unsigned char.

bool vtkVariant::IsSignedChar ( ) const

Get whether the variant is an signed char.

bool vtkVariant::IsShort ( ) const

Get whether the variant is an short.

Get whether the variant is an unsigned short.

bool vtkVariant::IsInt ( ) const

Get whether the variant is an int.

bool vtkVariant::IsUnsignedInt ( ) const

Get whether the variant is an unsigned int.

bool vtkVariant::IsLong ( ) const

Get whether the variant is an long.

Get whether the variant is an unsigned long.

bool vtkVariant::Is__Int64 ( ) const

Get whether the variant is an __int64.

Get whether the variant is an unsigned __int64.

bool vtkVariant::IsLongLong ( ) const

Get whether the variant is long long.

Get whether the variant is unsigned long long.

bool vtkVariant::IsVTKObject ( ) const

Get whether the variant is a VTK object pointer.

bool vtkVariant::IsArray ( ) const

Get whether the variant is a VTK array (i.e. a subclass of vtkAbstractArray).

unsigned int vtkVariant::GetType ( ) const

Get the type of the variant.

const char* vtkVariant::GetTypeAsString ( ) const

Get the type of the variant as a string.

Convert the variant to a string.

convert the variant to a Unicode string.

float vtkVariant::ToFloat ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

float vtkVariant::ToFloat ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 248 of file vtkVariant.h.

double vtkVariant::ToDouble ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

double vtkVariant::ToDouble ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 251 of file vtkVariant.h.

char vtkVariant::ToChar ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

char vtkVariant::ToChar ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 254 of file vtkVariant.h.

unsigned char vtkVariant::ToUnsignedChar ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

unsigned char vtkVariant::ToUnsignedChar ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 257 of file vtkVariant.h.

signed char vtkVariant::ToSignedChar ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

signed char vtkVariant::ToSignedChar ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 260 of file vtkVariant.h.

short vtkVariant::ToShort ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

short vtkVariant::ToShort ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 263 of file vtkVariant.h.

unsigned short vtkVariant::ToUnsignedShort ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

unsigned short vtkVariant::ToUnsignedShort ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 266 of file vtkVariant.h.

int vtkVariant::ToInt ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

int vtkVariant::ToInt ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 269 of file vtkVariant.h.

unsigned int vtkVariant::ToUnsignedInt ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

unsigned int vtkVariant::ToUnsignedInt ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 272 of file vtkVariant.h.

long vtkVariant::ToLong ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

long vtkVariant::ToLong ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 275 of file vtkVariant.h.

unsigned long vtkVariant::ToUnsignedLong ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

unsigned long vtkVariant::ToUnsignedLong ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 278 of file vtkVariant.h.

vtkTypeInt64 vtkVariant::ToTypeInt64 ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

vtkTypeInt64 vtkVariant::ToTypeInt64 ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 297 of file vtkVariant.h.

vtkTypeUInt64 vtkVariant::ToTypeUInt64 ( bool *  valid) const

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

vtkTypeUInt64 vtkVariant::ToTypeUInt64 ( ) const [inline]

Convert the variant to a numeric type: If it holds a numeric, cast to the appropriate type. If it holds a string, attempt to convert the string to the appropriate type; set the valid flag to false when the conversion fails. If it holds an array type, cast the first value of the array to the appropriate type. Fail if it holds a VTK object which is not an array.

Definition at line 300 of file vtkVariant.h.

Return the VTK object, or NULL if not of that type.

Return the array, or NULL if not of that type.

bool vtkVariant::IsEqual ( const vtkVariant other) const

Determines whether two variants have the same value. They do not need to be storing exactly the same type to have the same value. In practice you don't need to use this method: just use operator== instead. If you want precise equality down to the bit level use the following idiom: vtkVariantStrictEquality comparator; bool variantsEqual = comparator(firstVariant, secondVariant);

bool vtkVariant::operator== ( const vtkVariant other) const [inline]

Compare two variants for equality, greater than, and less than. These operators use the value represented by the variant instead of the particular type/bit pattern used to represent it. This behavior is similar to the default behavior in C and C++, including type promotion, with the following caveats: * When comparing type X with a string, type X will first be converted to string, then compared lexically (the usual behavior of string::operator< and company). * vtkObject pointers will be converted to an unsigned integer of appropriate size. If both variants contain vtkObjects then they are comparable directly. * Comparing char values with strings will not work the way you might expect if you're treating a char as a numeric type. Char values are written to strings as literal ASCII characters instead of numbers. This approach follows the principle of least surprise at the expense of speed. Casting integers to floating-point values is relatively slow. Casting numeric types to strings is very slow. If you prefer speed at the expense of counterintuitive behavior -- for example, when using vtkVariants as keys in STL containers -- you can use the functors described at the bottom of this file. The actual definitions of these operators are in vtkVariantInlineOperators.cxx.

Definition at line 114 of file vtkVariantInlineOperators.h.

bool vtkVariant::operator!= ( const vtkVariant other) const [inline]

Compare two variants for equality, greater than, and less than. These operators use the value represented by the variant instead of the particular type/bit pattern used to represent it. This behavior is similar to the default behavior in C and C++, including type promotion, with the following caveats: * When comparing type X with a string, type X will first be converted to string, then compared lexically (the usual behavior of string::operator< and company). * vtkObject pointers will be converted to an unsigned integer of appropriate size. If both variants contain vtkObjects then they are comparable directly. * Comparing char values with strings will not work the way you might expect if you're treating a char as a numeric type. Char values are written to strings as literal ASCII characters instead of numbers. This approach follows the principle of least surprise at the expense of speed. Casting integers to floating-point values is relatively slow. Casting numeric types to strings is very slow. If you prefer speed at the expense of counterintuitive behavior -- for example, when using vtkVariants as keys in STL containers -- you can use the functors described at the bottom of this file. The actual definitions of these operators are in vtkVariantInlineOperators.cxx.

Definition at line 282 of file vtkVariantInlineOperators.h.

bool vtkVariant::operator< ( const vtkVariant other) const [inline]

Compare two variants for equality, greater than, and less than. These operators use the value represented by the variant instead of the particular type/bit pattern used to represent it. This behavior is similar to the default behavior in C and C++, including type promotion, with the following caveats: * When comparing type X with a string, type X will first be converted to string, then compared lexically (the usual behavior of string::operator< and company). * vtkObject pointers will be converted to an unsigned integer of appropriate size. If both variants contain vtkObjects then they are comparable directly. * Comparing char values with strings will not work the way you might expect if you're treating a char as a numeric type. Char values are written to strings as literal ASCII characters instead of numbers. This approach follows the principle of least surprise at the expense of speed. Casting integers to floating-point values is relatively slow. Casting numeric types to strings is very slow. If you prefer speed at the expense of counterintuitive behavior -- for example, when using vtkVariants as keys in STL containers -- you can use the functors described at the bottom of this file. The actual definitions of these operators are in vtkVariantInlineOperators.cxx.

Definition at line 194 of file vtkVariantInlineOperators.h.

bool vtkVariant::operator> ( const vtkVariant other) const [inline]

Compare two variants for equality, greater than, and less than. These operators use the value represented by the variant instead of the particular type/bit pattern used to represent it. This behavior is similar to the default behavior in C and C++, including type promotion, with the following caveats: * When comparing type X with a string, type X will first be converted to string, then compared lexically (the usual behavior of string::operator< and company). * vtkObject pointers will be converted to an unsigned integer of appropriate size. If both variants contain vtkObjects then they are comparable directly. * Comparing char values with strings will not work the way you might expect if you're treating a char as a numeric type. Char values are written to strings as literal ASCII characters instead of numbers. This approach follows the principle of least surprise at the expense of speed. Casting integers to floating-point values is relatively slow. Casting numeric types to strings is very slow. If you prefer speed at the expense of counterintuitive behavior -- for example, when using vtkVariants as keys in STL containers -- you can use the functors described at the bottom of this file. The actual definitions of these operators are in vtkVariantInlineOperators.cxx.

Definition at line 288 of file vtkVariantInlineOperators.h.

bool vtkVariant::operator<= ( const vtkVariant other) const [inline]

Compare two variants for equality, greater than, and less than. These operators use the value represented by the variant instead of the particular type/bit pattern used to represent it. This behavior is similar to the default behavior in C and C++, including type promotion, with the following caveats: * When comparing type X with a string, type X will first be converted to string, then compared lexically (the usual behavior of string::operator< and company). * vtkObject pointers will be converted to an unsigned integer of appropriate size. If both variants contain vtkObjects then they are comparable directly. * Comparing char values with strings will not work the way you might expect if you're treating a char as a numeric type. Char values are written to strings as literal ASCII characters instead of numbers. This approach follows the principle of least surprise at the expense of speed. Casting integers to floating-point values is relatively slow. Casting numeric types to strings is very slow. If you prefer speed at the expense of counterintuitive behavior -- for example, when using vtkVariants as keys in STL containers -- you can use the functors described at the bottom of this file. The actual definitions of these operators are in vtkVariantInlineOperators.cxx.

Definition at line 295 of file vtkVariantInlineOperators.h.

bool vtkVariant::operator>= ( const vtkVariant other) const [inline]

Compare two variants for equality, greater than, and less than. These operators use the value represented by the variant instead of the particular type/bit pattern used to represent it. This behavior is similar to the default behavior in C and C++, including type promotion, with the following caveats: * When comparing type X with a string, type X will first be converted to string, then compared lexically (the usual behavior of string::operator< and company). * vtkObject pointers will be converted to an unsigned integer of appropriate size. If both variants contain vtkObjects then they are comparable directly. * Comparing char values with strings will not work the way you might expect if you're treating a char as a numeric type. Char values are written to strings as literal ASCII characters instead of numbers. This approach follows the principle of least surprise at the expense of speed. Casting integers to floating-point values is relatively slow. Casting numeric types to strings is very slow. If you prefer speed at the expense of counterintuitive behavior -- for example, when using vtkVariants as keys in STL containers -- you can use the functors described at the bottom of this file. The actual definitions of these operators are in vtkVariantInlineOperators.cxx.

Definition at line 302 of file vtkVariantInlineOperators.h.


Friends And Related Function Documentation

friend struct vtkVariantLessThan [friend]

Definition at line 385 of file vtkVariant.h.

friend struct vtkVariantEqual [friend]

Definition at line 386 of file vtkVariant.h.

friend struct vtkVariantStrictWeakOrder [friend]

Definition at line 387 of file vtkVariant.h.

friend struct vtkVariantStrictEquality [friend]

Definition at line 388 of file vtkVariant.h.

VTKCOMMONCORE_EXPORT ostream& operator<< ( ostream &  os,
const vtkVariant val 
) [friend]

Member Data Documentation

Definition at line 358 of file vtkVariant.h.

Definition at line 359 of file vtkVariant.h.

Definition at line 360 of file vtkVariant.h.

Definition at line 361 of file vtkVariant.h.

Definition at line 362 of file vtkVariant.h.

unsigned char vtkVariant::UnsignedChar

Definition at line 363 of file vtkVariant.h.

Definition at line 364 of file vtkVariant.h.

Definition at line 365 of file vtkVariant.h.

unsigned short vtkVariant::UnsignedShort

Definition at line 366 of file vtkVariant.h.

Definition at line 367 of file vtkVariant.h.

Definition at line 368 of file vtkVariant.h.

Definition at line 369 of file vtkVariant.h.

unsigned long vtkVariant::UnsignedLong

Definition at line 370 of file vtkVariant.h.

Definition at line 379 of file vtkVariant.h.


The documentation for this class was generated from the following files: