Graphite  Version 3
An experimental 3D geometry processing program
OGF::Any Class Reference

A class that stores a variable of arbitrary type. More...

#include <OGF/gom/types/any.h>

Public Member Functions

 Any ()
 Any constructor.
 
 ~Any ()
 Any destructor.
 
bool is_null () const
 Tests whether this Any is null. More...
 
void reset ()
 Resets this Any to the initial null value.
 
 Any (const Any &rhs)
 Any copy constructor. More...
 
Anyoperator= (const Any &rhs)
 Any affectation operator. More...
 
std::string as_string () const
 Gets a string representation. More...
 
MetaTypemeta_type () const
 Gets the MetaType of the stored value. More...
 
LifeCyclelife_cycle () const
 Gets the LifeCycle. More...
 
template<class T >
void set_value (const T &value)
 Sets the value of this Any. More...
 
void set_value (const char *value)
 Sets the value of this Any (overload for string literals). More...
 
template<class T >
bool get_value (T &value) const
 Gets the stored value. More...
 
bool get_value (std::string &value) const
 Gets the stored value (std::string overload). More...
 
bool get_value (index_t &value) const
 Gets the stored value (index_t overload). More...
 
bool get_value (signed_index_t &value) const
 Gets the stored value (signed_index_t overload). More...
 
bool get_value (float &value) const
 Gets the stored value (float overload). More...
 
bool get_value (double &value) const
 Gets the stored value (double overload). More...
 
template<class T >
bool get_value (T *&value) const
 Gets the stored value (pointers overload). More...
 
void create (MetaType *meta_type)
 Initializes this Any with the default value of a specified MetaType. More...
 
void copy_from (Memory::pointer addr, MetaType *meta_type)
 Assigns a value from a specifed address and specified type to this Any. More...
 
bool copy_to (Memory::pointer addr, MetaType *meta_type) const
 Copies the value stored in this Any at a specified address. More...
 

Static Public Member Functions

static void convert_to_string (MetaType *meta_type, std::string &string, Memory::pointer value)
 Converts an object of a given type into a string. More...
 
static void convert_from_string (MetaType *meta_type, const std::string &string, Memory::pointer value)
 Converts a string into an object of a given type. More...
 
static bool is_pointer_type (const MetaType *mtype)
 Tests whether a MetaType is a pointer type. More...
 
static MetaTypepointed_type (const MetaType *mtype)
 Gets the deferenced type. More...
 
static bool pointer_can_be_casted_to (const MetaType *derived_pointer_type, const MetaType *base_pointer_type)
 Tests whether a pointer type can be casted to an object type. More...
 
static MetaTyperesolve_meta_type_by_typeid_name (const std::string &typeid_name)
 Finds a MetaType by typeid name. More...
 
template<class T >
static MetaTyperesolve_meta_type ()
 Gets the MetaType associated with a type. More...
 

Protected Member Functions

bool copy_convert_to (Memory::pointer addr, MetaType *meta_type) const
 Tentatively converts the value stored in this Any to a type and if successful, store it at a specified address. More...
 
template<class T >
const T & value_as () const
 Gets the value as a specific type. More...
 
void destroy ()
 Deallocates the stored variable.
 
void copy (const Any &rhs)
 Copies another Any. More...
 

Static Protected Member Functions

static std::string meta_type_name (const MetaType *mt)
 

Detailed Description

A class that stores a variable of arbitrary type.

Definition at line 62 of file any.h.

Constructor & Destructor Documentation

◆ Any()

OGF::Any::Any ( const Any rhs)
inline

Any copy constructor.

Parameters
[in]rhsthe Any to be copied.

Definition at line 106 of file any.h.

Member Function Documentation

◆ as_string()

std::string OGF::Any::as_string ( ) const
inline

Gets a string representation.

Returns
a string representation of the stored argument

Definition at line 128 of file any.h.

◆ convert_from_string()

