#include <core/any.h>
Any container = new SomeType; Any othercontainer; othercontainer.empty(); //True [...] SomeType* p_good = container.get< SomeType* >(); //Correct OtherType* p_bad = container.get< OtherType* >(); //Wrong! Will lead to undefined behaviour! Any othercontainer = container; //Also holds pointer to same SomeType object as container container = "foobar"; //container now holds a const char* to the string delete p_good; //Object must be deleted manually, as a container Any does not deallocate dynamic objects [...] //othercontainer now holds invalid pointer to destroyed object
Based loosely on boost::any (http://www.boost.org)
Public Member Functions | |
| Any () | |
| Construct empty container. | |
| template<typename T> | |
| Any (const T &data) | |
| Construct container with given data. | |
| Any (const Any &any) | |
| Copy constructor. | |
| ~Any () | |
| Destruct container. | |
| template<typename T> | |
| Any & | operator= (const T &rhs) |
| Assign data. | |
| Any & | operator= (const Any &rhs) |
| Assign data. | |
| void | clear () |
| Clear data. | |
| bool | empty () const |
| Query if empty. | |
| const std::type_info & | getType () const |
| Get standard type info. | |
| const TypeInfo & | getTypeInfo () const |
| Get extended type info. | |
| template<typename T> | |
| T & | get () const |
| Get data. | |
| void * | getRaw () const |
| Get data as raw void pointer. | |
| void | swap (Any &any) |
| Swap data. | |
| neo::core::Any::Any | ( | const T & | data | ) | [inline] |
| data | Data of any type |
| neo::core::Any::Any | ( | const Any & | any | ) | [inline] |
Copy data in given container or construct empty container if the given container is empty
| any | Container to copy data from |
| Any & neo::core::Any::operator= | ( | const T & | rhs | ) | [inline] |
Assign data of any type
| rhs | Data of any type |
Assign data from given container, clear if given container is empty
| rhs | Any object to copy data from |
| bool neo::core::Any::empty | ( | ) | const [inline] |
| const std::type_info & neo::core::Any::getType | ( | ) | const [inline] |
Get standard type info of data stored in container. If the container is emtpy, typeid( void ) is returned.
| const TypeInfo & neo::core::Any::getTypeInfo | ( | ) | const [inline] |
Get extended type info of data stored in container. If the container is empty, neo::core::TypeInfo::NOTYPE is returned.
| T & neo::core::Any::get | ( | ) | const [inline] |
Get data as given type. IMPORTANT! There is no type checking in the container. You must make sure you access the data using the same type (or compatible type) as it was stored as, and that the container is not empty.
| void * neo::core::Any::getRaw | ( | ) | const [inline] |
Get data as raw void pointer. Only use this method if you know exactly what you are doing and don't care about type information at all.
| void neo::core::Any::swap | ( | Any & | any | ) | [inline] |
| any | Container to swap data with |
1.5.1