acedia::Any Class Reference

A class that can hold any value. More...

#include <any.hpp>

List of all members.

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.
Anyoperator= (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.
MetaClassmetaClass () const
 Get the MetaClass of the held value.
const StringtypeName () 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.

Detailed Description

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:

Note:
Any is not thread safe (except if you store immutable types)
Examples:

tuples.cpp.

Definition at line 122 of file any.hpp.


Constructor & Destructor Documentation

acedia::Any::Any ( const Any other  ) 

Copy constructor.

Note:
this method causes a deep copy of the stored value

Definition at line 73 of file any.cpp.


Member Function Documentation

template<typename T >
static Any acedia::Any::from ( const T &  val  )  [inline, static]

"Pseudo" constructor for any non-predefined type.

This method creates an instance of Any, calls setValue<T>(val) and returns it.

Definition at line 347 of file any.hpp.

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

Returns:
true if the type of the held value is equal to T; otherwise false

Definition at line 285 of file any.hpp.

MetaClass * acedia::Any::metaClass (  )  const

Get the MetaClass of the held value.

This method return always a valid MetaClass object; if valid() == false then the MetaClass of "void" is returned.

Returns:
the MetaClass object of the interval value

Definition at line 94 of file any.cpp.

Any & acedia::Any::operator= ( const Any other  ) 

Copy constructor.

Note:
this method causes a deep copy of other

Definition at line 80 of file any.cpp.

bool acedia::Any::operator== ( const Any other  )  const

Compare two Any objects.

Returns:
true if both metaClass and value are equal

Definition at line 127 of file any.cpp.

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.

Parameters:
verbose set verbose to true if you want to see all possible informations in the output.
Examples:
tuples.cpp.

Definition at line 121 of file any.cpp.

const String& acedia::Any::typeName (  )  const [inline]

Convenient method. Equal to metaClass()->name().

Returns:
the type name of the internal value

Definition at line 338 of file any.hpp.

bool acedia::Any::valid (  )  throw () [inline]

Test if this object contains valid data.

Returns:
true if this object contain any data; otherwise false

Definition at line 170 of file any.hpp.

template<typename T >
T& acedia::Any::value (  )  [inline]

Return the internal value as its native type.

Returns:
the value of this object as native type T
Exceptions:
NullPointerException if isNull() == true
ClassCastException if canConvert<T>() == false

Definition at line 316 of file any.hpp.

template<typename T >
const T& acedia::Any::value (  )  const [inline]

Return the internal value as its native type.

Returns:
the value of this object as native type T
Exceptions:
NullPointerException if isNull() == true
ClassCastException if canConvert<T>() == false

Definition at line 304 of file any.hpp.


Friends And Related Function Documentation

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.

Note:
Don't use this macro inside a namespace and always use the full class name (with all namespaces).

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.

Note:
don't use this makro within a namespace
See also:
ACEDIA_ANNOUNCE

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.

Parameters:
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
Note:
don't use this makro within a namespace
See also:
ACEDIA_ANNOUNCE
ACEDIA_DECLARE_CASE_CLASS
Examples:
networkPong.cpp, pong.cpp, and timedPong.cpp.

Definition at line 382 of file tuple.hpp.

ACEDIA_DECLARE_CASE_TUPLE2 ( name_seq,
Name1,
T1,
Name2,
T2   )  [related]

Declare a case tuple with and two elements.

See also:
ACEDIA_DECLARE_CASE_TUPLE1
Examples:
tuples.cpp.

Definition at line 389 of file tuple.hpp.

ACEDIA_DECLARE_CASE_TUPLE3 ( name_seq,
Name1,
T1,
Name2,
T2,
Name3,
T3   )  [related]

Declare a case tuple with and three elements.

See also:
ACEDIA_DECLARE_CASE_TUPLE1
Examples:
tuples.cpp.

Definition at line 396 of file tuple.hpp.

ACEDIA_DECLARE_CASE_TUPLE4 ( name_seq,
Name1,
T1,
Name2,
T2,
Name3,
T3,
Name4,
T4   )  [related]

Declare a case tuple with and four elements.

See also:
ACEDIA_DECLARE_CASE_TUPLE1

Definition at line 403 of file tuple.hpp.

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.

See also:
ACEDIA_DECLARE_CASE_TUPLE1

Definition at line 410 of file tuple.hpp.

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.

See also:
ACEDIA_DECLARE_CASE_TUPLE1

Definition at line 417 of file tuple.hpp.

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.

See also:
ACEDIA_DECLARE_CASE_TUPLE1

Definition at line 424 of file tuple.hpp.

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.

See also:
ACEDIA_DECLARE_CASE_TUPLE1

Definition at line 431 of file tuple.hpp.

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.

See also:
ACEDIA_DECLARE_CASE_TUPLE1

Definition at line 438 of file tuple.hpp.


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.2