Commit b7159f4d authored by neverlord's avatar neverlord

hello world example

parent ac6327a0
...@@ -44,4 +44,10 @@ Makefile ...@@ -44,4 +44,10 @@ Makefile
unit_testing/Makefile unit_testing/Makefile
libcppa.so* libcppa.so*
blob/cppatest blob/cppatest
callgrind.out.* callgrind.out*
examples/announce_example_1
examples/announce_example_2
examples/announce_example_3
examples/announce_example_4
examples/announce_example_5
examples/hello_world_example
...@@ -234,3 +234,4 @@ examples/announce_example_2.cpp ...@@ -234,3 +234,4 @@ examples/announce_example_2.cpp
examples/announce_example_3.cpp examples/announce_example_3.cpp
examples/announce_example_4.cpp examples/announce_example_4.cpp
examples/announce_example_5.cpp examples/announce_example_5.cpp
examples/hello_world_example.cpp
...@@ -64,6 +64,19 @@ ...@@ -64,6 +64,19 @@
* @section Intro Introduction * @section Intro Introduction
* *
* This library provides an implementation of the Actor model for C++. * This library provides an implementation of the Actor model for C++.
* It uses a network transparent messaging system to ease development
* of both concurrent and distributed software using C++.
*
* @p libcppa uses a thread pool to schedule actors by default.
* Individual actors can be spawned (created) with a special flag to run in
* an own thread if needed.
*
* In @p libcppa, each context is an actor. Even main is implicitly
* converted to an actor if needed.
*
* @subsection IntroHelloWorld Hello World Example
*
* @include hello_world_example.cpp
* *
* @section GettingStarted Getting started with libcppa * @section GettingStarted Getting started with libcppa
* *
...@@ -86,7 +99,7 @@ ...@@ -86,7 +99,7 @@
* @p libcppa uses a copy-on-write optimization for its message * @p libcppa uses a copy-on-write optimization for its message
* passing implementation. * passing implementation.
* *
* {@link tuple Tuples} should @b always be used used with by-value semantic, * {@link tuple Tuples} should @b always be used with by-value semantic,
* since tuples use a copy-on-write smart pointer internally. Let's assume two * since tuples use a copy-on-write smart pointer internally. Let's assume two
* tuple @p x and @p y, whereas @p y is a copy of @p x: * tuple @p x and @p y, whereas @p y is a copy of @p x:
* *
...@@ -145,6 +158,11 @@ ...@@ -145,6 +158,11 @@
* // x has the type tuple<std::string, std::string> * // x has the type tuple<std::string, std::string>
* auto x = make_tuple("hello", "tuple"); * auto x = make_tuple("hello", "tuple");
* *
* receive
* (
* // equal to on(std::string("hello actor!"))
* on("hello actor!") >> []() { }
* );
* @endcode * @endcode
*/ */
...@@ -532,7 +550,7 @@ local_actor* operator<<(local_actor* whom, any_tuple&& what); ...@@ -532,7 +550,7 @@ local_actor* operator<<(local_actor* whom, any_tuple&& what);
#endif #endif
template<class C, typename Arg0, typename... Args> template<typename Arg0, typename... Args>
void reply(const Arg0& arg0, const Args&... args) void reply(const Arg0& arg0, const Args&... args)
{ {
send(self()->mailbox().last_sender(), arg0, args...); send(self()->mailbox().last_sender(), arg0, args...);
......
...@@ -117,7 +117,7 @@ constexpr typename detail::boxed<T>::type val() ...@@ -117,7 +117,7 @@ constexpr typename detail::boxed<T>::type val()
//constexpr detail::boxed<anything> any_vals = detail::boxed<anything>(); //constexpr detail::boxed<anything> any_vals = detail::boxed<anything>();
constexpr anything any_vals = anything(); constexpr anything any_vals = anything();
constexpr detail::on_the_fly_invoke_rule_builder on_param_match() constexpr detail::on_the_fly_invoke_rule_builder on_arg_match()
{ {
return { }; return { };
} }
......
...@@ -7,13 +7,15 @@ noinst_PROGRAMS = announce_example_1 \ ...@@ -7,13 +7,15 @@ noinst_PROGRAMS = announce_example_1 \
announce_example_2 \ announce_example_2 \
announce_example_3 \ announce_example_3 \
announce_example_4 \ announce_example_4 \
announce_example_5 announce_example_5 \
hello_world_example
announce_example_1_SOURCES = announce_example_1.cpp announce_example_1_SOURCES = announce_example_1.cpp
announce_example_2_SOURCES = announce_example_2.cpp announce_example_2_SOURCES = announce_example_2.cpp
announce_example_3_SOURCES = announce_example_3.cpp announce_example_3_SOURCES = announce_example_3.cpp
announce_example_4_SOURCES = announce_example_4.cpp announce_example_4_SOURCES = announce_example_4.cpp
announce_example_5_SOURCES = announce_example_5.cpp announce_example_5_SOURCES = announce_example_5.cpp
hello_world_example_SOURCES = hello_world_example.cpp
EXAMPLES_LIBS = $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB) -L../.libs/ -lcppa EXAMPLES_LIBS = $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB) -L../.libs/ -lcppa
...@@ -22,4 +24,5 @@ announce_example_2_LDADD = $(EXAMPLES_LIBS) ...@@ -22,4 +24,5 @@ announce_example_2_LDADD = $(EXAMPLES_LIBS)
announce_example_3_LDADD = $(EXAMPLES_LIBS) announce_example_3_LDADD = $(EXAMPLES_LIBS)
announce_example_4_LDADD = $(EXAMPLES_LIBS) announce_example_4_LDADD = $(EXAMPLES_LIBS)
announce_example_5_LDADD = $(EXAMPLES_LIBS) announce_example_5_LDADD = $(EXAMPLES_LIBS)
hello_world_example_LDADD = $(EXAMPLES_LIBS)
#include <string>
#include <iostream>
#include "cppa/cppa.hpp"
using namespace cppa;
void echo_actor()
{
// wait for a message
receive
(
// invoke this lambda expression if we receive a string
on<std::string>() >> [](const std::string& what)
{
// prints "Hello World!"
std::cout << what << std::endl;
// reply "!dlroW olleH"
reply(std::string(what.rbegin(), what.rend()));
}
);
}
int main()
{
// create a new actor that invokes the function echo_actor
auto hello_actor = spawn(echo_actor);
// send "Hello World!" to our new actor
// note: libcppa converts string literals to std::string objects
send(hello_actor, "Hello World!");
// wait for a response and print it
receive
(
on<std::string>() >> [](const std::string& what)
{
std::cout << what << std::endl;
}
);
// wait until all other actors we've spawned are done
await_all_others_done();
// done
return 0;
}
...@@ -622,7 +622,7 @@ EXCLUDE_SYMBOLS = ...@@ -622,7 +622,7 @@ EXCLUDE_SYMBOLS =
# directories that contain example code fragments that are included (see # directories that contain example code fragments that are included (see
# the \include command). # the \include command).
EXAMPLE_PATH = documentation EXAMPLE_PATH = examples
# If the value of the EXAMPLE_PATH tag contains directories, you can use the # If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
......
...@@ -83,7 +83,7 @@ size_t test__pattern() ...@@ -83,7 +83,7 @@ size_t test__pattern()
CPPA_CHECK_EQUAL(value, 1); CPPA_CHECK_EQUAL(value, 1);
lambda_invoked[4] = true; lambda_invoked[4] = true;
}, },
on_param_match() >> [&](double v1, const float& v2) on_arg_match() >> [&](double v1, const float& v2)
{ {
CPPA_CHECK_EQUAL(v1, 1.0); CPPA_CHECK_EQUAL(v1, 1.0);
CPPA_CHECK_EQUAL(v2, 2.0f); CPPA_CHECK_EQUAL(v2, 2.0f);
......
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