Loading...
Searching...
No Matches
Variant Class Reference

The Variant class represents a union of data values. More...

`#include <avogadro/core/variant.h>`

## Public Types

enum | Type { Null , Bool , Int , Long , Float , Double , Pointer , String , Vector , Matrix }

## Public Member Functions

| Variant ()
template<typename T>
| Variant (T value)
| Variant (const Variant &variant)
| Variant (double x, double y, double z)
| ~Variant ()
Type | type () const
bool | isNull () const
template<typename T>
bool | setValue (T value)
bool | setValue (double x, double y, double z)
bool | setValue (const std::vector< double > &v)
template<typename T>
T | value () const
void | clear ()
bool | toBool () const
char | toChar () const
unsigned char | toUChar () const
short | toShort () const
unsigned short | toUShort () const
int | toInt () const
unsigned int | toUInt () const
long | toLong () const
unsigned long | toULong () const
float | toFloat () const
double | toDouble () const
Real | toReal () const
void * | toPointer () const
std::string | toString () const
MatrixX | toMatrix () const
Vector3 | toVector3 () const
std::vector< double > | toList () const
const MatrixX & | toMatrixRef () const
Variant & | operator= (const Variant &variant)
template<>
| Variant (char v)
template<>
| Variant (const char *v)
template<>
| Variant (const MatrixXf &v)
template<>
| Variant (const Vector3 &v)
template<>
| Variant (const Vector3f &v)
template<>
| Variant (const std::vector< double > &v)
template<>
bool | setValue (bool v)
template<>
bool | setValue (char v)
template<>
bool | setValue (short v)
template<>
bool | setValue (int v)
template<>
bool | setValue (long v)
template<>
bool | setValue (float v)
template<>
bool | setValue (double v)
template<>
bool | setValue (std::string string)
template<>
bool | setValue (const char *string)
template<>
bool | setValue (void *pointer)
template<>
bool | setValue (MatrixX matrix)
template<>
bool | setValue (Vector3 vector)
template<>
bool | setValue (Vector3f vector)
template<>
bool | value () const
template<>
char | value () const
template<>
short | value () const
template<>
int | value () const
template<>
long | value () const
template<>
float | value () const
template<>
double | value () const
template<>
void * | value () const
template<>
std::string | value () const
template<>
MatrixX | value () const
template<>
const MatrixX & | value () const
template<>
Vector3 | value () const
template<>
const Vector3 & | value () const
template<>
std::vector< double > | value () const

## Detailed Description

Variant objects allow for the storage of and conversion between a variety of different data types.

## Constructor & Destructor Documentation

## Variant() [1/4]

Variant | ( |  | ) |

Creates a null variant.

## Variant() [2/4]

template<typename T>

Variant | ( | T | value | ) |

Creates a variant to store `value`.

## Variant() [3/4]

Variant | ( | const Variant & | variant | ) |

Creates a new copy of `variant`.

## Variant() [4/4]

Variant | ( | double | x,
|  | double | y,
|  | double | z )

Creates a variant to store a 3D vector

## ~Variant()

~Variant | ( |  | ) |

Destroys the variant object.

## Member Function Documentation

## type()

Variant::Type type | ( |  | ) | const

Returns
  variant's type.

## isNull()

bool isNull | ( |  | ) | const

Returns
  `true` if the variant is null.

## setValue() [1/3]

template<typename T>

bool setValue | ( | T | value | ) |

Sets the value of the variant to `value`.

## setValue() [2/3]

bool setValue | ( | double | x,
|  | double | y,
|  | double | z )

Sets the value of the variant to a 3D vector

## setValue() [3/3]

bool setValue | ( | const std::vector< double > & | v | ) |

Sets the value of the variant to a vector<double>

## value()

template<typename T>

T value | ( |  | ) | const

Returns
  the value of the variant in the type given by `T`.

## clear()

void clear | ( |  | ) |

Clears the variant's data and sets the variant to null.

## toBool()

bool toBool | ( |  | ) | const

Returns
  the value of the variant as a `bool`.

## toChar()

char toChar | ( |  | ) | const

Returns
  the value of the variant as a `char`.

## toUChar()

unsigned char toUChar | ( |  | ) | const

Returns
  the value of the variant as an `unsigned` `char`.

## toShort()

short toShort | ( |  | ) | const

Returns
  the value of the variant as a `short`.

## toUShort()

unsigned short toUShort | ( |  | ) | const

Returns
  the value of the variant as an `unsigned` `short`.

## toInt()

int toInt | ( |  | ) | const

Returns
  the value of the variant as an `int`.

## toUInt()

unsigned int toUInt | ( |  | ) | const

Returns
  the value of the variant as an `unsigned` `int`.

## toLong()

long toLong | ( |  | ) | const

Returns
  the value of the variant as a `long`.

## toULong()

unsigned long toULong | ( |  | ) | const

Returns
  the value of the variant as an `unsigned` `long`.

## toFloat()

float toFloat | ( |  | ) | const

Returns
  the value of the variant as a `float`.

## toDouble()

double toDouble | ( |  | ) | const

Returns
  the value of the variant as a `double`.

## toReal()

Real toReal | ( |  | ) | const

Returns
  the value of the variant as a `Real`.

## toPointer()

void * toPointer | ( |  | ) | const

Returns
  the value of the variant as a pointer.

## toString()

std::string toString | ( |  | ) | const

Returns
  the value of the variant as a string.

## toMatrix()

MatrixX toMatrix | ( |  | ) | const

Returns
  the value of the variant as a MatrixX.

## toVector3()

Vector3 toVector3 | ( |  | ) | const

Returns
  the value of the variant as a Vector3

## toList()

std::vector< double > toList | ( |  | ) | const

Returns
  the value as a vector<double>

## toMatrixRef()

const MatrixX & toMatrixRef | ( |  | ) | const

Returns
  a reference to the value of the variant as a MatrixX. This method will not perform any casting – if type() is not exactly MatrixX, the function will fail and return a reference to an empty MatrixX.

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

- variant.h
- variant-inline.h