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
d8b30f1c
Commit
d8b30f1c
authored
Jun 23, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix exception handling in announce_1
parent
a95ded47
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
31 deletions
+32
-31
examples/type_system/announce_1.cpp
examples/type_system/announce_1.cpp
+32
-31
No files found.
examples/type_system/announce_1.cpp
View file @
d8b30f1c
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include "caf/binary_deserializer.hpp"
#include "caf/binary_deserializer.hpp"
using
std
::
cout
;
using
std
::
cout
;
using
std
::
cerr
;
using
std
::
endl
;
using
std
::
endl
;
using
std
::
vector
;
using
std
::
vector
;
...
@@ -21,8 +22,7 @@ struct foo {
...
@@ -21,8 +22,7 @@ struct foo {
// announce requires foo to have the equal operator implemented
// announce requires foo to have the equal operator implemented
bool
operator
==
(
const
foo
&
lhs
,
const
foo
&
rhs
)
{
bool
operator
==
(
const
foo
&
lhs
,
const
foo
&
rhs
)
{
return
lhs
.
a
==
rhs
.
a
return
lhs
.
a
==
rhs
.
a
&&
lhs
.
b
==
rhs
.
b
;
&&
lhs
.
b
==
rhs
.
b
;
}
}
// a pair of two ints
// a pair of two ints
...
@@ -37,7 +37,7 @@ struct foo2 {
...
@@ -37,7 +37,7 @@ struct foo2 {
vector
<
vector
<
double
>>
b
;
vector
<
vector
<
double
>>
b
;
};
};
bool
operator
==
(
const
foo2
&
lhs
,
const
foo2
&
rhs
)
{
bool
operator
==
(
const
foo2
&
lhs
,
const
foo2
&
rhs
)
{
return
lhs
.
a
==
rhs
.
a
&&
lhs
.
b
==
rhs
.
b
;
return
lhs
.
a
==
rhs
.
a
&&
lhs
.
b
==
rhs
.
b
;
}
}
...
@@ -74,40 +74,42 @@ void testee(event_based_actor* self, size_t remaining) {
...
@@ -74,40 +74,42 @@ void testee(event_based_actor* self, size_t remaining) {
}
}
int
main
(
int
,
char
**
)
{
int
main
(
int
,
char
**
)
{
// announces foo to the libcaf type system;
// announces foo to the libcaf type system;
// the function expects member pointers to all elements of foo
// the function expects member pointers to all elements of foo
announce
<
foo
>
(
"foo"
,
&
foo
::
a
,
&
foo
::
b
);
announce
<
foo
>
(
"foo"
,
&
foo
::
a
,
&
foo
::
b
);
// announce foo2 to the libcaf type system,
// announce foo2 to the libcaf type system,
// note that recursive containers are managed automatically by libcaf
// note that recursive containers are managed automatically by libcaf
announce
<
foo2
>
(
"foo2"
,
&
foo2
::
a
,
&
foo2
::
b
);
announce
<
foo2
>
(
"foo2"
,
&
foo2
::
a
,
&
foo2
::
b
);
// serialization can throw if types are not announced properly
try
{
// init some test data
foo2
vd
;
foo2
vd
;
vd
.
a
=
5
;
vd
.
a
=
5
;
vd
.
b
.
resize
(
1
);
vd
.
b
.
resize
(
1
);
vd
.
b
.
back
().
push_back
(
42
);
vd
.
b
.
back
().
push_back
(
42
);
// serialize test data
vector
<
char
>
buf
;
vector
<
char
>
buf
;
binary_serializer
bs
(
std
::
back_inserter
(
buf
));
binary_serializer
bs
(
std
::
back_inserter
(
buf
));
bs
<<
vd
;
bs
<<
vd
;
// deserialize written test data from buffer
binary_deserializer
bd
(
buf
.
data
(),
buf
.
size
());
binary_deserializer
bd
(
buf
.
data
(),
buf
.
size
());
foo2
vd2
;
foo2
vd2
;
uniform_typeid
<
foo2
>
()
->
deserialize
(
&
vd2
,
&
bd
);
uniform_typeid
<
foo2
>
()
->
deserialize
(
&
vd2
,
&
bd
);
// deserialized data must be equal to original input
assert
(
vd
==
vd2
);
assert
(
vd
==
vd2
);
// announce std::pair<int, int> to the type system
// announce std::pair<int, int> to the type system
announce
<
foo_pair
>
(
"foo_pair"
,
&
foo_pair
::
first
,
&
foo_pair
::
second
);
announce
<
foo_pair
>
(
"foo_pair"
,
&
foo_pair
::
first
,
&
foo_pair
::
second
);
// libcaf returns the same uniform_type_info
// libcaf returns the same uniform_type_info
// instance for the type aliases foo_pair and foo_pair2
// instance for the type aliases foo_pair and foo_pair2
assert
(
uniform_typeid
<
foo_pair
>
()
==
uniform_typeid
<
foo_pair2
>
());
assert
(
uniform_typeid
<
foo_pair
>
()
==
uniform_typeid
<
foo_pair2
>
());
}
// spawn a testee that receives two messages
catch
(
std
::
exception
&
e
)
{
cerr
<<
"error during type (de)serialization: "
<<
e
.
what
()
<<
endl
;
return
-
1
;
}
// spawn a testee that receives two messages of user-defined type
auto
t
=
spawn
(
testee
,
2
);
auto
t
=
spawn
(
testee
,
2
);
{
{
// lifetime scope of self
scoped_actor
self
;
scoped_actor
self
;
// send t a foo
// send t a foo
self
->
send
(
t
,
foo
{
std
::
vector
<
int
>
{
1
,
2
,
3
,
4
},
5
});
self
->
send
(
t
,
foo
{
std
::
vector
<
int
>
{
1
,
2
,
3
,
4
},
5
});
...
@@ -116,5 +118,4 @@ int main(int, char**) {
...
@@ -116,5 +118,4 @@ int main(int, char**) {
}
}
await_all_actors_done
();
await_all_actors_done
();
shutdown
();
shutdown
();
return
0
;
}
}
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