Variant

Inherited: None

Description

Variant can contain values with common data types and return information about this types. Also Variant can convert cantained values to another data types using MetaType::convert function. Example:

Variant variant; // This variant invalid for now
variant     = Variant(true); // Now varinat contain boolean true value
variant     = Variant(42); // Now varinat contain integer 42 value
string str  = variant.toString() + " is the answer for everything"; // Now string contain string "42 is the answer for everything" value

Object based classes can be automatically registered in meta type system to be using as Variant objects. Example:

MyObject::registerClassFactory();

And then:

MyObject *origin = new MyObject;
Variant variant = Variant::fromValue(origin);
....
MyObject *object = variant.value<MyObject *>();

Public Methods

Variant ()

Variant (MetaType::Type type)

Variant (bool value)

Variant (const ByteArray & value)

Variant (const Matrix3 & value)

Variant (const Matrix4 & value)

Variant (const Quaternion & value)

Variant (const VariantList & value)

Variant (const VariantMap & value)

Variant (const Vector2 & value)

Variant (const Vector3 & value)

Variant (const Vector4 & value)

Variant (const char * value)

Variant (const std::string & value)

Variant (float value)

Variant (int value)

Variant (unsigned int value)

Variant (uint32_t type, void * copy)

Variant (const Variant & value)

template <typename T> bool

canConvert () const

bool

canConvert (uint32_t type) const

void

clear ()

void

data () const

bool

isValid () const

bool

toBool () const

const ByteArray

toByteArray () const

float

toFloat () const

int

toInt () const

const VariantList

toList () const

const VariantMap

toMap () const

const Matrix3

toMatrix3 () const

const Matrix4

toMatrix4 () const

const Quaternion

toQuaternion () const

const std::string

toString () const

const Vector2

toVector2 () const

const Vector3

toVector3 () const

const Vector4

toVector4 () const

uint32_t

type () const

uint32_t

userType () const

template <typename T> T

value () const

bool

operator!= (const Variant & right) const

Variant &

operator= (const Variant & value)

bool

operator== (const Variant & right) const

Static Methods

template <typename T> Variant

fromValue (const T & value)

Methods Description

Variant::Variant ()

Constructs an invalid variant.


Variant::Variant (MetaType::Type type)

Constructs an uninitialized variant of type.


Variant::Variant (bool value)

Constructs a new variant with a boolean value.


Variant::Variant (ByteArray & value)

Constructs a new variant with a ByteArray value.


Variant::Variant (Matrix3 & value)

Constructs a new variant with a Matrix3 value.


Variant::Variant (Matrix4 & value)

Constructs a new variant with a Matrix4 value.


Variant::Variant (Quaternion & value)

Constructs a new variant with a Quaternion value.


Variant::Variant (VariantList & value)

Constructs a new variant with a list of variants value.


Variant::Variant (VariantMap & value)

Constructs a new variant with a map of variants value.


Variant::Variant (Vector2 & value)

Constructs a new variant with a Vector2 value.


Variant::Variant (Vector3 & value)

Constructs a new variant with a Vector3 value.


Variant::Variant (Vector4 & value)

Constructs a new variant with a Vector4 value.


Variant::Variant (char * value)

Constructs a new variant with a string value.


Variant::Variant (std::string & value)

Constructs a new variant with a string value.


Variant::Variant (float value)

Constructs a new variant with a floating point value.


Variant::Variant (int value)

Constructs a new variant with an integer value.


Variant::Variant (int value)

Constructs a new variant with an integer value.


Variant::Variant (uint32_t type, void * copy)

Constructs a new variant of type and initialized with copy value.


Variant::Variant (Variant & value)

Constructs a copy of variant value.


template <typename T> bool Variant::canConvert () const

Returns the possibility of conversion for this variant to type T.

See also value and MetaType::convert.


bool Variant::canConvert (uint32_t type) const

Returns true if variant converted to a type; otherwise return false.


void Variant::clear ()

Frees used resources and make this variant an invalid.


