You.i Engine
CYIVariant Class Reference

Detailed Description

A container class for common data types.

This class is used to hold primitive or class types while providing type information. Functions are also provided to convert between types. The following types are supported:

  • Float
  • Arrays of Floats
  • Float vectors with 2 items (std::vec2)
  • Float vectors with 3 items (std::vec3)
  • Integer (32 bit)
  • Arrays of Integers (32 bit)
  • Quaternions (glm::quat)
  • String
Note
Some types cannot be converted to all possible types. Similarly, some functions are only available on variants of specific types.
See also
CYIAny

#include <animation/YiVariant.h>

Public Types

enum  Type : uint8_t {
  Type::Invalid,
  Type::Float,
  Type::FloatArray,
  Type::FloatVec2,
  Type::FloatVec3,
  Type::Integer,
  Type::IntegerArray,
  Type::Quaternion,
  Type::String
}
 

Public Member Functions

 CYIVariant ()=default
 
 CYIVariant (float value)
 
 CYIVariant (const float pValue[], uint32_t count)
 
 CYIVariant (std::vector< float > values)
 
 CYIVariant (const glm::vec2 &rvValue)
 
 CYIVariant (float x, float y)
 
 CYIVariant (const glm::vec3 &rvValue)
 
 CYIVariant (float x, float y, float z)
 
 CYIVariant (int32_t value)
 
 CYIVariant (const int32_t pValue[], uint32_t count)
 
 CYIVariant (std::vector< int32_t > values)
 
 CYIVariant (const glm::quat &rValue)
 
 CYIVariant (const CYIString &rsValue)
 
void Set (float value)
 
void Set (const float pValue[], uint32_t count)
 
void Set (std::vector< float > values)
 
void Set (const glm::vec2 &rvValue)
 
void Set (float x, float y)
 
void Set (const glm::vec3 &rvValue)
 
void Set (float x, float y, float z)
 
void Set (int32_t value)
 
void Set (const int32_t pValue[], uint32_t count)
 
void Set (std::vector< int32_t > values)
 
void Set (const glm::quat &rValue)
 
void Set (const CYIString &rsValue)
 
void SetInvalid ()
 
float GetAsFloat () const
 
const float * GetAsFloatPointer (size_t *pSize=nullptr) const
 
glm::vec2 GetAsFloatVec2 () const
 
glm::vec3 GetAsFloatVec3 () const
 
int32_t GetAsInt () const
 
const int32_t * GetAsIntPointer (size_t *pSize=nullptr) const
 
glm::quat GetAsQuaternion () const
 
CYIString GetAsString () const
 
bool IsValid () const
 
Type GetType () const
 
bool operator+= (const CYIVariant &rOther)
 Supported types: Int, String, Float, FloatVec2, FloatVec3, FloatArray and IntArray. More...
 
bool operator-= (const CYIVariant &rOther)
 Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray. More...
 
bool operator*= (const CYIVariant &rOther)
 Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray. More...
 
bool operator/= (const CYIVariant &rOther)
 Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray. More...
 
CYIVariant operator+ (const CYIVariant &rOther) const
 Supported types: Int, String, Float, FloatVec2, FloatVec3, FloatArray and IntArray. More...
 
CYIVariant operator- (const CYIVariant &rOther) const
 Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray. More...
 
CYIVariant operator* (const CYIVariant &rOther) const
 Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray. More...
 
CYIVariant operator/ (const CYIVariant &rOther) const
 Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray. More...
 
CYIVariant LogOf () const
 
CYIVariant ExpOf () const
 
size_t GetApproximateSize () const
 

Static Public Member Functions

static void Lerp (const CYIVariant &start, const CYIVariant &end, float *pPercentages, size_t percentageCount, CYIVariant &out_variant)
 

Friends

bool operator== (const CYIVariant &rLHS, const CYIVariant &rRHS)
 All types are supported. Two 'invalid' variants are considered to be equal. More...
 
bool operator!= (const CYIVariant &rLHS, const CYIVariant &rRHS)
 All types are supported. Two 'invalid' variants are considered to be equal. More...
 

Member Enumeration Documentation

◆ Type

enum CYIVariant::Type : uint8_t
strong

The type of data contained in this variant. By default, empty variant objects have a type of Invalid.

Enumerator
Invalid 

No type.

Float 

Single-precision floating-point

FloatArray 

Array of single-precision floating-point values

FloatVec2 

Vector of single-precision floating-point values (glm::vec2)

FloatVec3 

Vector of single-precision floating-point values (glm::vec3)

Integer 

Integer (32 bit)

IntegerArray 

Array of integers (32 bit)

Quaternion 

Quaternion (glm::quat)

String 

String

Constructor & Destructor Documentation

◆ CYIVariant() [1/13]

CYIVariant::CYIVariant ( )
default

Creates an empty variant. The type of the variant is set to Invalid.

◆ CYIVariant() [2/13]

CYIVariant::CYIVariant ( float  value)

Creates a variant from the floating-point value value. The type of the variant is set to Float.

