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
1cf9ca9b
Commit
1cf9ca9b
authored
Sep 17, 2015
by
ufownl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support array members in `announce`
parent
f4af07aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
1 deletion
+87
-1
libcaf_core/caf/detail/default_uniform_type_info.hpp
libcaf_core/caf/detail/default_uniform_type_info.hpp
+18
-1
libcaf_core/caf/uniform_type_info.hpp
libcaf_core/caf/uniform_type_info.hpp
+42
-0
libcaf_core/test/serialization.cpp
libcaf_core/test/serialization.cpp
+27
-0
No files found.
libcaf_core/caf/detail/default_uniform_type_info.hpp
View file @
1cf9ca9b
...
...
@@ -86,6 +86,7 @@ using list_impl = std::integral_constant<int, 1>;
using
map_impl
=
std
::
integral_constant
<
int
,
2
>
;
using
pair_impl
=
std
::
integral_constant
<
int
,
3
>
;
using
opt_impl
=
std
::
integral_constant
<
int
,
4
>
;
using
array_impl
=
std
::
integral_constant
<
int
,
5
>
;
using
recursive_impl
=
std
::
integral_constant
<
int
,
9
>
;
template
<
class
T
>
...
...
@@ -100,7 +101,9 @@ constexpr int impl_id() {
?
3
:
(
detail
::
is_optional
<
T
>::
value
?
4
:
9
))));
:
(
std
::
is_array
<
T
>::
value
?
5
:
9
)))));
}
template
<
class
T
>
...
...
@@ -166,6 +169,13 @@ private:
}
}
template
<
class
T
,
size_t
N
>
void
simpl
(
const
T
(
&
val
)[
N
],
serializer
*
s
,
array_impl
)
const
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
(
*
this
)(
val
[
i
],
s
);
}
}
template
<
class
T
>
void
simpl
(
const
T
&
val
,
serializer
*
s
,
recursive_impl
)
const
{
uniform_typeid
<
T
>
()
->
serialize
(
&
val
,
s
);
...
...
@@ -219,6 +229,13 @@ private:
}
}
template
<
class
T
,
size_t
N
>
void
dimpl
(
T
(
&
val
)[
N
],
deserializer
*
d
,
array_impl
)
const
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
(
*
this
)(
val
[
i
],
d
);
}
}
template
<
class
T
>
void
dimpl
(
T
&
storage
,
deserializer
*
d
,
recursive_impl
)
const
{
uniform_typeid
<
T
>
()
->
deserialize
(
&
storage
,
d
);
...
...
libcaf_core/caf/uniform_type_info.hpp
View file @
1cf9ca9b
...
...
@@ -71,6 +71,48 @@ private:
T
value_
;
};
template
<
class
T
,
size_t
N
>
class
uniform_value_impl
<
T
[
N
]
>
:
public
uniform_value_t
{
public:
uniform_value_impl
(
const
uniform_type_info
*
ptr
)
:
uniform_value_t
(
ptr
,
&
value_
)
{
// nop
}
uniform_value_impl
(
const
uniform_type_info
*
ptr
,
const
T
(
&
val
)[
N
])
:
uniform_value_t
(
ptr
,
&
value_
)
{
array_copy
(
value_
,
val
);
}
uniform_value
copy
()
override
{
return
uniform_value
{
new
uniform_value_impl
(
ti
,
value_
)};
}
private:
template
<
class
U
,
size_t
Len
>
static
void
array_copy_impl
(
U
(
&
lhs
)[
Len
],
const
U
(
&
rhs
)[
Len
],
std
::
true_type
)
{
for
(
size_t
i
=
0
;
i
<
Len
;
++
i
)
{
array_copy
(
lhs
[
i
],
rhs
[
i
]);
}
}
template
<
class
U
,
size_t
Len
>
static
void
array_copy_impl
(
U
(
&
lhs
)[
Len
],
const
U
(
&
rhs
)[
Len
],
std
::
false_type
)
{
std
::
copy
(
rhs
,
rhs
+
Len
,
lhs
);
}
template
<
class
U
,
size_t
Len
>
static
void
array_copy
(
U
(
&
lhs
)[
Len
],
const
U
(
&
rhs
)[
Len
])
{
array_copy_impl
(
lhs
,
rhs
,
std
::
integral_constant
<
bool
,
std
::
is_array
<
U
>::
value
>
{});
}
T
value_
[
N
];
};
/// Creates a uniform value of type `T`.
template
<
class
T
,
class
...
Ts
>
uniform_value
make_uniform_value
(
const
uniform_type_info
*
uti
,
Ts
&&
...
xs
)
{
...
...
libcaf_core/test/serialization.cpp
View file @
1cf9ca9b
...
...
@@ -106,16 +106,29 @@ enum class test_enum {
c
};
struct
test_array
{
int
value
[
4
];
int
value2
[
2
][
4
];
};
struct
fixture
{
int32_t
i32
=
-
345
;
test_enum
te
=
test_enum
::
b
;
string
str
=
"Lorem ipsum dolor sit amet."
;
raw_struct
rs
;
test_array
ta
{
{
0
,
1
,
2
,
3
},
{
{
0
,
1
,
2
,
3
},
{
4
,
5
,
6
,
7
}
},
};
message
msg
;
fixture
()
{
announce
<
test_enum
>
(
"test_enum"
);
announce
(
typeid
(
raw_struct
),
uniform_type_info_ptr
{
new
raw_struct_type_info
});
announce
<
test_array
>
(
"test_array"
,
&
test_array
::
value
,
&
test_array
::
value2
);
rs
.
str
.
assign
(
string
(
str
.
rbegin
(),
str
.
rend
()));
msg
=
make_message
(
i32
,
te
,
str
,
rs
);
}
...
...
@@ -259,6 +272,20 @@ CAF_TEST(test_raw_struct) {
CAF_CHECK
(
rs
==
x
);
}
CAF_TEST
(
test_array_serialization
)
{
auto
buf
=
binary_util
::
serialize
(
ta
);
test_array
x
;
binary_util
::
deserialize
(
buf
,
&
x
);
for
(
auto
i
=
0
;
i
<
4
;
++
i
)
{
CAF_CHECK
(
ta
.
value
[
i
]
==
x
.
value
[
i
]);
}
for
(
auto
i
=
0
;
i
<
2
;
++
i
)
{
for
(
auto
j
=
0
;
j
<
4
;
++
j
)
{
CAF_CHECK
(
ta
.
value2
[
i
][
j
]
==
x
.
value2
[
i
][
j
]);
}
}
}
CAF_TEST
(
test_single_message
)
{
auto
buf
=
binary_util
::
serialize
(
msg
);
message
x
;
...
...
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