Commit 1e63cdaa authored by Dominik Charousset's avatar Dominik Charousset

Update manual entries for `announce`

parent 8002ff4f
......@@ -43,8 +43,7 @@ Accessing shared memory segments concurrently can cause undefined behavior that
However, sharing \textit{data} between actors is fine, as long as the data is \textit{immutable} and its lifetime is guaranteed to outlive all actors.
The simplest way to meet the lifetime guarantee is by storing the data in smart pointers such as \lstinline^std::shared_ptr^.
Nevertheless, the recommended way of sharing informations is message passing.
Sending data to multiple actors does not necessarily result in copying the data several times.
Read Section \ref{Sec::Tuples} to learn more about \lib's copy-on-write optimization for tuples.
Sending the same message to multiple actors does not result in copying the data several times.
\end{itemize}
\subsection{Constructors of Class-based Actors}
......
......@@ -121,9 +121,11 @@ void tester(event_based_actor* self, const calculator_type& testee) {
int main() {
// announce custom message types
announce<shutdown_request>();
announce<plus_request>(&plus_request::a, &plus_request::b);
announce<minus_request>(&minus_request::a, &minus_request::b);
announce<shutdown_request>("shutdown_request");
announce<plus_request>("plus_request",
&plus_request::a, &plus_request::b);
announce<minus_request>("minus_request",
&minus_request::a, &minus_request::b);
// test function-based impl
spawn(tester, spawn_typed(typed_calculator));
await_all_actors_done();
......
......@@ -27,14 +27,15 @@ using namespace cppa;
struct foo { int a; int b; };
int main() {
announce<foo>(&foo::a, &foo::b);
announce<foo>("foo", &foo::a, &foo::b);
// ... foo can now safely be used in messages ...
}
\end{lstlisting}
Without the \lstinline^announce^ function call, the example program would terminate with an exception, because \lib rejects all types without available runtime type information.
\lstinline^announce()^ takes the class as template parameter and pointers to all members (or getter/setter pairs) as arguments.
\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.
......
No preview for this file type
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment