Variant Class Reference

The Variant class is described here: Variants. More...

#include <ArmarXCore/observers/variant/Variant.h>

+ Inheritance diagram for Variant:

Public Member Functions

virtual VariantPtr clone () const
 Returns a copy of the Variant.
 
template<>
bool get () const
 
template<>
float get () const
 
template<>
double get () const
 
template<typename T>
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > get () const
 Template-based getter for the Variant's value.
 
template<typename T>
std::enable_if_t< std::is_base_of_v< VariantDataClass, typename T::element_type >, T > get () const
 
template<typename T>
std::enable_if_t<(std::is_standard_layout_v< T > &&std::is_trivial_v< T >)||std::is_same_v< std::string, T >, T > get () const
 This getter is only called if a wrong template parameter is given (i.e: the type does not inherit from VariantDataClass).
 
template<>
bool get () const
 
template<>
float get () const
 
template<>
double get () const
 
bool getBool (const Ice::Current &c=Ice::emptyCurrent) const override
 Return the Variant's value as bool.
 
template<class TVariantDataClass>
IceInternal::Handle< TVariantDataClass > getClass () const
 Return the Variant's value as TVariantDataClass.
 
double getDouble (const Ice::Current &c=Ice::emptyCurrent) const override
 Return the Variant's value as double.
 
float getFloat (const Ice::Current &c=Ice::emptyCurrent) const override
 Return the Variant's value as float.
 
bool getInitialized (const Ice::Current &c=Ice::emptyCurrent) const override
 Tells if the Variant is properly initialized.
 
int getInt (const Ice::Current &c=Ice::emptyCurrent) const override
 Return the Variant's value as int.
 
long getLong (const Ice::Current &c=Ice::emptyCurrent) const override
 Return the Variant's value as long.
 
virtual std::string getOutputValueOnly () const
 Returns the formatted content of the Variant as a string.
 
std::string getString (const Ice::Current &c=Ice::emptyCurrent) const override
 Return the Variant's value as string.
 
VariantTypeId getType (const Ice::Current &c=Ice::emptyCurrent) const override
 Return the Variant's internal type.
 
std::string getTypeName (const Ice::Current &c=Ice::emptyCurrent) const override
 Return the Variant's internal type.
 
Variant & operator= (bool b)
 
Variant & operator= (const std::string &s)
 
Variant & operator= (const Variant &prototype)
 
Variant & operator= (const VariantDataClass &prototype)
 
Variant & operator= (const VariantDataClassPtr &prototype)
 
Variant & operator= (double d)
 
Variant & operator= (float f)
 
Variant & operator= (int n)
 
Variant & operator= (long n)
 
template<>
void set (const bool &value)
 
template<>
void set (const bool &value)
 
template<>
void set (const double &value)
 
template<>
void set (const double &value)
 
template<>
void set (const float &value)
 
template<>
void set (const float &value)
 
template<typename T>
std::enable_if_t<!std::is_base_of_v< VariantDataClass, T > > set (const T &value)
 Template-based setter for the Variant's value for non-VariantDataClass-instances.
 
template<typename T>
std::enable_if_t< std::is_base_of_v< VariantDataClass, T > > set (const VariantDataClassPtr &variantDataClass)
 Template-based setter for the Variant's value for VariantDataClass-instances.
 
void setBool (bool b, const Ice::Current &c=Ice::emptyCurrent) override
 Sets the Variant's value to b.
 
void setClass (const VariantDataClass &variantDataClass)
 Sets the Variant's value to variantDataClass.
 
void setClass (const VariantDataClassPtr &variantDataClass)
 Sets the Variant's value to variantDataClass.
 
void setDouble (double d, const Ice::Current &c=Ice::emptyCurrent) override
 Sets the Variant's value to d.
 
void setFloat (float f, const Ice::Current &c=Ice::emptyCurrent) override
 Sets the Variant's value to f.
 
void setInt (int n, const Ice::Current &c=Ice::emptyCurrent) override
 Sets the Variant's value to n.
 
void setLong (long n, const Ice::Current &c=Ice::emptyCurrent) override
 Sets the Variant's value to n.
 
void setString (const std::string &s, const Ice::Current &c=Ice::emptyCurrent) override
 Sets the Variant's value to s.
 
void setType (VariantTypeId typeId, const Ice::Current &c=Ice::emptyCurrent) override
 Sets the Variant's type to typeId.
 
bool validate (const Ice::Current &c=Ice::emptyCurrent) const override
 Checks if the Variant is initialized and the stored value is valid with respect to the Variant's type.
 
 Variant ()
 
 Variant (char const var[])
 Construct a Variant from a string.
 