◆ CYIVariant() [3/13]

CYIVariant::CYIVariant ( const float  pValue[],
uint32_t  count 
)

Creates a variant from the floating-point values contained in pValue, copying exactly count values. The type of the variant is set to FloatArray.

◆ CYIVariant() [4/13]

CYIVariant::CYIVariant ( std::vector< float >  values)

Creates a variant from the floating-point values contained in values. The type of the variant is set to FloatArray.

◆ CYIVariant() [5/13]

CYIVariant::CYIVariant ( const glm::vec2 &  rvValue)

Creates a variant from the floating-point vector rvValue. The type of the variant is set to FloatVec2.

◆ CYIVariant() [6/13]

CYIVariant::CYIVariant ( float  x,
float  y 
)

Creates a variant from the floating-point values x and y. The type of the variant is set to FloatVec2.

◆ CYIVariant() [7/13]

CYIVariant::CYIVariant ( const glm::vec3 &  rvValue)

Creates a variant from the floating-point vector rvValue. The type of the variant is set to FloatVec3.

◆ CYIVariant() [8/13]

CYIVariant::CYIVariant ( float  x,
float  y,
float  z 
)

Creates a variant from the floating-point values x, y and z. The type of the variant is set to FloatVec3.

◆ CYIVariant() [9/13]

CYIVariant::CYIVariant ( int32_t  value)

Creates a variant from the integer value value. The type of the variant is set to Int.

◆ CYIVariant() [10/13]

CYIVariant::CYIVariant ( const int32_t  pValue[],
uint32_t  count 
)

Creates a variant from the integer values contained in pValue, copying exactly count values. The type of the variant is set to IntArray.

◆ CYIVariant() [11/13]

CYIVariant::CYIVariant ( std::vector< int32_t >  values)

Creates a variant from the integer values contained in values. The type of the variant is set to IntArray.

◆ CYIVariant() [12/13]

CYIVariant::CYIVariant ( const glm::quat &  rValue)

Creates a variant from the quaternion rValue. The type of the variant is set to Quaternion.

◆ CYIVariant() [13/13]

CYIVariant::CYIVariant ( const CYIString rsValue)
explicit

Creates a variant from the String rsValue. The type of the variant is set to String.

Member Function Documentation

◆ ExpOf()

CYIVariant CYIVariant::ExpOf ( ) const

Calculates and returns the exponential of each value contained in this variant. Does not support Invalid, Quaternion and String types.

◆ GetApproximateSize()

size_t CYIVariant::GetApproximateSize ( ) const

Returns the approximate size used by this object in memory. Includes both stack and heap memory.

◆ GetAsFloat()

float CYIVariant::GetAsFloat ( ) const

Returns the content of this variant as a floating-point value. For array and vector types, the first value is used. Does not support the Invalid type.

◆ GetAsFloatPointer()

const float* CYIVariant::GetAsFloatPointer ( size_t pSize = nullptr) const

Returns the content of this variant as a floating-point array. The number of elements in the array can optionally be returned by providing a pointer to pSize. This variant object retains ownership of the returned array. Does not support the Invalid, Int, IntArray and String types.

◆ GetAsFloatVec2()

glm::vec2 CYIVariant::GetAsFloatVec2 ( ) const

Returns the content of this variant as a floating-point vector. For Float and Int types, the second element of the returned vector will be 0. For Quaternion types, the returned value is a vector containing radian euler angles. For array types, the returned value is filled with up to the first 2 items from the array. Does not support the Invalid and String types.

◆ GetAsFloatVec3()

glm::vec3 CYIVariant::GetAsFloatVec3 ( ) const

Returns the content of this variant as a floating-point vector. For Float and Int types, the second and third element of the returned vector will be 0. For Quaternion types, the returned value is a vector containing radian euler angles. For array types, the returned value is filled with up to the first 3 items from the array. Does not support the Invalid and String types.

◆ GetAsInt()

int32_t CYIVariant::GetAsInt ( ) const

Returns the content of this variant as an integer value. For array and vector types, the first value is used. Does not support the Invalid type.

◆ GetAsIntPointer()

const int32_t* CYIVariant::GetAsIntPointer ( size_t pSize = nullptr) const

Returns the content of this variant as an integer array. The number of elements in the array can optionally be returned by providing a pointer to pSize. This variant object retains ownership of the returned array. Does not support the Invalid, Float, FloatVec2, FloatVec3, FloatArray, Quaternion and String types.

◆ GetAsQuaternion()

glm::quat CYIVariant::GetAsQuaternion ( ) const

Returns the content of this variant as a quaternion. For Int and Float types, only the w component of the quaternion is filled. For FloatVec2 and FloatVec3 types, the value is interpreted as euler angles. For array types, the required value is filled with up to the first 4 items from the array. Does not support Invalid and String types.

◆ GetAsString()

CYIString CYIVariant::GetAsString ( ) const

Returns the content of this variant as a String. Does not support Invalid, FloatArray, FloatVec2, FloatVec3, IntArray and Quaternion types.

