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
329f45ff
Commit
329f45ff
authored
Apr 11, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #452 from actor-framework/topic/serialization-tweaks
Enhance serialization framework
parents
a73e1f42
058d2a1a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
57 deletions
+39
-57
libcaf_core/caf/detail/delegate_serialize.hpp
libcaf_core/caf/detail/delegate_serialize.hpp
+11
-1
libcaf_core/caf/detail/type_traits.hpp
libcaf_core/caf/detail/type_traits.hpp
+27
-55
libcaf_core/test/serialization.cpp
libcaf_core/test/serialization.cpp
+1
-1
No files found.
libcaf_core/caf/detail/delegate_serialize.hpp
View file @
329f45ff
...
...
@@ -52,11 +52,21 @@ namespace detail {
// to enable both ADL and picking up existing boost code.
template
<
class
Processor
,
class
U
>
void
delegate_serialize
(
Processor
&
proc
,
U
&
x
)
{
auto
delegate_serialize
(
Processor
&
proc
,
U
&
x
)
->
decltype
(
serialize
(
proc
,
x
,
0
))
{
using
namespace
boost
::
serialization
;
serialize
(
proc
,
x
,
0
);
}
// Calls `serialize(...)` without the unused version argument, which CAF
// ignores anyway.
template
<
class
Processor
,
class
U
>
auto
delegate_serialize
(
Processor
&
proc
,
U
&
x
)
->
decltype
(
serialize
(
proc
,
x
))
{
serialize
(
proc
,
x
);
}
}
// namespace detail
}
// namespace caf
...
...
libcaf_core/caf/detail/type_traits.hpp
View file @
329f45ff
...
...
@@ -258,66 +258,38 @@ struct is_tuple<std::tuple<Ts...>> : std::true_type { };
template
<
class
F
,
class
S
>
struct
is_tuple
<
std
::
pair
<
F
,
S
>>
:
std
::
true_type
{
};
/// Checks whether `T` provides a free
/// `serialize(Processor&, T&, const unsigned int)` function.
template
<
class
T
>
struct
has_free_serialize
{
private:
// check for free function
template
<
class
C
,
class
E
=
decltype
(
serialize
(
std
::
declval
<
serializer
&
>(),
std
::
declval
<
C
&>
(),
0
))
>
static
bool
sfinae_fun
(
C
*
)
{
return
true
;
}
static
void
sfinae_fun
(
void
*
)
{
// nop
}
using
type
=
typename
std
::
remove_const
<
T
>::
type
;
using
result_type
=
decltype
(
sfinae_fun
(
static_cast
<
type
*>
(
nullptr
)));
public:
static
constexpr
bool
value
=
std
::
is_same
<
bool
,
result_type
>::
value
;
};
/// Checks whether `T` provides a member
/// `T::serialize(Processor&, const unsigned int)` function.
template
<
class
T
>
struct
has_member_serialize
{
private:
// check for free function
template
<
class
C
,
class
E
=
decltype
(
std
::
declval
<
C
&
>()
.
serialize
(
std
::
declval
<
serializer
&>
(),
0
))
>
static
bool
sfinae_fun
(
C
*
)
{
return
true
;
}
/// Checks whether `T` provides either a free function or a member function for
/// serialization. The following signatures are tested:
///
/// - `serialize(Processor&, T&, const unsigned int)`
/// - `serialize(Processor&, T&)`
/// - `T::serialize(Processor&, const unsigned int)`.
/// - `T::serialize(Processor&)`.
template
<
class
T
,
bool
Ignore
=
std
::
is_pointer
<
T
>
::
value
||
std
::
is_function
<
T
>::
value
>
struct
has_serialize
{
template
<
class
U
>
static
auto
test
(
caf
::
serializer
*
sink
,
U
*
x
)
->
decltype
(
serialize
(
*
sink
,
*
x
,
0u
),
std
::
true_type
());
static
void
sfinae_fun
(
void
*
)
{
// nop
}
template
<
class
U
>
static
auto
test
(
caf
::
serializer
*
sink
,
U
*
x
)
->
decltype
(
serialize
(
*
sink
,
*
x
),
std
::
true_type
());
using
type
=
typename
std
::
remove_const
<
T
>::
type
;
template
<
class
U
>
static
auto
test
(
caf
::
serializer
*
sink
,
U
*
x
)
->
decltype
(
x
->
serialize
(
*
sink
,
0u
),
std
::
true_type
());
using
result_type
=
decltype
(
sfinae_fun
(
static_cast
<
type
*>
(
nullptr
)));
template
<
class
U
>
static
auto
test
(
caf
::
serializer
*
sink
,
U
*
x
)
->
decltype
(
x
->
serialize
(
*
sink
),
std
::
true_type
());
public:
static
constexpr
bool
value
=
std
::
is_same
<
bool
,
result_type
>::
value
;
};
template
<
class
>
static
auto
test
(...)
->
std
::
false_type
;
/// Checks whether `T` provides either a free function
/// `serialize(Processor&, T&, const unsigned int)` or a member function
/// `T::serialize(Processor&, const unsigned int)`. If `T` is iterable,
/// then the template checks whether `T::value_type` is serializable.
template
<
class
T
,
bool
Ignore
=
std
::
is_pointer
<
T
>
::
value
||
std
::
is_function
<
T
>::
value
>
struct
has_serialize
{
static
constexpr
bool
value
=
has_free_serialize
<
T
>::
value
||
has_member_serialize
<
T
>::
value
;
using
type
=
decltype
(
test
<
T
>
(
nullptr
,
nullptr
));
static
constexpr
bool
value
=
type
::
value
;
};
template
<
class
T
>
...
...
libcaf_core/test/serialization.cpp
View file @
329f45ff
...
...
@@ -74,7 +74,7 @@ struct raw_struct {
};
template
<
class
Processor
>
void
serialize
(
Processor
&
proc
,
raw_struct
&
x
,
const
unsigned
int
)
{
void
serialize
(
Processor
&
proc
,
raw_struct
&
x
)
{
proc
&
x
.
str
;
}
...
...
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