AvogadroLibs  1.96.0
Public Types | Public Member Functions | List of all members
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 ,
  Matrix
}
 

Public Member Functions

 Variant ()
 
template<typename T >
 Variant (T value)
 
 Variant (const Variant &variant)
 
 ~Variant ()
 
Type type () const
 
bool isNull () const
 
template<typename T >
bool setValue (T value)
 
template<typename 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
 
const MatrixX & toMatrixRef () const
 
Variantoperator= (const Variant &variant)
 
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 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/3]

Variant ( )

Creates a null variant.

◆ Variant() [2/3]

Variant ( value)

Creates a variant to store value.

◆ Variant() [3/3]

Variant ( const Variant variant)

Creates a new copy of variant.

◆ ~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()

bool setValue ( value)

Sets the value of the variant to value.

◆ value()

T value

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.

◆ 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: