libcaf
0.13.2
|
libcaf
provides a fully network transparent communication between actors.
More...
Classes | |
class | caf::deserializer |
Technology-independent deserialization interface. More... | |
class | caf::serializer |
Technology-independent serialization interface. More... | |
class | caf::uniform_type_info |
Provides a platform independent type name and a (very primitive) kind of reflection in combination with object. More... | |
Functions | |
const uniform_type_info * | caf::announce (const std::type_info &tinfo, uniform_type_info_ptr utype) |
Adds a new mapping to the type system. More... | |
template<class Member , class Parent , class... Ts> | |
std::pair< Member Parent::*, abstract_uniform_type_info< Member > * > | caf::compound_member (Member Parent::*memptr, const Ts &...xs) |
Creates meta information for a non-trivial Member , whereas xs are the "sub-members" of Member . More... | |
template<class Member , class Parent , class... Ts> | |
std::pair< Member &(Parent::*)(), abstract_uniform_type_info< Member > * > | caf::compound_member (Member &(Parent::*getter)(), const Ts &...xs) |
Creates meta information for a non-trivial Member accessed via the getter member function getter returning a mutable reference, whereas xs are the "sub-members" of Member . More... | |
template<class Parent , class GRes , class SRes , class SArg , class... Ts> | |
std::pair< std::pair< GRes(Parent::*)() const, SRes(Parent::*)(SArg)>, abstract_uniform_type_info< typename std::decay< GRes >::type > * > | caf::compound_member (const std::pair< GRes(Parent::*)() const, SRes(Parent::*)(SArg)> &gspair, const Ts &...xs) |
Creates meta information for a non-trivial Member accessed via the pair of getter and setter member function pointers gspair , whereas xs are the "sub-members" of Member . More... | |
template<class T , class... Ts> | |
const uniform_type_info * | caf::announce (std::string tname, const Ts &...xs) |
Adds a new type mapping for T to the type system using tname as its uniform name and the list of member pointers xs . More... | |
libcaf
provides a fully network transparent communication between actors.
Thus, it needs to serialize and deserialize message objects. Unfortunately, this is not possible using the C++ RTTI system.
Since it is not possible to extend std::type_info,
libcaf` uses its own type abstraction: uniform_type_info.
Unlike `std::type_info::name(), uniform_type_info::name() is guaranteed to return the same name on all supported platforms. Furthermore, it allows to create an instance of a type by name:
However, you should rarely if ever need to use object or uniform_type_info.
There is one exception, though, where you need to care about the type system: using custom data types in messages. The source code below compiles fine, but crashes with an exception during runtime.
Depending on your platform, the error message looks somewhat like this:
terminate called after throwing an instance of std::runtime_error
what(): uniform_type_info::by_type_info(): foo is an unknown typeid name
The user-defined struct foo
is not known by the type system. Thus, foo
cannot be serialized and is rejected.
Fortunately, there is an easy way to add foo
the type system, without needing to implement serialize/deserialize by yourself:
announce() takes the class as template parameter and pointers to all members (or getter/setter pairs) as arguments. This works for all primitive data types and STL compliant containers. See the announce example 1, example 2, example 3 and example 4 for more details.
Obviously, there are limitations. If your class does implement an unsupported data structure, you have to implement serialize/deserialize by yourself. Example 5 shows, how to announce a tree data structure to the type system.
const uniform_type_info* caf::announce | ( | const std::type_info & | tinfo, |
uniform_type_info_ptr | utype | ||
) |
Adds a new mapping to the type system.
Returns utype.get()
on success, otherwise a pointer to the previously installed singleton.
announce
is not thead-safe! const uniform_type_info* caf::announce | ( | std::string | tname, |
const Ts &... | xs | ||
) |
Adds a new type mapping for T
to the type system using tname
as its uniform name and the list of member pointers xs
.
announce
is not thead-safe! std::pair<Member Parent::*, abstract_uniform_type_info<Member>*> caf::compound_member | ( | Member Parent::* | memptr, |
const Ts &... | xs | ||
) |
Creates meta information for a non-trivial Member
, whereas xs
are the "sub-members" of Member
.
std::pair<Member& (Parent::*)(), abstract_uniform_type_info<Member>*> caf::compound_member | ( | Member &(Parent::*)() | getter, |
const Ts &... | xs | ||
) |
Creates meta information for a non-trivial Member
accessed via the getter member function getter
returning a mutable reference, whereas xs
are the "sub-members" of Member
.
std::pair<std::pair<GRes (Parent::*)() const, SRes (Parent::*)(SArg)>, abstract_uniform_type_info<typename std::decay<GRes>::type>*> caf::compound_member | ( | const std::pair< GRes(Parent::*)() const, SRes(Parent::*)(SArg)> & | gspair, |
const Ts &... | xs | ||
) |
Creates meta information for a non-trivial Member
accessed via the pair of getter and setter member function pointers gspair
, whereas xs
are the "sub-members" of Member
.