\section{Platform-Independent Type System}
\label{Sec::TypeSystem}

\lib provides a fully network transparent communication between actors.
Thus, \lib needs to serialize and deserialize messages.
Unfortunately, this is not possible using the RTTI system of C++.
\lib uses its own RTTI based on the class \lstinline^uniform_type_info^, since it is not possible to extend \lstinline^std::type_info^.

Unlike \lstinline^std::type_info::name()^, \lstinline^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.

\begin{lstlisting}
// creates a signed, 32 bit integer
uniform_value i = uniform_typeid<int>()->create();
\end{lstlisting}

You should rarely, if ever, need to use \lstinline^uniform_value^ or \lstinline^uniform_type_info^.
The type \lstinline^uniform_value^ stores a type-erased pointer along with the associated \lstinline^uniform_type_info^.
The sole purpose of this simple abstraction is to enable the pattern matching engine of \lib to query the type information and then dispatch the value to a message handler.
When using a \lstinline^message_builder^, each element is stored as a \lstinline^uniform_value^.

\subsection{User-Defined Data Types in Messages}
\label{Sec::TypeSystem::UserDefined}

All user-defined types must be explicitly ``announced'' so that \lib can (de)serialize them correctly, as shown in the example below.

\begin{lstlisting}
#include "caf/all.hpp"

struct foo { int a; int b; };

int main() {
  caf::announce<foo>("foo", &foo::a, &foo::b);
  // ... foo can now safely be used in messages ...
}
\end{lstlisting}

Without announcing \lstinline^foo^, \lib is not able to (de)serialize instances of it.
The function \lstinline^announce()^ takes the class as template parameter.
The first argument to the function always is the type name followed by pointers to all members (or getter/setter pairs).
This works for all primitive data types and STL compliant containers.
See the announce examples 1 -- 4 of the standard distribution for more details.

Obviously, there are limitations.
You have to implement serialize/deserialize by yourself if your class does implement an unsupported data structure.
See \lstinline^announce_example_5.cpp^ in the examples folder.
