#include <cxxtools/any.h>
Public Member Functions | |
| template<typename T> | |
| Any (const T &type) | |
| Construct with value. | |
| Any () | |
| Default constructor. | |
| Any & | assign (Value *value) |
| Assigns an abstract value. | |
| Any (const Any &val) | |
| Copy constructor. | |
| ~Any () | |
| Destructor. | |
| void | clear () |
| Clear content. | |
| bool | empty () const |
| Check if empty. | |
| Any & | swap (Any &other) |
| Swap values. | |
| const char * | typeName () const |
| Check typename of assigned type. | |
| const std::type_info & | type () const |
| Returns type info of assigned type. | |
| template<typename T> | |
| Any & | operator= (const T &rhs) |
| Assign value. | |
| Any & | operator= (const Any &rhs) |
| Assign value of other Any. | |
| template<typename T> | |
| bool | operator== (const T &value) const |
| Check if equal. | |
| bool | operator== (const Any &a) const |
| Check if equal. | |
| bool | operator!= (const Any &a) const |
| Check if inequal. | |
| bool | operator< (const Any &a) const |
| Check if less. | |
| const Any::Value * | value () const |
| Any::Value * | value () |
Friends | |
| template<typename T> | |
| T | any_cast (const Any &) |
| Get contained value. | |
Classes | |
| class | BasicValue |
| class | Value |
Any a = 5; int i = any_cast<int>( a ); // i is 5 now float f = any_cast<float>( a ) // throws std::bad_cast
Anys can be compared by the contained types and values. Two Anys are considered equal when the contained values are equal and of the same type. A special case is less-than comparison, when the contained types are different. std::type_info::before will be used to decide which Any is less.
Any a = 6; Any b = 6; Any c = '6'; Any d = 1; // true, same type, same value a == b; // false, different types b == c; // true, same type and less d \< a; // implementation dependent d \< c;
| Any | ( | const T & | type | ) |
| Any | ( | ) |
Constructs an empty any. No memory needs to be allocated for empty Anys.
| ~Any | ( | ) |
Deallocates the memory needed to hold the value. This will also destruct the contained type.
| void clear | ( | ) |
Removes the stored type resulting in a destructor call for the stored type. All memory required to hold the value is deallocated.
| bool empty | ( | ) | const |
Returns true if no value has been assigned, false otherwise.
The member function swaps the assigned values between *this and right. No exceptions are thrown, and no memory needs to be allocated.
| other | Other any to swap value |
| const char* typeName | ( | ) | const |
Returns the typename of the currently assigned type. If the Any is empty "void" is returned.
| const std::type_info& type | ( | ) | const |
Returns the std::type_info of the currently assigned type. If the Any is empty the type_info of void is returned.
| Any& operator= | ( | const T & | rhs | ) |
Assigns a value of an arbitrary type. The type to be assigned must be copy-constructible. Memory is allocated to store the value. If an exception is thrown during construction, the Any will remain unaltered and the exception is porpagated.
| rhs | Value to assign |
| bool operator== | ( | const T & | value | ) | const |
Returns true if the contained type and the passed type are equal and have equal values.
| bool operator== | ( | const Any & | a | ) | const |
Returns true if the contained types are equal and have equal values.
| bool operator!= | ( | const Any & | a | ) | const |
Returns true if the contained types have different values or if the conatained types are different.
| bool operator< | ( | const Any & | a | ) | const |
| T any_cast | ( | const Any & | any | ) | [friend] |
This function is used to get the contained value from an Any. It is not possible to get a float out of an Any if the contained value is an int, but the typeid's must match. It is, however, possible to get a const reference to the contained type.
| any | Any to read to |
| std::bad_cast | on type mismatch |