template<>
 Variant (const bool &var, void *)
 
template<>
 Variant (const bool &var, void *t)
 
template<>
 Variant (const double &var, void *)
 
template<>
 Variant (const double &var, void *t)
 
template<>
 Variant (const float &var, void *)
 
template<>
 Variant (const float &var, void *t)
 
template<class T>
 Variant (const IceInternal::Handle< T > &var, typename std::enable_if_t< std::is_base_of_v< VariantDataClass, T > > *t=nullptr)
 Construct a Variant from an IceHandle to a VariantDataClass instance.
 
template<>
 Variant (const std::int16_t &var, void *)
 
template<>
 Variant (const std::int16_t &var, void *t)
 
template<>
 Variant (const std::int32_t &var, void *)
 
template<>
 Variant (const std::int32_t &var, void *t)
 
template<>
 Variant (const std::int64_t &var, void *)
 
template<>
 Variant (const std::int64_t &var, void *t)
 
template<>
 Variant (const std::int8_t &var, void *)
 
template<>
 Variant (const std::int8_t &var, void *t)
 
template<>
 Variant (const std::string &var, void *)
 
template<>
 Variant (const std::string &var, void *t)
 
template<>
 Variant (const std::uint16_t &var, void *)
 
template<>
 Variant (const std::uint16_t &var, void *t)
 
template<>
 Variant (const std::uint32_t &var, void *)
 
template<>
 Variant (const std::uint32_t &var, void *t)
 
template<>
 Variant (const std::uint64_t &var, void *)
 
template<>
 Variant (const std::uint64_t &var, void *t)
 
template<>
 Variant (const std::uint8_t &var, void *)
 
template<>
 Variant (const std::uint8_t &var, void *t)
 
template<>
 Variant (const std::uint8_t &var, void *t)
 
template<class T>
 Variant (const T &var, typename std::enable_if_t< std::is_base_of_v< VariantDataClass, T > > *t=nullptr)
 Construct a Variant from a reference to a VariantDataClass instance.
 
template<class T>
 Variant (const T &var, typename std::enable_if_t<!(std::is_base_of_v< VariantDataClass, T >||std::is_pointer_v< T >)> *t=nullptr)
 Construct a Variant from a non-VariantDataClass instance, e.g.
 
template<class T>
 Variant (const T *var, typename std::enable_if_t< std::is_base_of_v< VariantDataClass, T > > *t=nullptr)
 Construct a Variant from a pointer to a VariantDataClass instance.
 
 Variant (const Variant &source)
 

Static Public Member Functions

static VariantTypeId addTypeName (const std::string &typeName)
 Register a new type for the use in a Variant.
 
template<typename Type>
static std::string GetType ()
 Template-based getter for a type name.
 
static const std::map< VariantTypeId, std::string > & getTypes ()
 Returns the mapping of currently registered types.
 
static int hashTypeName (const std::string &typeName)
 Compute and return a hash value for a given type name.
 
static std::string typeToString (VariantTypeId typeId)
 Return the name of the registered type typeId.
 

Protected Member Functions

void output (std::ostream &stream) const
 Outputs a formatted representation of the Variant to stream.
 

Protected Attributes

bool initialized
 

Friends

std::ostream & operator<< (std::ostream &stream, const Variant &rhs)
 
std::ostream & operator<< (std::ostream &stream, const VariantPtr &rhs)
 

Detailed Description

The Variant class is described here: Variants.

Constructor & Destructor Documentation

◆ Variant() [1/32]

Variant ( )

◆ Variant() [2/32]

Variant ( const Variant & source)

◆ Variant() [3/32]

template<class T>
Variant ( const T & var,
typename std::enable_if_t<!(std::is_base_of_v< VariantDataClass, T >||std::is_pointer_v< T >)> * t = nullptr )
inline

Construct a Variant from a non-VariantDataClass instance, e.g.

from an int

Template Parameters
TThe desired type of the Variant
Parameters
varThe initialization value as a T-instance
tFor type checking only: Do not use

◆ Variant() [4/32]

Variant ( char const var[])
inline

Construct a Variant from a string.

Parameters
varThe initialization value

◆ Variant() [5/32]

template<class T>
Variant ( const T & var,
typename std::enable_if_t< std::is_base_of_v< VariantDataClass, T > > * t = nullptr )
inline

Construct a Variant from a reference to a VariantDataClass instance.

The VariantDataClass is cloned!

Template Parameters
TThe desired type of the Variant
Parameters
varThe initialization value as a T-instance
tFor type checking only: Do not use.

◆ Variant() [6/32]

