libcppa  Version 0.1
Classes | Enumerations | Functions
libcppa's platform-independent type system.

Classes

class  cppa::deserializer
 Technology-independent deserialization interface. More...
class  cppa::primitive_variant
 An union container for primitive data types. More...
class  cppa::serializer
 Technology-independent serialization interface. More...
class  cppa::uniform_type_info
 Provides a platform independent type name and a (very primitive) kind of reflection in combination with object. More...

Enumerations

enum  cppa::primitive_type {
  cppa::pt_int8,
  cppa::pt_int16,
  cppa::pt_int32,
  cppa::pt_int64,
  cppa::pt_uint8,
  cppa::pt_uint16,
  cppa::pt_uint32,
  cppa::pt_uint64,
  cppa::pt_float,
  cppa::pt_double,
  cppa::pt_long_double,
  cppa::pt_u8string,
  cppa::pt_u16string,
  cppa::pt_u32string,
  cppa::pt_null
}

Functions

bool cppa::announce (const std::type_info &tinfo, uniform_type_info *utype)
template<class C , class Parent , typename... Args>
std::pair< C Parent::*,
util::abstract_uniform_type_info
< C > * > 
cppa::compound_member (C Parent::*c_ptr, const Args &...args)
template<typename T , typename... Args>
bool cppa::announce (const Args &...args)
constexpr const char * cppa::primitive_type_name (primitive_type ptype)
template<typename T >
const T & get (const primitive_variant &pv)
template<typename T >
T & get_ref (primitive_variant &pv)
template<primitive_type PT>
const T & get_ref (const primitive_variant &pv)

Detailed Description

libcppa provides a fully network transparent communication between actors. Thus, libcppa 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, libcppa 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:

 // creates a signed, 32 bit integer
 cppa::object i = cppa::uniform_type_info::by_name("@i32")->create();

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 libcppa's type system: using custom data types in messages. The source code below compiles fine, but crashes with an exception during runtime.

 #include "cppa/cppa.hpp"
 using namespace cppa;

 struct foo { int a; int b; };

 int main()
 {
     send(self(), foo{1,2});
     return 0;
 }

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 libcppa type system. Thus, libcppa is unable to serialize/deserialize foo and rejects it.

Fortunately, there is an easy way to add foo the type system, without needing to implement serialize/deserialize by yourself:

 cppa::announce<foo>(&foo::a, &foo::b);

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 libcppa type system.


Enumeration Type Documentation

enum primitive_type [related]

Represents a type flag of primitive_variant.

Includes integers (signed and unsigned), floating points and unicode strings (std::string, std::u16string and std::u32string).

Enumerator:
pt_int8 

equivalent of std::int8_t

pt_int16 

equivalent of std::int16_t

pt_int32 

equivalent of std::int32_t

pt_int64 

equivalent of std::int64_t

pt_uint8 

equivalent of std::uint8_t

pt_uint16 

equivalent of std::uint16_t

pt_uint32 

equivalent of std::uint32_t

pt_uint64 

equivalent of std::uint64_t

pt_float 

equivalent of float

pt_double 

equivalent of double

pt_long_double 

equivalent of long double

pt_u8string 

equivalent of std::string

pt_u16string 

equivalent of std::u16string

pt_u32string 

equivalent of std::u32string

pt_null 

equivalent of void


Function Documentation

bool cppa::announce ( const std::type_info &  tinfo,
uniform_type_info *  utype 
)

Adds a new type mapping to the libcppa type system.

Parameters:
tinfoC++ RTTI for the new type
utypeCorresponding uniform_type_info instance.
Returns:
true if uniform_type was added as known instance (mapped to plain_type); otherwise false is returned and uniform_type was deleted.
Examples:
announce_example_5.cpp.
template<typename T , typename... Args>
bool cppa::announce ( const Args &...  args)

Adds a new type mapping for T to the libcppa type system.

Parameters:
argsMembers of T.
Returns:
true if T was added to the libcppa type system; otherwise false.
template<class C , class Parent , typename... Args>
std::pair<C Parent::*, util::abstract_uniform_type_info<C>*> cppa::compound_member ( C Parent::*  c_ptr,
const Args &...  args 
)

Creates meta informations for a non-trivial member C.

Parameters:
c_ptrPointer to the non-trivial member.
args"Sub-members" of c_ptr
See also:
announce example 4
Returns:
A pair of c_ptr and the created meta informations.
template<typename T >
const T & get ( const primitive_variant pv) [related]

Casts a primitive variant to its C++ type.

Parameters:
pvA primitive variant of type T.
Returns:
A const reference to the value of pv of type T.
Exceptions:
<tt>std::logic_error</tt>if pv is not of type T.
template<typename T >
T & get_ref ( primitive_variant pv) [related]

Casts a non-const primitive variant to its C++ type.

Parameters:
pvA primitive variant of type T.
Returns:
A reference to the value of pv of type T.
Exceptions:
<tt>std::logic_error</tt>if pv is not of type T.
template<primitive_type PT>
const T & get_ref ( const primitive_variant pv) [related]

Casts a primitive variant to its C++ type.

Template Parameters:
TC++ type equivalent of PT.
Parameters:
pvA primitive variant of type T.
Returns:
A const reference to the value of pv of type T.
constexpr const char* cppa::primitive_type_name ( primitive_type  ptype)

Maps a primitive_type value to its name.

Parameters:
ptypeRequestet primitive_type.
Returns:
A C-string representation of ptype.