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 ...@@ -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. 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^. 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. 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. Sending the same message to multiple actors does not result in copying the data several times.
Read Section \ref{Sec::Tuples} to learn more about \lib's copy-on-write optimization for tuples.
\end{itemize} \end{itemize}
\subsection{Constructors of Class-based Actors} \subsection{Constructors of Class-based Actors}
......
...@@ -121,9 +121,11 @@ void tester(event_based_actor* self, const calculator_type& testee) { ...@@ -121,9 +121,11 @@ void tester(event_based_actor* self, const calculator_type& testee) {
int main() { int main() {
// announce custom message types // announce custom message types
announce<shutdown_request>(); announce<shutdown_request>("shutdown_request");
announce<plus_request>(&plus_request::a, &plus_request::b); announce<plus_request>("plus_request",
announce<minus_request>(&minus_request::a, &minus_request::b); &plus_request::a, &plus_request::b);
announce<minus_request>("minus_request",
&minus_request::a, &minus_request::b);
// test function-based impl // test function-based impl
spawn(tester, spawn_typed(typed_calculator)); spawn(tester, spawn_typed(typed_calculator));
await_all_actors_done(); await_all_actors_done();
......
...@@ -27,14 +27,15 @@ using namespace cppa; ...@@ -27,14 +27,15 @@ using namespace cppa;
struct foo { int a; int b; }; struct foo { int a; int b; };
int main() { int main() {
announce<foo>(&foo::a, &foo::b); announce<foo>("foo", &foo::a, &foo::b);
// ... foo can now safely be used in messages ... // ... foo can now safely be used in messages ...
} }
\end{lstlisting} \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. 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. This works for all primitive data types and STL compliant containers.
See the announce examples 1 -- 4 of the standard distribution for more details. 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