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
0076feb1
Commit
0076feb1
authored
Apr 13, 2014
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correctly announce enums, closes #122
parent
5b743abf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
6 deletions
+74
-6
cppa/detail/default_uniform_type_info.hpp
cppa/detail/default_uniform_type_info.hpp
+48
-6
unit_testing/test_serialization.cpp
unit_testing/test_serialization.cpp
+26
-0
No files found.
cppa/detail/default_uniform_type_info.hpp
View file @
0076feb1
...
...
@@ -238,7 +238,8 @@ class forwarding_serialize_policy {
template
<
typename
T
,
class
AccessPolicy
,
class
SerializePolicy
=
default_serialize_policy
,
bool
IsEmptyType
=
std
::
is_empty
<
T
>
::
value
>
bool
IsEnum
=
std
::
is_enum
<
T
>
::
value
,
bool
IsEmptyType
=
std
::
is_class
<
T
>::
value
&&
std
::
is_empty
<
T
>::
value
>
class
member_tinfo
:
public
util
::
abstract_uniform_type_info
<
T
>
{
public:
...
...
@@ -250,11 +251,11 @@ class member_tinfo : public util::abstract_uniform_type_info<T> {
member_tinfo
()
{
}
void
serialize
(
const
void
*
vptr
,
serializer
*
s
)
const
{
void
serialize
(
const
void
*
vptr
,
serializer
*
s
)
const
override
{
m_spol
(
m_apol
(
vptr
),
s
);
}
void
deserialize
(
void
*
vptr
,
deserializer
*
d
)
const
{
void
deserialize
(
void
*
vptr
,
deserializer
*
d
)
const
override
{
std
::
integral_constant
<
bool
,
AccessPolicy
::
grants_mutable_access
>
token
;
ds
(
vptr
,
d
,
token
);
}
...
...
@@ -277,7 +278,8 @@ class member_tinfo : public util::abstract_uniform_type_info<T> {
};
template
<
typename
T
,
class
A
,
class
S
>
class
member_tinfo
<
T
,
A
,
S
,
true
>
:
public
util
::
abstract_uniform_type_info
<
T
>
{
class
member_tinfo
<
T
,
A
,
S
,
false
,
true
>
:
public
util
::
abstract_uniform_type_info
<
T
>
{
public:
...
...
@@ -287,12 +289,47 @@ class member_tinfo<T, A, S, true> : public util::abstract_uniform_type_info<T> {
member_tinfo
()
{
}
void
serialize
(
const
void
*
,
serializer
*
)
const
{
}
void
serialize
(
const
void
*
,
serializer
*
)
const
override
{
}
void
deserialize
(
void
*
,
deserializer
*
)
const
{
}
void
deserialize
(
void
*
,
deserializer
*
)
const
override
{
}
};
template
<
typename
T
,
class
AccessPolicy
,
class
SerializePolicy
>
class
member_tinfo
<
T
,
AccessPolicy
,
SerializePolicy
,
true
,
false
>
:
public
util
::
abstract_uniform_type_info
<
T
>
{
typedef
typename
std
::
underlying_type
<
T
>::
type
value_type
;
public:
member_tinfo
(
AccessPolicy
apol
,
SerializePolicy
spol
)
:
m_apol
(
std
::
move
(
apol
)),
m_spol
(
std
::
move
(
spol
))
{
}
member_tinfo
(
AccessPolicy
apol
)
:
m_apol
(
std
::
move
(
apol
))
{
}
member_tinfo
()
{
}
void
serialize
(
const
void
*
p
,
serializer
*
s
)
const
override
{
auto
val
=
m_apol
(
p
);
m_spol
(
static_cast
<
value_type
>
(
val
),
s
);
}
void
deserialize
(
void
*
p
,
deserializer
*
d
)
const
override
{
value_type
tmp
;
m_spol
(
tmp
,
d
);
m_apol
(
p
,
static_cast
<
T
>
(
tmp
));
}
private:
AccessPolicy
m_apol
;
SerializePolicy
m_spol
;
};
template
<
typename
T
,
class
C
>
class
memptr_access_policy
{
...
...
@@ -362,6 +399,11 @@ struct fake_access_policy {
return
*
reinterpret_cast
<
const
T
*>
(
vptr
);
}
template
<
typename
U
>
inline
void
operator
()(
void
*
vptr
,
U
&&
value
)
const
{
*
reinterpret_cast
<
T
*>
(
vptr
)
=
std
::
forward
<
U
>
(
value
);
}
static
constexpr
bool
grants_mutable_access
=
true
;
};
...
...
unit_testing/test_serialization.cpp
View file @
0076feb1
...
...
@@ -120,11 +120,15 @@ void test_ieee_754() {
CPPA_CHECK_EQUAL
(
f2
,
u2
);
}
enum
class
test_enum
{
a
,
b
,
c
};
}
// namespace <anonymous>
int
main
()
{
CPPA_TEST
(
test_serialization
);
announce
<
test_enum
>
();
test_ieee_754
();
typedef
std
::
integral_constant
<
int
,
detail
::
impl_id
<
strmap
>
()
>
token
;
...
...
@@ -263,5 +267,27 @@ int main() {
}
catch
(
exception
&
e
)
{
CPPA_FAILURE
(
to_verbose_string
(
e
));
}
// test serialization of enums
try
{
auto
enum_tuple
=
make_any_tuple
(
test_enum
::
b
);
// serialize b1 to buf
util
::
buffer
wr_buf
;
binary_serializer
bs
(
&
wr_buf
,
&
addressing
);
bs
<<
enum_tuple
;
// deserialize b2 from buf
binary_deserializer
bd
(
wr_buf
.
data
(),
wr_buf
.
size
(),
&
addressing
);
any_tuple
enum_tuple2
;
uniform_typeid
<
any_tuple
>
()
->
deserialize
(
&
enum_tuple2
,
&
bd
);
auto
opt
=
tuple_cast
<
test_enum
>
(
enum_tuple2
);
CPPA_CHECK
(
opt
.
valid
());
if
(
opt
.
valid
())
{
auto
&
tup
=
*
opt
;
CPPA_CHECK_EQUAL
(
tup
.
size
(),
1
);
CPPA_CHECK
(
get
<
0
>
(
tup
)
==
test_enum
::
b
);
}
}
catch
(
exception
&
e
)
{
CPPA_FAILURE
(
to_verbose_string
(
e
));
}
return
CPPA_TEST_RESULT
();
}
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