template<class T>
Variant ( const IceInternal::Handle< T > & var,
typename std::enable_if_t< std::is_base_of_v< VariantDataClass, T > > * t = nullptr )
inline

Construct a Variant from an IceHandle to a VariantDataClass instance.

This is a float pointer copy.

Template Parameters
TThe desired type of the Variant
Parameters
varThe initialization value as a handle to a T-instance
tFor type checking only: Do not use.

◆ Variant() [7/32]

template<class T>
Variant ( const T * var,
typename std::enable_if_t< std::is_base_of_v< VariantDataClass, T > > * t = nullptr )
inline

Construct a Variant from a pointer to a VariantDataClass instance.

The VariantDataClass is cloned!

Template Parameters
TThe desired type of the Variant
Parameters
varThe initialization value as a pointer to a T-instance
tFor type checking only: Do not use.

◆ Variant() [8/32]

template<>
Variant ( const std::int8_t & var,
void *  )

◆ Variant() [9/32]

template<>
Variant ( const std::int16_t & var,
void *  )

◆ Variant() [10/32]

template<>
Variant ( const std::int32_t & var,
void *  )

◆ Variant() [11/32]

template<>
Variant ( const std::int64_t & var,
void *  )

◆ Variant() [12/32]

template<>
Variant ( const std::uint8_t & var,
void *  )

◆ Variant() [13/32]

template<>
Variant ( const std::uint16_t & var,
void *  )

◆ Variant() [14/32]

template<>
Variant ( const std::uint32_t & var,
void *  )

◆ Variant() [15/32]

template<>
Variant ( const std::uint64_t & var,
void *  )

◆ Variant() [16/32]

template<>
Variant ( const float & var,
void *  )

◆ Variant() [17/32]

template<>
Variant ( const double & var,
void *  )

◆ Variant() [18/32]

template<>
Variant ( const bool & var,
void *  )

◆ Variant() [19/32]

template<>
Variant ( const std::string & var,
void *  )

◆ Variant() [20/32]

template<>
template Variant ( const std::int8_t & var,
void * t )

◆ Variant() [21/32]

template<>
template Variant ( const std::int16_t & var,
void * t )

◆ Variant() [22/32]

template<>
template Variant ( const std::int32_t & var,
void * t )

◆ Variant() [23/32]

template<>
template Variant ( const std::int64_t & var,
void * t )

◆ Variant() [24/32]

template<>
Variant ( const std::uint8_t & var,
void * t )

◆ Variant() [25/32]

template<>
template Variant ( const std::uint8_t & var,
void * t )

◆ Variant() [26/32]

template<>
template Variant ( const std::uint16_t & var,
void * t )

◆ Variant() [27/32]

template<>
template Variant ( const std::uint32_t & var,
void * t )

◆ Variant() [28/32]

template<>
template Variant ( const std::uint64_t & var,
void * t )

◆ Variant() [29/32]

template<>
template Variant ( const float & var,
void * t )

◆ Variant() [30/32]

template<>
template Variant ( const double & var,
void * t )

◆ Variant() [31/32]

template<>
template Variant ( const bool & var,
void * t )

◆ Variant() [32/32]

template<>
template Variant ( const std::string & var,
void * t )

Member Function Documentation

◆ addTypeName()

VariantTypeId addTypeName ( const std::string & typeName)
static

Register a new type for the use in a Variant.

Exceptions
LocalExceptionif an already registered type has the same hash value as typeName.

◆ clone()

VariantPtr clone ( ) const
virtual

Returns a copy of the Variant.

◆ get() [1/9]

template<>
bool get ( ) const

◆ get() [2/9]

template<>
float get ( ) const

◆ get() [3/9]

template<>
double get ( ) const

◆ get() [4/9]

template<typename T>
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > get ( ) const
inline

Template-based getter for the Variant's value.

Template Parameters
TType of the desired value, that inherits from VariantDataClass (e.g: Vector3, LinkedPose, ChannelRef).
Exceptions
NotInitializedExceptionif the Variant has not been initialized yet
InvalidTypeExceptionif T is not compatible with the Variant's internal type
Returns
a shared pointer to the desired data type (e.g: Vector3Ptr)

◆ get() [5/9]

template<typename T>
std::enable_if_t< std::is_base_of_v< VariantDataClass, typename T::element_type >, T > get ( ) const
inline

◆ get() [6/9]

template<typename T>
std::enable_if_t<(std::is_standard_layout_v< T > &&std::is_trivial_v< T >)||std::is_same_v< std::string, T >, T > get ( ) const
inline

This getter is only called if a wrong template parameter is given (i.e: the type does not inherit from VariantDataClass).