static void OGF::Any::convert_from_string ( MetaType meta_type,
const std::string &  string,
Memory::pointer  value 
)
static

Converts a string into an object of a given type.

It does the same thing as ogf_convert_from_string(), namely it uses the Serializer registered in the Meta repository. We cannot use ogf_convert_from_string() since it would introduce a circular dependency in Meta, that uses ArgList.

Parameters
[in]meta_typea pointer to the MetaType
[in]stringa const reference to the string
[out]valuea pointer to the converted value

◆ convert_to_string()

static void OGF::Any::convert_to_string ( MetaType meta_type,
std::string &  string,
Memory::pointer  value 
)
static

Converts an object of a given type into a string.

It does the same thing as ogf_convert_to_string(), namely it uses the Serializer registered in the Meta repository. We cannot use ogf_convert_to_string() since it would introduce a circular dependency in Meta, that uses ArgList.

Parameters
[in]meta_typea pointer to the MetaType
[out]stringthe string representation of the object
[in]valuea pointer to the object

◆ copy()

void OGF::Any::copy ( const Any rhs)
inlineprotected

Copies another Any.

Parameters
[in]rhsthe Any to be copied.

Definition at line 618 of file any.h.

◆ copy_convert_to()

bool OGF::Any::copy_convert_to ( Memory::pointer  addr,
MetaType meta_type 
) const
protected

Tentatively converts the value stored in this Any to a type and if successful, store it at a specified address.

Parameters
[out]addra memory address where to store the value
[in]meta_typethe MetaType
Return values
trueon success
falseif no conversion is available.

◆ copy_from()

void OGF::Any::copy_from ( Memory::pointer  addr,
MetaType meta_type 
)
inline

Assigns a value from a specifed address and specified type to this Any.

Parameters
[in]addra memory address
[in]meta_typethe MetaType

Definition at line 452 of file any.h.

◆ copy_to()

bool OGF::Any::copy_to ( Memory::pointer  addr,
MetaType meta_type 
) const
inline

Copies the value stored in this Any at a specified address.

Parameters
[out]addra memory address where to store the value
[in]meta_typethe MetaType
Return values
trueon success
falseif type mistmatches stored type and no conversion is available.

Definition at line 479 of file any.h.

◆ create()

void OGF::Any::create ( MetaType meta_type)
inline

Initializes this Any with the default value of a specified MetaType.

Parameters
[in]meta_typea pointer to the MetaType.

Definition at line 433 of file any.h.

◆ get_value() [1/7]

bool OGF::Any::get_value ( double &  value) const
inline

Gets the stored value (double overload).

Parameters
[out]valuethe stored value.
Return values
trueif the specified type was correct.
falseotherwise.

Definition at line 354 of file any.h.

◆ get_value() [2/7]

bool OGF::Any::get_value ( float &  value) const
inline

Gets the stored value (float overload).

Parameters
[out]valuethe stored value.
Return values
trueif the specified type was correct.
falseotherwise.

Definition at line 320 of file any.h.

◆ get_value() [3/7]

bool OGF::Any::get_value ( index_t value) const
inline

Gets the stored value (index_t overload).

Parameters
[out]valuethe stored value.
Return values
trueif the specified type was correct.
falseotherwise.

Definition at line 248 of file any.h.

◆ get_value() [4/7]

bool OGF::Any::get_value ( signed_index_t value) const
inline

Gets the stored value (signed_index_t overload).

Parameters
[out]valuethe stored value.
Return values
trueif the specified type was correct.
falseotherwise.

Definition at line 284 of file any.h.

◆ get_value() [5/7]

bool OGF::Any::get_value ( std::string &  value) const
inline

Gets the stored value (std::string overload).

Parameters
[out]valuethe stored value.
Return values
trueif the specified type was correct.
falseotherwise.

Definition at line 237 of file any.h.

◆ get_value() [6/7]

template<class T >
bool OGF::Any::get_value ( T &  value) const
inline

