| public |
Inheritance Graph
graph BT
Generic
click Generic "classUtil_1_1Generic"
Description
Container for a value with generic type.
A Generic object is able to store a single object of different types. This allows for the usage of Generic as variable with a type that does not have to be known at compile-time.
Util::Generic value;
value = 42.0;
std::cout << value.contains<std::string>() << std::endl;
value = std::string("fourty-two");
std::cout << value.contains<std::string>() << std::endl;
std::cout << value.ref<std::string>() << std::endl;
value = false;
Author: Benjamin Eikel
Date: 2013-05-28
Classes
| struct | Util::Generic::AbstractStorage Abstract base class for all template instantiations in subclasses. |
| struct | Util::Generic::Storage |
Public Functions
| Generic() Construct with invalid value. |
|
| template< typename type_t > | |
| Generic(type_t && object) Construct with a copy of the given object. |
|
| Generic(const Generic & other) Copy construct from another generic object. |
|
| Generic( Generic && void) Move construct from another generic object. |
|
| ~Generic() Destroy the generic object. |
|
| template< typename type_t > | |
| Generic & | operator=(type_t && object) Copy from another object. |
| Generic & | operator=( Generic && void) Move construct from another generic object. |
| bool | valid() const Check if the generic object contains any data. |
| template< typename type_t > | |
| bool | contains() const Check if the stored data is of the given type. |
| template< typename type_t > | |
| type_t * | get() |
| template< typename type_t > | |
| const type_t * | get() const |
| template< typename type_t > | |
| type_t & | ref() |
| template< typename type_t > | |
| const type_t & | ref() const |
Documentation
function
Util::Generic::Generic
| public | inline |
| Generic( | ) |
Construct with invalid value.
Defined in Util/Generic.h:75
function
Util::Generic::Generic
| public | inline | explicit |
| template< typename type_t > | ||
| Generic( | type_t && | object ) |
Construct with a copy of the given object.
Defined in Util/Generic.h:80
function
Util::Generic::Generic
| public | inline |
| Generic( | const Generic & | other ) |
Copy construct from another generic object.
Defined in Util/Generic.h:86
function
Util::Generic::Generic
| public |
| Generic( | Generic && | void ) |
Move construct from another generic object.
Defined in Util/Generic.h:90
function
Util::Generic::~Generic
| public |
| ~Generic( | ) |
Destroy the generic object.
Defined in Util/Generic.h:93
function
Util::Generic::operator=
| public | inline |
| template< typename type_t > | ||
| Generic & operator=( | type_t && | object ) |
Copy from another object.
Defined in Util/Generic.h:97
function
Util::Generic::operator=
| public |
| Generic & operator=( | Generic && | void ) |
Move construct from another generic object.
Defined in Util/Generic.h:102
function
Util::Generic::valid
| public | const | inline |
| bool valid( | ) const |
Check if the generic object contains any data.
Defined in Util/Generic.h:105
function
Util::Generic::contains
| public | const | inline |
| template< typename type_t > | |
| bool contains( | ) const |
Check if the stored data is of the given type.
Defined in Util/Generic.h:111
function
Util::Generic::get
| public | inline |
| template< typename type_t > | |
| type_t * get( | ) |
Access the data of the generic object by pointer.
Returns
Pointer to the stored data, ornullptrif no data is stored or the data is not of the requested type.
Defined in Util/Generic.h:122
function
Util::Generic::get
| public | const | inline |
| template< typename type_t > | |
| const type_t * get( | ) const |
Access the data of the generic object for reading by pointer.
Returns
Pointer to the stored data, ornullptrif no data is stored or the data is not of the requested type.
Defined in Util/Generic.h:140
function
Util::Generic::ref
| public | inline |
| template< typename type_t > | |
| type_t & ref( | ) |
Access the data of the generic object by reference.
Exceptions
- std::bad_cast
- if no data is stored or the data is not of the requested type
Returns
Reference to the stored data
Defined in Util/Generic.h:153
function
Util::Generic::ref
| public | const | inline |
| template< typename type_t > | |
| const type_t & ref( | ) const |
Access the data of the generic object for reading by reference.
Exceptions
- std::bad_cast
- if no data is stored or the data is not of the requested type
Returns
Reference to the stored data
Defined in Util/Generic.h:169