Exceptions
InvalidTypeException
Returns
For type checking only: Do not use
Note
There exist specializations of this method that allow the basic types bool, int, float, double and std::string

◆ get() [7/9]

template<>
bool get ( ) const

◆ get() [8/9]

template<>
float get ( ) const

◆ get() [9/9]

template<>
template std::string get< std::string > ( ) const

◆ getBool()

bool getBool ( const Ice::Current & c = Ice::emptyCurrent) const
override

Return the Variant's value as bool.

Exceptions
InvalidTypeExceptionif the Variant's type is not VariantType::Bool
NotInitializedExceptionif the Variant is uninitialized

Inherited from VariantBase Ice interface.

◆ getClass()

template<class TVariantDataClass>
IceInternal::Handle< TVariantDataClass > getClass ( ) const
inline

Return the Variant's value as TVariantDataClass.

Template Parameters
TVariantDataClassThe type for returning the data
Exceptions
InvalidTypeExceptionif the Variant's type is not compatible to TVariantDataClass
NotInitializedExceptionif the Variant is uninitialized

◆ getDouble()

double getDouble ( const Ice::Current & c = Ice::emptyCurrent) const
override

Return the Variant's value as double.

Exceptions
InvalidTypeExceptionif the Variant's type is not VariantType::Double
NotInitializedExceptionif the Variant is uninitialized

Inherited from VariantBase Ice interface.

◆ getFloat()

float getFloat ( const Ice::Current & c = Ice::emptyCurrent) const
override

Return the Variant's value as float.

Exceptions
InvalidTypeExceptionif the Variant's type is not VariantType::Float
NotInitializedExceptionif the Variant is uninitialized

Inherited from VariantBase Ice interface.

◆ getInitialized()

bool getInitialized ( const Ice::Current & c = Ice::emptyCurrent) const
override

Tells if the Variant is properly initialized.

◆ getInt()

int getInt ( const Ice::Current & c = Ice::emptyCurrent) const
override

Return the Variant's value as int.

Exceptions
InvalidTypeExceptionif the Variant's type is not VariantType::Int
NotInitializedExceptionif the Variant is uninitialized

Inherited from VariantBase Ice interface.

◆ getLong()

long getLong ( const Ice::Current & c = Ice::emptyCurrent) const
override

Return the Variant's value as long.

Exceptions
InvalidTypeExceptionif the Variant's type is not VariantType::Long
NotInitializedExceptionif the Variant is uninitialized

Inherited from VariantBase Ice interface.

◆ getOutputValueOnly()

std::string getOutputValueOnly ( ) const
virtual

Returns the formatted content of the Variant as a string.

Reimplemented in TimedVariant.

◆ getString()

std::string getString ( const Ice::Current & c = Ice::emptyCurrent) const
override

Return the Variant's value as string.

Exceptions
InvalidTypeExceptionif the Variant's type is not VariantType::String
NotInitializedExceptionif the Variant is uninitialized

Inherited from VariantBase Ice interface.

◆ GetType()

template<typename Type>
static std::string GetType ( )
inlinestatic

Template-based getter for a type name.

◆ getType()

VariantTypeId getType ( const Ice::Current & c = Ice::emptyCurrent) const
override

Return the Variant's internal type.

Returns
The Variant's type as a VariantTypeId

◆ getTypeName()

std::string getTypeName ( const Ice::Current & c = Ice::emptyCurrent) const
override

Return the Variant's internal type.

Returns
The Variant's type as a string

◆ getTypes()

const std::map< VariantTypeId, std::string > & getTypes ( )
static

Returns the mapping of currently registered types.

◆ hashTypeName()

int hashTypeName ( const std::string & typeName)
static

Compute and return a hash value for a given type name.

◆ operator=() [1/9]

Variant & operator= ( bool b)
inline

◆ operator=() [2/9]

Variant & operator= ( const std::string & s)
inline

◆ operator=() [3/9]

Variant & operator= ( const Variant & prototype)

◆ operator=() [4/9]

Variant & operator= ( const VariantDataClass & prototype)

◆ operator=() [5/9]

Variant & operator= ( const VariantDataClassPtr & prototype)

◆ operator=() [6/9]

Variant & operator= ( double d)
inline

◆ operator=() [7/9]

Variant & operator= ( float f)
inline

◆ operator=() [8/9]

Variant & operator= ( int n)
inline

◆ operator=() [9/9]

Variant & operator= ( long n)
inline

◆ output()

void output ( std::ostream & stream) const
protected

Outputs a formatted representation of the Variant to stream.

◆ set() [1/8]

template<>
void set ( const bool & value)

