Variant Class Reference

Tagged union for holding values. More...

#include <variant.h>

List of all members.


union  Data

Public Types

enum  Type {
  valuelessType = 0x00, undefinedType = 0x00, nullType = 0x04, numericalType = 0x01,
  integerType = 0x05, unsignedIntegerType = 0x01, floatingType = 0x09, stringType = 0x02,
  objectType = 0x03
enum  Display { decimal = 0x00, binary = 0x10, octal = 0x20, hexadecimal = 0x30 }

Public Member Functions

 Variant ()
 Variant (const Variant &other)
 Variant (bool l)
 Variant (char l)
 Variant (int l)
 Variant (long l)
 Variant (long long l)
 Variant (unsigned char ul)
 Variant (unsigned int ul)
 Variant (unsigned long ul)
 Variant (unsigned long long ul)
 Variant (float f)
 Variant (double f)
 Variant (const std::string &s)
 Variant (const char *s)
 Variant (const ObjectType &t)
 ~Variant ()
void setValue (Variant other)
void setValue (bool l)
void setValue (char l)
void setValue (int l)
void setValue (long l)
void setValue (long long l)
void setValue (unsigned char ul)
void setValue (unsigned int ul)
void setValue (unsigned long ul)
void setValue (unsigned long long ul)
void setValue (float f)
void setValue (double f)
void setValue (const std::string &s)
void setValue (const char *s)
void setValue (const ObjectType &t)
void clear ()
Variantoperator= (Variant other)
bool canConvertTo (Type otherType) const
VariantconvertTo (Type newType)
long long toInteger () const
unsigned long long toUnsignedInteger () const
double toDouble () const
const std::string & toString () const
const ObjectTypetoObjectType () const
ObjectTypetoObjectType ()
bool toBool () const
Type type () const
bool hasNumericalType () const
bool isValueless () const
bool isNull () const
bool isUndefined () const
Variantoperator+= (const Variant &other)
Variantoperator-= (const Variant &other)
Variantoperator*= (const Variant &other)
Variantoperator/= (const Variant &other)
Variantoperator%= (const Variant &other)
Variantoperator++ ()
Variant operator++ (int)
Variantoperator-- ()
Variant operator-- (int)
Variant operator- () const
Variantoperator|= (const Variant &other)
Variantoperator^= (const Variant &other)
Variantoperator&= (const Variant &other)
Variantoperator<<= (const Variant &other)
Variantoperator>>= (const Variant &other)
Variant operator~ () const
bool operator! () const
void setDisplayType (Display display)
std::ostream & display (std::ostream &out, bool setFlags=true) const

Static Public Member Functions

static Variant null ()


void swap (Variant &a, Variant &b)
bool operator== (const Variant &a, const Variant &b)
bool operator< (const Variant &a, const Variant &b)
bool operator<= (const Variant &a, const Variant &b)

Detailed Description

Tagged union for holding values.

Can hold: 64 bits signed integers (integer), 64 bits unsigned integers (unsignedInteger), 64 bits floating points (floating), strings (string) and object types (objectType). By default the variant's value is not defined and the type is unknown, in which case most operations will fail, and the value is value is null.

Explicit conversion are allowed in some cases : you can check if a conversion is possible using canConvertTo and then convert the internal value using convertTo.

Most usual operators have been overloaded and behave as exepected is c/c++

Member Enumeration Documentation


Default supertype.


Undefined variant.


Defined variant with no value.


Internal supertype for integer, unsigned integer and floating.


64 bits signed integer, conversion with other numerical types possible (ie unsignedInteger and floating)


64 bits unsigned integer, conversion with other numerical types possible (ie integer and floating)


64 bits floating point, conversion with other numerical types possible (ie integer and unsignedInteger)


std::string, no conversion possible


Objectype, no conversion possible.

Constructor & Destructor Documentation

Variant::Variant ( const Variant other)
Variant::Variant ( bool  l)
Variant::Variant ( char  l)
Variant::Variant ( int  l)
Variant::Variant ( long  l)
Variant::Variant ( long long  l)
Variant::Variant ( unsigned char  ul)
Variant::Variant ( unsigned int  ul)
Variant::Variant ( unsigned long  ul)
Variant::Variant ( unsigned long long  ul)
Variant::Variant ( float  f)
Variant::Variant ( double  f)
Variant::Variant ( const std::string &  s)
Variant::Variant ( const char *  s)
Variant::Variant ( const ObjectType t)

Member Function Documentation

bool Variant::canConvertTo ( Type  otherType) const
void Variant::clear ( )
std::ostream& Variant::display ( std::ostream &  out,
bool  setFlags = true 
) const
bool Variant::hasNumericalType ( ) const
bool Variant::isNull ( ) const
bool Variant::isUndefined ( ) const
bool Variant::isValueless ( ) const
static Variant Variant::null ( ) [static]
bool Variant::operator! ( ) const
Variant& Variant::operator%= ( const Variant other)
Variant& Variant::operator&= ( const Variant other)
Variant& Variant::operator*= ( const Variant other)
Variant& Variant::operator++ ( )
Variant Variant::operator++ ( int  )
Variant& Variant::operator+= ( const Variant other)
Variant Variant::operator- ( ) const
Variant& Variant::operator-- ( )
Variant Variant::operator-- ( int  )
Variant& Variant::operator-= ( const Variant other)
Variant& Variant::operator/= ( const Variant other)
Variant& Variant::operator<<= ( const Variant other)
Variant& Variant::operator= ( Variant  other)
Variant& Variant::operator>>= ( const Variant other)
Variant& Variant::operator^= ( const Variant other)
Variant& Variant::operator|= ( const Variant other)
void Variant::setDisplayType ( Display  display)
void Variant::setValue ( Variant  other)
void Variant::setValue ( bool  l)
void Variant::setValue ( char  l)
void Variant::setValue ( int  l)
void Variant::setValue ( long  l)
void Variant::setValue ( long long  l)
void Variant::setValue ( unsigned char  ul)
void Variant::setValue ( unsigned int  ul)
void Variant::setValue ( unsigned long  ul)
void Variant::setValue ( unsigned long long  ul)
void Variant::setValue ( float  f)
void Variant::setValue ( double  f)
void Variant::setValue ( const std::string &  s)
void Variant::setValue ( const char *  s)
void Variant::setValue ( const ObjectType t)
bool Variant::toBool ( ) const
double Variant::toDouble ( ) const
long long Variant::toInteger ( ) const
const std::string& Variant::toString ( ) const
unsigned long long Variant::toUnsignedInteger ( ) const
Type Variant::type ( ) const

Friends And Related Function Documentation

bool operator< ( const Variant a,
const Variant b 
) [friend]
bool operator<= ( const Variant a,
const Variant b 
) [friend]
bool operator== ( const Variant a,
const Variant b 
) [friend]
void swap ( Variant a,
Variant b 
) [friend]

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