◆ GetType()

Type CYIVariant::GetType ( ) const

Returns the type of value contained in this variant.

See also
CYIVariant::Type

◆ IsValid()

bool CYIVariant::IsValid ( ) const

Returns true if this variant contains a value. That is, this function returns false only if the type of this variant is Invalid.

◆ Lerp()

static void CYIVariant::Lerp ( const CYIVariant start,
const CYIVariant end,
float *  pPercentages,
size_t  percentageCount,
CYIVariant out_variant 
)
static

Performs a linear interpolation between two variant objects start and end. The output of the interpolation is stored in out_variant.

The pPercentages array must contain at least one percentage value (which ranges from 0.0 to 1.0) to specify the point on the interpolation curve to return a value for. For array and vector types, multiple percentage values can be provided and the percentageCount parameter must contain the number of available percentage values.

Note
The start and end variants must be of the same type.
This function does not support the Invalid and String types.

◆ LogOf()

CYIVariant CYIVariant::LogOf ( ) const

Calculates and returns the natural logarithm of each value contained in this variant. Does not support Invalid, Quaternion and String types.

◆ operator*()

CYIVariant CYIVariant::operator* ( const CYIVariant rOther) const

Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.

◆ operator*=()

bool CYIVariant::operator*= ( const CYIVariant rOther)

Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.

◆ operator+()

CYIVariant CYIVariant::operator+ ( const CYIVariant rOther) const

Supported types: Int, String, Float, FloatVec2, FloatVec3, FloatArray and IntArray.

◆ operator+=()

bool CYIVariant::operator+= ( const CYIVariant rOther)

Supported types: Int, String, Float, FloatVec2, FloatVec3, FloatArray and IntArray.

◆ operator-()

CYIVariant CYIVariant::operator- ( const CYIVariant rOther) const

Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.

◆ operator-=()

bool CYIVariant::operator-= ( const CYIVariant rOther)

Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.

◆ operator/()

CYIVariant CYIVariant::operator/ ( const CYIVariant rOther) const

Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.

◆ operator/=()

bool CYIVariant::operator/= ( const CYIVariant rOther)

Supported types: Int, Float, FloatVec2, FloatVec3, FloatArray and IntArray.

◆ Set() [1/12]

void CYIVariant::Set ( float  value)

Sets the data contained in the variant to the floating-point value value. The type of the variant is set to Float.

◆ Set() [2/12]

void CYIVariant::Set ( const float  pValue[],
uint32_t  count 
)

Sets the data contained in the variant to the floating-point values contained in pValue, copying exactly count values. The type of the variant is set to FloatArray.

◆ Set() [3/12]

void CYIVariant::Set ( std::vector< float >  values)

Sets the data contained in the variant to the floating-point values contained in values. The type of the variant is set to FloatArray.

◆ Set() [4/12]

void CYIVariant::Set ( const glm::vec2 &  rvValue)

Sets the data contained in the variant to the floating-point vector rvValue. The type of the variant is set to FloatVec2.

◆ Set() [5/12]

void CYIVariant::Set ( float  x,
float  y 
)

Sets the data contained in the variant to the floating-point values x and y. The type of the variant is set to FloatVec2.

◆ Set() [6/12]

void CYIVariant::Set ( const glm::vec3 &  rvValue)

Sets the data contained in the variant to the floating-point vector rvValue. The type of the variant is set to FloatVec3.

◆ Set() [7/12]

void CYIVariant::Set ( float  x,
float  y,
float  z 
)

Sets the data contained in the variant to the floating-point values x, y and z. The type of the variant is set to FloatVec3.

◆ Set() [8/12]

void CYIVariant::Set ( int32_t  value)

Sets the data contained in the variant to the integer value value. The type of the variant is set to Int.

◆ Set() [9/12]

void CYIVariant::Set ( const int32_t  pValue[],
uint32_t  count 
)

Sets the data contained in the variant to the integer values contained in pValue, copying exactly count values. The type of the variant is set to IntArray.

◆ Set() [10/12]

void CYIVariant::Set ( std::vector< int32_t >  values)

Sets the data contained in the variant to the integer values contained in values. The type of the variant is set to IntArray.

◆ Set() [11/12]

void CYIVariant::Set ( const glm::quat &  rValue)

Sets the data contained in the variant to the quaternion rValue. The type of the variant is set to Quaternion.

◆ Set() [12/12]

void CYIVariant::Set ( const CYIString rsValue)

Sets the data contained in the variant to the string rsValue. The type of the variant is set to String.

◆ SetInvalid()

void CYIVariant::SetInvalid ( )

Clears the data contained in this variant. The type of the variant is set to Invalid.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const CYIVariant rLHS,
const CYIVariant rRHS 
)
friend

All types are supported. Two 'invalid' variants are considered to be equal.

◆ operator==

bool operator== ( const CYIVariant rLHS,
const CYIVariant rRHS 
)
friend

All types are supported. Two 'invalid' variants are considered to be equal.


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