void Variant::data () const

Returns pure pointer to value data.


template <typename T> Variant Variant::fromValue (T & value)

Returns the variant containing provided value.

Returns an invalid variant if unknown value type.

See also value, canConvert, and MetaType::convert.


bool Variant::isValid () const

Returns true if variant value is valid; otherwise return false.


bool Variant::toBool () const

Returns variant as a bool value if variant has a type MetaType::BOOLEAN. Otherwise it tries to convert existing value to a bool.

See also value, canConvert, and MetaType::convert.


const ByteArray Variant::toByteArray () const

Returns variant as a ByteArray value if variant has a type MetaType::BYTEARRAY. Otherwise it tries to convert existing value to a ByteArray.

See also value, canConvert, and MetaType::convert.


float Variant::toFloat () const

Returns variant as a float value if variant has a type MetaType::FLOAT. Otherwise it tries to convert existing value to a float.

See also value, canConvert, and MetaType::convert.


int Variant::toInt () const

Returns variant as an integer value if variant has a type MetaType::INTEGER. Otherwise it tries to convert existing value to an integer.

See also value, canConvert, and MetaType::convert.


const VariantList Variant::toList () const

Returns variant as a variant list value if variant has a type MetaType::VARIANTLIST. Otherwise it tries to convert existing value to a variant list.

See also value, canConvert, and MetaType::convert.


const VariantMap Variant::toMap () const

Returns variant as a variant map value if variant has a type MetaType::VARIANTMAP. Otherwise it tries to convert existing value to a variant map.

See also value, canConvert, and MetaType::convert.


const Matrix3 Variant::toMatrix3 () const

Returns variant as a Matrix3 value if variant has a type MetaType::MATRIX3. Otherwise it tries to convert existing value to a Matrix3.

See also value, canConvert, and MetaType::convert.


const Matrix4 Variant::toMatrix4 () const

Returns variant as a Matrix4 value if variant has a type MetaType::MATRIX4. Otherwise it tries to convert existing value to a Matrix4.

See also value, canConvert, and MetaType::convert.


const Quaternion Variant::toQuaternion () const

Returns variant as a Quaternion value if variant has a type MetaType::QUATERNION. Otherwise it tries to convert existing value to a Quaternion.

See also value, canConvert, and MetaType::convert.


const std::string Variant::toString () const

Returns variant as a string value if variant has a type MetaType::STRING. Otherwise it tries to convert existing value to a string.

See also value, canConvert, and MetaType::convert.


const Vector2 Variant::toVector2 () const

Returns variant as a Vector2 value if variant has a type MetaType::VECTOR2. Otherwise it tries to convert existing value to a Vector2.

See also value, canConvert, and MetaType::convert.


const Vector3 Variant::toVector3 () const

Returns variant as a Vector3 value if variant has a type MetaType::VECTOR3. Otherwise it tries to convert existing value to a Vector3.

See also value, canConvert, and MetaType::convert.


const Vector4 Variant::toVector4 () const

Returns variant as a Vector4 value if variant has a type MetaType::VECTOR4. Otherwise it tries to convert existing value to a Vector4.

See also value, canConvert, and MetaType::convert.


uint32_t Variant::type () const

Returns type of variant value.

Note: If type of variant is user defined then fonction return MetaType::USERTYPE. To get the real type id use userType.

See also userType.


uint32_t Variant::userType () const

Returns user type of variant value.

See also type.


template <typename T> T Variant::value () const

Returns contained value which cast or converted to type T.

Returns default T value if invalid variant or variant can not be converted to type T.

See also fromValue, canConvert, and MetaType::convert.


bool Variant::operator!= (Variant & right) const

Compares a this variant with variant right value. Returns true if variants are NOT equal; otherwise returns false.


Variant & Variant::operator= (Variant & value)

Assigns the value of the variant to this variant.


bool Variant::operator== (Variant & right) const

Compares a this variant with variant right value. Returns true if variants are equal; otherwise returns false.