Gets the stored value.

Parameters
[out]valuethe stored value.
Return values
trueif the specified type was correct.
falseotherwise.

Definition at line 210 of file any.h.

◆ get_value() [7/7]

template<class T >
bool OGF::Any::get_value ( T *&  value) const
inline

Gets the stored value (pointers overload).

More complicated than using the default function, this is because AnyStore is not a subtype of AnyStore if B is a subclass of A (inheritance does not play well with templates).

Parameters
[out]valuethe stored value.
Return values
trueif the specified type was correct.
falseotherwise.

Definition at line 392 of file any.h.

◆ is_null()

bool OGF::Any::is_null ( ) const
inline

Tests whether this Any is null.

Return values
trueif the Any does not store a value.
falseotherwise.

Definition at line 91 of file any.h.

◆ is_pointer_type()

static bool OGF::Any::is_pointer_type ( const MetaType mtype)
static

Tests whether a MetaType is a pointer type.

Return values
trueif MetaType is a pointer type.
falseotherwise.

◆ life_cycle()

LifeCycle* OGF::Any::life_cycle ( ) const

Gets the LifeCycle.

Returns
a pointer to the LifeCycle.

◆ meta_type()

MetaType* OGF::Any::meta_type ( ) const
inline

Gets the MetaType of the stored value.

Returns
a pointer to the MetaType or nullptr if there is no stored value.

Definition at line 141 of file any.h.

◆ operator=()

Any& OGF::Any::operator= ( const Any rhs)
inline

Any affectation operator.

Parameters
[in]rhsthe Any to be copied.
Returns
a reference to this Any after affectation.

Definition at line 116 of file any.h.

◆ pointed_type()

static MetaType* OGF::Any::pointed_type ( const MetaType mtype)
static

Gets the deferenced type.

Parameters
[in]mtypea pointer MetaType.
Returns
the deferenced type.

◆ pointer_can_be_casted_to()

static bool OGF::Any::pointer_can_be_casted_to ( const MetaType derived_pointer_type,
const MetaType base_pointer_type 
)
static

Tests whether a pointer type can be casted to an object type.

Parameters
[in]derived_pointer_typethe MetaType of the derived pointer type.
[in]base_pointer_typethe MetaType of the base pointer type.
Return values
trueif pointers of type derived_pointer_type can be casted to pointers of type base_pointer_type.
falseotherwise.

◆ resolve_meta_type()

template<class T >
static MetaType* OGF::Any::resolve_meta_type ( )
inlinestatic

Gets the MetaType associated with a type.

Returns
a pointer to the MetaType.

Definition at line 568 of file any.h.

◆ resolve_meta_type_by_typeid_name()

static MetaType* OGF::Any::resolve_meta_type_by_typeid_name ( const std::string &  typeid_name)
static

Finds a MetaType by typeid name.

Parameters
[in]typeid_namethe C++ RTTI name of the system, as obtained by typeid<T>.name()
Returns
the MetaType associated with type_name if it exists or nullptr otherwise

Redirects to Meta::resolve_meta_type_by_typeid_name(). It is there because we cannot include <meta.h> since it uses ArgList that in turn uses Any.

◆ set_value() [1/2]

void OGF::Any::set_value ( const char *  value)
inline

Sets the value of this Any (overload for string literals).

Strings literals are stored internally as std::string.

Parameters
[in]valuethe string to be stored.

Definition at line 200 of file any.h.

◆ set_value() [2/2]

template<class T >
void OGF::Any::set_value ( const T &  value)
inline

Sets the value of this Any.

Parameters
[in]valuethe value to be stored.

Definition at line 155 of file any.h.

◆ value_as()

template<class T >
const T& OGF::Any::value_as ( ) const
inlineprotected

Gets the value as a specific type.

Template Parameters
Tthe type.
Returns
a reference to the stored value as type T.

This is a brute-force cast, check before that type matches.

Definition at line 593 of file any.h.


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