neo::core::Any Class Reference

#include <core/any.h>

List of all members.


Detailed Description

Generic container for objects of any type. Also provides information at runtime about the stored type and type traits. Type safety is only assured when using the same type for retrieving the contained object as was used for storing it. There is no type checking.

Example usage:

 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)

Author:
Mattias Jansson (mattias@realityrift.com)


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>
Anyoperator= (const T &rhs)
 Assign data.
Anyoperator= (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 TypeInfogetTypeInfo () 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.


Constructor & Destructor Documentation

template<typename T>
neo::core::Any::Any ( const T &  data  )  [inline]

Parameters:
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

Parameters:
any Container to copy data from


Member Function Documentation

template<typename T>
Any & neo::core::Any::operator= ( const T &  rhs  )  [inline]

Assign data of any type

Parameters:
rhs Data of any type
Returns:
Self-reference

Any & neo::core::Any::operator= ( const Any rhs  )  [inline]

Assign data from given container, clear if given container is empty

Parameters:
rhs Any object to copy data from
Returns:
Self-reference

bool neo::core::Any::empty (  )  const [inline]

Returns:
true if no data has been assigned, false if not

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.

Returns:
Type info

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.

See also:
neo::core::TypeInfo
Returns:
Type information

template<typename T>
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.

Returns:
Data

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.

Returns:
Data

void neo::core::Any::swap ( Any any  )  [inline]

Parameters:
any Container to swap data with


The documentation for this class was generated from the following file:
Generated on Sat Feb 17 20:51:01 2007 for NeoEngine 2 - Evolution by  doxygen 1.5.1