A class that can hold any value. More...
#include <any.hpp>
Public Member Functions | |
bool | valid () throw () |
Test if this object contains valid data. | |
Any () | |
Creates an Any object with valid() == false . | |
Any (bool) | |
Creates an Any object from a bool. | |
Any (boost::int8_t) | |
Creates an Any object from a 8 bit integer. | |
Any (boost::uint8_t) | |
Creates an Any object from a 8 bit unsigned integer. | |
Any (boost::int16_t) | |
Creates an Any object from a 16 bit integer. | |
Any (boost::uint16_t) | |
Creates an Any object from a 16 bit unsigned integer. | |
Any (boost::int32_t) | |
Creates an Any object from a 32 bit integer. | |
Any (boost::uint32_t) | |
Creates an Any object from a 32 bit unsigned integer. | |
Any (boost::int64_t) | |
Creates an Any object from a 64 bit integer. | |
Any (boost::uint64_t) | |
Creates an Any object from a 64 bit unsigned integer. | |
Any (float) | |
Creates an Any object from a float. | |
Any (double) | |
Creates an Any object from a double. | |
Any (const char *cstr) | |
Creates an Any object from a c-string. | |
Any (const String &str) | |
Creates an Any object from an acedia::String. | |
Any (const StringList &strList) | |
Creates an Any object from an acedia::StringList. | |
Any (const Any &other) | |
Copy constructor. | |
~Any () | |
Release the internal hold data. | |
Any & | operator= (const Any &other) |
Copy constructor. | |
template<typename T > | |
void | setValue (const T &t) |
set the value to t | |
template<typename T > | |
bool | instanceOf () const throw () |
Ask any object if its internal value is an instance of T . | |
template<typename T > | |
const T & | value () const |
Return the internal value as its native type. | |
template<typename T > | |
T & | value () |
Return the internal value as its native type. | |
MetaClass * | metaClass () const |
Get the MetaClass of the held value. | |
const String & | typeName () const |
Convenient method. Equal to metaClass()->name() . | |
String | toString (bool verbose=false) const |
Convert the internal value to a string. | |
bool | operator== (const Any &other) const |
Compare two Any objects. | |
Static Public Member Functions | |
template<typename T > | |
static Any | from (const T &val) |
"Pseudo" constructor for any non-predefined type. | |
Related Functions | |
(Note that these are not member functions.) | |
ACEDIA_ANNOUNCE(class_name_seq) | |
Use this macro to register a new type to the acedia type system. | |
ACEDIA_DECLARE_CASE_CLASS(seq) | |
Declare a case class with given name and namespace(s). | |
ACEDIA_DECLARE_CASE_TUPLE1(name_seq, Name1, T1) | |
Declare a case tuple with and one element. | |
ACEDIA_DECLARE_CASE_TUPLE2(name_seq, Name1, T1, Name2, T2) | |
Declare a case tuple with and two elements. | |
ACEDIA_DECLARE_CASE_TUPLE3(name_seq, Name1, T1, Name2, T2, Name3, T3) | |
Declare a case tuple with and three elements. | |
ACEDIA_DECLARE_CASE_TUPLE4(name_seq, Name1, T1, Name2, T2, Name3, T3, Name4, T4) | |
Declare a case tuple with and four elements. | |
ACEDIA_DECLARE_CASE_TUPLE5(name_seq, Name1, T1, Name2, T2, Name3, T3, Name4, T4, Name5, T5) | |
Declare a case tuple with and five elements. | |
ACEDIA_DECLARE_CASE_TUPLE6(name_seq, Name1, T1, Name2, T2, Name3, T3, Name4, T4, Name5, T5, Name6, T6) | |
Declare a case tuple with and six elements. | |
ACEDIA_DECLARE_CASE_TUPLE7(name_seq, Name1, T1, Name2, T2, Name3, T3, Name4, T4, Name5, T5, Name6, T6, Name7, T7) | |
Declare a case tuple with and seven elements. | |
ACEDIA_DECLARE_CASE_TUPLE8(name_seq, Name1, T1, Name2, T2, Name3, T3, Name4, T4, Name5, T5, Name6, T6, Name7, T7, Name8, T8) | |
Declare a case tuple with and eight elements. | |
ACEDIA_DECLARE_CASE_TUPLE9(name_seq, Name1, T1, Name2, T2, Name3, T3, Name4, T4, Name5, T5, Name6, T6, Name7, T7, Name8, T8, Name9, T9) | |
Declare a case tuple with and nine elements. |
A class that can hold any value.
In comparison to comparable classes (like boost::any) ensures Any that the held value is serializable.
To make your own class serializable read boost serialization
Any can only store:
Definition at line 122 of file any.hpp.
acedia::Any::Any | ( | const Any & | other | ) |
static Any acedia::Any::from | ( | const T & | val | ) | [inline, static] |
bool acedia::Any::instanceOf | ( | ) | const throw () [inline] |
Ask any object if its internal value is an instance of T
.
This method don't care about inheritance. It only returns true if the held value is an instance of T
. It returns false if T
is a base of the internal type!
MetaClass * acedia::Any::metaClass | ( | ) | const |
bool acedia::Any::operator== | ( | const Any & | other | ) | const |
String acedia::Any::toString | ( | bool | verbose = false |
) | const |
Convert the internal value to a string.
This method can only convert types that provide a specialization of the ToStringConverter template.
verbose | set verbose to true if you want to see all possible informations in the output. |
const String& acedia::Any::typeName | ( | ) | const [inline] |
Convenient method. Equal to metaClass()->name()
.
bool acedia::Any::valid | ( | ) | throw () [inline] |
T& acedia::Any::value | ( | ) | [inline] |
Return the internal value as its native type.
NullPointerException | if isNull() == true | |
ClassCastException | if canConvert<T>() == false |
const T& acedia::Any::value | ( | ) | const [inline] |
Return the internal value as its native type.
NullPointerException | if isNull() == true | |
ClassCastException | if canConvert<T>() == false |
ACEDIA_ANNOUNCE | ( | class_name_seq | ) | [related] |
Use this macro to register a new type to the acedia type system.
The macro uses the boost preprocessor sequences.
Example:
If you want to announce your MyClass
then you have to write: ACEDIA_ANNOUNCE((MyClass))
. Note the double brackets!
If you want to announce your my_namespace::MySecondClass
then you have to write: ACEDIA_ANNOUNCE((my_namespace)(MySecondClass))
and so on.
Definition at line 138 of file announce.hpp.
ACEDIA_DECLARE_CASE_CLASS | ( | seq | ) | [related] |
Declare a case class with given name and namespace(s).
A case class is comparable to atomics in Erlang or case objects in Scala.
This makro also announces the case class.
If you want to pass values to your case class use the ACEDIA_DECLARE_CASE_TUPLE macros.
Definition at line 155 of file announce.hpp.
ACEDIA_DECLARE_CASE_TUPLE1 | ( | name_seq, | |||
Name1, | |||||
T1 | ) | [related] |
Declare a case tuple with and one element.
The resulting class has a getter Name1()
which returns the value of the first element. It's equal to get<0>()
.
Name1
is also used in the toString method of the resulting class to generate a well readable representation of its content.
This makro also announces the case tuple.
name_seq | a sequence that contains all namespaces and the class name | |
Name1 | name of the getter for the first element; must not contain any whitespaces because it is used as a method name (you'll get a compiler error if Name1 contains any whitespace) | |
T1 | type of the element |
ACEDIA_DECLARE_CASE_TUPLE2 | ( | name_seq, | |||
Name1, | |||||
T1, | |||||
Name2, | |||||
T2 | ) | [related] |
Declare a case tuple with and two elements.
ACEDIA_DECLARE_CASE_TUPLE3 | ( | name_seq, | |||
Name1, | |||||
T1, | |||||
Name2, | |||||
T2, | |||||
Name3, | |||||
T3 | ) | [related] |
Declare a case tuple with and three elements.
ACEDIA_DECLARE_CASE_TUPLE4 | ( | name_seq, | |||
Name1, | |||||
T1, | |||||
Name2, | |||||
T2, | |||||
Name3, | |||||
T3, | |||||
Name4, | |||||
T4 | ) | [related] |
Declare a case tuple with and four elements.
ACEDIA_DECLARE_CASE_TUPLE5 | ( | name_seq, | |||
Name1, | |||||
T1, | |||||
Name2, | |||||
T2, | |||||
Name3, | |||||
T3, | |||||
Name4, | |||||
T4, | |||||
Name5, | |||||
T5 | ) | [related] |
Declare a case tuple with and five elements.
ACEDIA_DECLARE_CASE_TUPLE6 | ( | name_seq, | |||
Name1, | |||||
T1, | |||||
Name2, | |||||
T2, | |||||
Name3, | |||||
T3, | |||||
Name4, | |||||
T4, | |||||
Name5, | |||||
T5, | |||||
Name6, | |||||
T6 | ) | [related] |
Declare a case tuple with and six elements.
ACEDIA_DECLARE_CASE_TUPLE7 | ( | name_seq, | |||
Name1, | |||||
T1, | |||||
Name2, | |||||
T2, | |||||
Name3, | |||||
T3, | |||||
Name4, | |||||
T4, | |||||
Name5, | |||||
T5, | |||||
Name6, | |||||
T6, | |||||
Name7, | |||||
T7 | ) | [related] |
Declare a case tuple with and seven elements.
ACEDIA_DECLARE_CASE_TUPLE8 | ( | name_seq, | |||
Name1, | |||||
T1, | |||||
Name2, | |||||
T2, | |||||
Name3, | |||||
T3, | |||||
Name4, | |||||
T4, | |||||
Name5, | |||||
T5, | |||||
Name6, | |||||
T6, | |||||
Name7, | |||||
T7, | |||||
Name8, | |||||
T8 | ) | [related] |
Declare a case tuple with and eight elements.
ACEDIA_DECLARE_CASE_TUPLE9 | ( | name_seq, | |||
Name1, | |||||
T1, | |||||
Name2, | |||||
T2, | |||||
Name3, | |||||
T3, | |||||
Name4, | |||||
T4, | |||||
Name5, | |||||
T5, | |||||
Name6, | |||||
T6, | |||||
Name7, | |||||
T7, | |||||
Name8, | |||||
T8, | |||||
Name9, | |||||
T9 | ) | [related] |
Declare a case tuple with and nine elements.