◆ set() [2/8]

template<>
template void set< bool > ( const bool & value)

◆ set() [3/8]

template<>
void set ( const double & value)

◆ set() [4/8]

template<>
template void set< double > ( const double & value)

◆ set() [5/8]

template<>
void set ( const float & value)

◆ set() [6/8]

template<>
template void set< float > ( const float & value)

◆ set() [7/8]

template<typename T>
std::enable_if_t<!std::is_base_of_v< VariantDataClass, T > > set ( const T & value)
inline

Template-based setter for the Variant's value for non-VariantDataClass-instances.

Values not derived from VariantDataClass are not allowed, thus this method always throws an exception.

Template Parameters
TThe desired type of the Variant
Exceptions
InvalidTypeException
Returns
For type checking only: Do not use

◆ set() [8/8]

template<typename T>
std::enable_if_t< std::is_base_of_v< VariantDataClass, T > > set ( const VariantDataClassPtr & variantDataClass)
inline

Template-based setter for the Variant's value for VariantDataClass-instances.

Template Parameters
TThe desired type of the Variant
Exceptions
InvalidTypeExceptionif a type other than T has already been set.
Returns
For type checking only: Do not use

◆ setBool()

void setBool ( bool b,
const Ice::Current & c = Ice::emptyCurrent )
override

Sets the Variant's value to b.

The Variant's type is fixed to VariantType::Bool.

Exceptions
InvalidTypeExceptionif a different type has already been set.

Inherited from VariantBase Ice interface.

◆ setClass() [1/2]

void setClass ( const VariantDataClass & variantDataClass)

Sets the Variant's value to variantDataClass.

The Variant's type is fixed to the type of variantDataClass. The data class is cloned!

Exceptions
InvalidTypeExceptionif a different type has already been set.

Inherited from VariantBase Ice interface.

◆ setClass() [2/2]

void setClass ( const VariantDataClassPtr & variantDataClass)

Sets the Variant's value to variantDataClass.

The Variant's type is fixed to the type of variantDataClass. Flat pointer copy!

Exceptions
InvalidTypeExceptionif a different type has already been set.

Inherited from VariantBase Ice interface.

◆ setDouble()

void setDouble ( double d,
const Ice::Current & c = Ice::emptyCurrent )
override

Sets the Variant's value to d.

The Variant's type is fixed to VariantType::Double.

Exceptions
InvalidTypeExceptionif a different type has already been set.

Inherited from VariantBase Ice interface.

◆ setFloat()

void setFloat ( float f,
const Ice::Current & c = Ice::emptyCurrent )
override

Sets the Variant's value to f.

The Variant's type is fixed to VariantType::Float.

Exceptions
InvalidTypeExceptionif a different type has already been set.

Inherited from VariantBase Ice interface.

◆ setInt()

void setInt ( int n,
const Ice::Current & c = Ice::emptyCurrent )
override

Sets the Variant's value to n.

The Variant's type is fixed to VariantType::Int.

Exceptions
InvalidTypeExceptionif a different type has already been set.

Inherited from VariantBase Ice interface.

◆ setLong()

void setLong ( long n,
const Ice::Current & c = Ice::emptyCurrent )
override

Sets the Variant's value to n.

The Variant's type is fixed to VariantType::Long.

Exceptions
InvalidTypeExceptionif a different type has already been set.

Inherited from VariantBase Ice interface.

◆ setString()

void setString ( const std::string & s,
const Ice::Current & c = Ice::emptyCurrent )
override

Sets the Variant's value to s.

The Variant's type is fixed to VariantType::String.

Exceptions
InvalidTypeExceptionif a different type has already been set.

Inherited from VariantBase Ice interface.

◆ setType()

void setType ( VariantTypeId typeId,
const Ice::Current & c = Ice::emptyCurrent )
override

Sets the Variant's type to typeId.

A Variant's type can not be changed after it has been set.

Exceptions
LocalExceptionif a different type has already been set.

Inherited from VariantBase Ice interface.

◆ typeToString()

std::string typeToString ( VariantTypeId typeId)
static

Return the name of the registered type typeId.

Exceptions
UnknownTypeExceptionif typeId is not registered yet.

◆ validate()

bool validate ( const Ice::Current & c = Ice::emptyCurrent) const
override

Checks if the Variant is initialized and the stored value is valid with respect to the Variant's type.

Inherited from VariantBase Ice interface.

Friends And Related Symbol Documentation

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream & stream,
const Variant & rhs )
friend

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream & stream,
const VariantPtr & rhs )
friend

Member Data Documentation

◆ initialized

bool initialized
mutableprotected

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