Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
2e704f7e
Commit
2e704f7e
authored
May 11, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed typed calculator example
parent
8f2cd321
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
12 deletions
+15
-12
examples/CMakeLists.txt
examples/CMakeLists.txt
+6
-5
examples/message_passing/typed_calculator.cpp
examples/message_passing/typed_calculator.cpp
+9
-7
No files found.
examples/CMakeLists.txt
View file @
2e704f7e
...
@@ -21,14 +21,15 @@ add(. aout)
...
@@ -21,14 +21,15 @@ add(. aout)
add
(
. hello_world
)
add
(
. hello_world
)
# basic message passing primitives
# basic message passing primitives
add
(
message_passing cell
)
add
(
message_passing divider
)
add
(
message_passing request
)
add
(
message_passing promises
)
add
(
message_passing calculator
)
add
(
message_passing calculator
)
add
(
message_passing cell
)
add
(
message_passing dancing_kirby
)
add
(
message_passing delegating
)
add
(
message_passing delegating
)
add
(
message_passing divider
)
add
(
message_passing fixed_stack
)
add
(
message_passing fixed_stack
)
add
(
message_passing dancing_kirby
)
add
(
message_passing promises
)
add
(
message_passing request
)
add
(
message_passing typed_calculator
)
# dynamic behavior changes using 'become'
# dynamic behavior changes using 'become'
add
(
dynamic_behavior skip_messages
)
add
(
dynamic_behavior skip_messages
)
...
...
examples/message_passing/typed_calculator.cpp
View file @
2e704f7e
...
@@ -32,11 +32,12 @@ calculator_type::behavior_type typed_calculator_fun(calculator_type::pointer) {
...
@@ -32,11 +32,12 @@ calculator_type::behavior_type typed_calculator_fun(calculator_type::pointer) {
}
}
class
typed_calculator_class
:
public
calculator_type
::
base
{
class
typed_calculator_class
:
public
calculator_type
::
base
{
p
rotected
:
p
ublic
:
typed_calculator_class
(
actor_config
&
cfg
)
:
calculator_type
::
base
(
cfg
)
{
typed_calculator_class
(
actor_config
&
cfg
)
:
calculator_type
::
base
(
cfg
)
{
// nop
// nop
}
}
protected:
behavior_type
make_behavior
()
override
{
behavior_type
make_behavior
()
override
{
return
{
return
{
[](
plus_atom
,
int
x
,
int
y
)
{
[](
plus_atom
,
int
x
,
int
y
)
{
...
@@ -52,10 +53,10 @@ protected:
...
@@ -52,10 +53,10 @@ protected:
void
tester
(
event_based_actor
*
self
,
const
calculator_type
&
testee
)
{
void
tester
(
event_based_actor
*
self
,
const
calculator_type
&
testee
)
{
self
->
link_to
(
testee
);
self
->
link_to
(
testee
);
// first test: 2 + 1 = 3
// first test: 2 + 1 = 3
self
->
request
(
testee
,
plus_atom
::
value
,
2
,
1
).
then
(
self
->
request
(
testee
,
infinite
,
plus_atom
::
value
,
2
,
1
).
then
(
[
=
](
result_atom
,
int
r1
)
{
[
=
](
result_atom
,
int
r1
)
{
// second test: 2 - 1 = 1
// second test: 2 - 1 = 1
self
->
request
(
testee
,
minus_atom
::
value
,
2
,
1
).
then
(
self
->
request
(
testee
,
infinite
,
minus_atom
::
value
,
2
,
1
).
then
(
[
=
](
result_atom
,
int
r2
)
{
[
=
](
result_atom
,
int
r2
)
{
// both tests succeeded
// both tests succeeded
if
(
r1
==
3
&&
r2
==
1
)
{
if
(
r1
==
3
&&
r2
==
1
)
{
...
@@ -74,13 +75,14 @@ void tester(event_based_actor* self, const calculator_type& testee) {
...
@@ -74,13 +75,14 @@ void tester(event_based_actor* self, const calculator_type& testee) {
);
);
}
}
}
// namespace <anonymous>
void
caf_main
(
actor_system
&
system
)
{
int
main
()
{
actor_system
system
;
// test function-based impl
// test function-based impl
system
.
spawn
(
tester
,
system
.
spawn
(
typed_calculator_fun
));
system
.
spawn
(
tester
,
system
.
spawn
(
typed_calculator_fun
));
system
.
await_all_actors_done
();
system
.
await_all_actors_done
();
// test class-based impl
// test class-based impl
system
.
spawn
(
tester
,
system
.
spawn
<
typed_calculator_class
>
());
system
.
spawn
(
tester
,
system
.
spawn
<
typed_calculator_class
>
());
}
}
}
// namespace <anonymous>
CAF_MAIN
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment