A class that stores a variable of arbitrary type.
More...
#include <OGF/gom/types/any.h>
|
|
static std::string | meta_type_name (const MetaType *mt) |
| |
A class that stores a variable of arbitrary type.
Definition at line 62 of file any.h.
◆ Any() [1/2]
Any constructor.
Definition at line 76 of file any.h.
◆ ~Any()
Any destructor.
Definition at line 82 of file any.h.
◆ Any() [2/2]
| OGF::Any::Any |
( |
const Any & |
rhs | ) |
|
|
inline |
Any copy constructor.
- Parameters
-
| [in] | rhs | the Any to be copied. |
Definition at line 114 of file any.h.
◆ 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 136 of file any.h.
◆ convert_from_string()
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. If conversion was not successful, an error message is displayed.
- Parameters
-
| [in] | meta_type | a pointer to the MetaType |
| [in] | string | a const reference to the string |
| [out] | value | a pointer to the converted value |
- Return values
-
| true | if conversion was successful, false otherwise |
◆ convert_to_string()
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. If conversion was not successful, an error message is displayed.
- Parameters
-
| [in] | meta_type | a pointer to the MetaType |
| [out] | string | the string representation of the object |
| [in] | value | a pointer to the object |
- Return values
-
| true | if conversion was successful, false otherwise |
◆ copy()
| void OGF::Any::copy |
( |
const Any & |
rhs | ) |
|
|
inlineprotected |
Copies another Any.
- Parameters
-
| [in] | rhs | the Any to be copied. |
Definition at line 660 of file any.h.
◆ copy_convert_to()
Tentatively converts the value stored in this Any to a type and if successful, store it at a specified address.
- Parameters
-
| [out] | addr | a memory address where to store the value |
| [in] | meta_type | the MetaType |
- Return values
-
| true | on success |
| false | if no conversion is available. |
◆ copy_from()
Assigns a value from a specifed address and specified type to this Any.
- Parameters
-
| [in] | addr | a memory address |
| [in] | meta_type | the MetaType |
Definition at line 484 of file any.h.
◆ copy_to()
Copies the value stored in this Any at a specified address.
- Parameters
-
| [out] | addr | a memory address where to store the value |
| [in] | meta_type | the MetaType |
- Return values
-
| true | on success |
| false | if type mistmatches stored type and no conversion is available. |
Definition at line 511 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
-
Definition at line 465 of file any.h.
◆ data()
Gets a pointer to the stored value.
Use at your own risk !
- Returns
- a raw untyped pointer to the stored value
Definition at line 685 of file any.h.
◆ destroy()
| void OGF::Any::destroy |
( |
| ) |
|
|
inlineprotected |
Deallocates the stored variable.
Definition at line 642 of file any.h.
◆ get_value() [1/8]
| bool OGF::Any::get_value |
( |
double & |
value | ) |
const |
|
inline |
Gets the stored value (double overload).
- Parameters
-
| [out] | value | the stored value. |
- Return values
-
| true | if the specified type was correct. |
| false | otherwise. |
Definition at line 379 of file any.h.
◆ get_value() [2/8]
| bool OGF::Any::get_value |
( |
float & |
value | ) |
const |
|
inline |
Gets the stored value (float overload).
- Parameters
-
| [out] | value | the stored value. |
- Return values
-
| true | if the specified type was correct. |
| false | otherwise. |
Definition at line 345 of file any.h.
◆ get_value() [3/8]
Gets the stored value (index_t overload).
- Parameters
-
| [out] | value | the stored value. |
- Return values
-
| true | if the specified type was correct. |
| false | otherwise. |
Definition at line 273 of file any.h.
◆ get_value() [4/8]
Gets the stored value (signed_index_t overload).
- Parameters
-
| [out] | value | the stored value. |
- Return values
-
| true | if the specified type was correct. |
| false | otherwise. |
Definition at line 309 of file any.h.
◆ get_value() [5/8]
Gets the stored value as a SmartPointer.
- Parameters
-
| [out] | value | the stored value. |
- Return values
-
| true | if the specified type T corresponded to the stored value. |
| false | otherwise. |
Definition at line 220 of file any.h.
◆ get_value() [6/8]
| bool OGF::Any::get_value |
( |
std::string & |
value | ) |
const |
|
inline |
Gets the stored value (std::string overload).
- Parameters
-
| [out] | value | the stored value. |
- Return values
-
| true | if the specified type was correct. |
| false | otherwise. |
Definition at line 262 of file any.h.
◆ get_value() [7/8]
template<class T >
| bool OGF::Any::get_value |
( |
T & |
value | ) |
const |
|
inline |
Gets the stored value.
- Parameters
-
| [out] | value | the stored value. |
- Return values
-
| true | if the specified type T corresponded to the stored value. |
| false | otherwise. |
Definition at line 235 of file any.h.
◆ get_value() [8/8]
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] | value | the stored value. |
- Return values
-
| true | if the specified type was correct. |
| false | otherwise. |
Definition at line 417 of file any.h.
◆ is_a()
Tests whether the stored object inherits a given type.
- Parameters
-
| [in] | type | a const pointer to the MetaType to be tested. |
- Return values
-
| true | if this object inherits type |
| false | otherwise |
◆ is_null()
| bool OGF::Any::is_null |
( |
| ) |
const |
|
inline |
Tests whether this Any is null.
- Return values
-
| true | if the Any does not store a value. |
| false | otherwise. |
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
-
| true | if MetaType is a pointer type. |
| false | otherwise. |
◆ is_smart_pointer_type()
| static bool OGF::Any::is_smart_pointer_type |
( |
const MetaType * |
mtype | ) |
|
|
static |
Tests whether a MetaType is a smart pointer type.
- Return values
-
| true | if MetaType is SmartPointer<Counted>. |
| false | otherwise. |
◆ life_cycle()
Gets the LifeCycle.
The LifeCycle knows how to construct, copy, and destroy objects of a given type.
- 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 149 of file any.h.
◆ operator=()
| Any & OGF::Any::operator= |
( |
const Any & |
rhs | ) |
|
|
inline |
Any affectation operator.
- Parameters
-
| [in] | rhs | the Any to be copied. |
- Returns
- a reference to this Any after affectation.
Definition at line 124 of file any.h.
◆ pointed_type()
Gets the deferenced type.
- Parameters
-
- 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_type | the MetaType of the derived pointer type. |
| [in] | base_pointer_type | the MetaType of the base pointer type. |
- Return values
-
| true | if pointers of type derived_pointer_type can be casted to pointers of type base_pointer_type. |
| false | otherwise. |
◆ reset()
Resets this Any to the initial null value.
Definition at line 106 of file any.h.
◆ resolve_meta_type()
template<class T >
| static MetaType * OGF::Any::resolve_meta_type |
( |
| ) |
|
|
inlinestatic |
◆ resolve_meta_type_by_typeid_name()
| static MetaType * OGF::Any::resolve_meta_type_by_typeid_name |
( |
const std::string & |
typeid_name | ) |
|
|
static |
◆ 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] | value | the string to be stored. |
Definition at line 210 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] | value | the value to be stored. |
Definition at line 165 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
-
- Returns
- a reference to the stored value as type T.
This is a brute-force cast, check before that type matches.
Definition at line 635 of file any.h.
The documentation for this class was generated from the following file: