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
cc944f64
Commit
cc944f64
authored
Jul 09, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine API of stateful actors
parent
8d96abe9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
12 deletions
+21
-12
libcaf_core/caf/experimental/stateful_actor.hpp
libcaf_core/caf/experimental/stateful_actor.hpp
+17
-8
libcaf_core/test/stateful_actor.cpp
libcaf_core/test/stateful_actor.cpp
+4
-4
No files found.
libcaf_core/caf/experimental/stateful_actor.hpp
View file @
cc944f64
...
...
@@ -28,10 +28,15 @@
namespace
caf
{
namespace
experimental
{
/// An event-based actor with managed state. The state is constructed
/// before `make_behavior` will get called and destroyed after the
/// actor called `quit`. This state management brakes cycles and
/// allows actors to automatically release ressources as soon
/// as possible.
template
<
class
State
,
class
Base
=
event_based_actor
>
class
stateful_actor
:
public
Base
{
public:
stateful_actor
()
{
stateful_actor
()
:
state
(
state_
)
{
// nop
}
...
...
@@ -39,19 +44,23 @@ public:
// nop
}
void
initialize
()
override
{
cr_state
(
this
);
Base
::
initialize
();
}
/// Destroys the state of this actor (no further overriding allowed).
void
on_exit
()
override
final
{
state_
.
~
State
();
}
State
&
state
()
{
return
state_
;
/// A reference to the actor's state.
State
&
state
;
/// @cond PRIVATE
void
initialize
()
override
{
cr_state
(
this
);
Base
::
initialize
();
}
/// @endcond
private:
template
<
class
T
>
typename
std
::
enable_if
<
std
::
is_constructible
<
State
,
T
>::
value
>::
type
...
...
libcaf_core/test/stateful_actor.cpp
View file @
cc944f64
...
...
@@ -43,10 +43,10 @@ struct counter {
behavior
adder
(
stateful_actor
<
counter
>*
self
)
{
return
{
[
=
](
add_atom
,
int
x
)
{
self
->
state
()
.
value
+=
x
;
self
->
state
.
value
+=
x
;
},
[
=
](
get_atom
)
{
return
self
->
state
()
.
value
;
return
self
->
state
.
value
;
}
};
}
...
...
@@ -62,10 +62,10 @@ typed_adder_actor::behavior_type
typed_adder
(
typed_adder_actor
::
stateful_pointer
<
counter
>
self
)
{
return
{
[
=
](
add_atom
,
int
x
)
{
self
->
state
()
.
value
+=
x
;
self
->
state
.
value
+=
x
;
},
[
=
](
get_atom
)
{
return
self
->
state
()
.
value
;
return
self
->
state
.
value
;
}
};
}
...
...
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