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
196ae5f6
Commit
196ae5f6
authored
Aug 03, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove dead code and simplify `uti_impl`
parent
90dc64c7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
200 deletions
+112
-200
libcaf_core/caf/detail/uniform_type_info_map.hpp
libcaf_core/caf/detail/uniform_type_info_map.hpp
+1
-18
libcaf_core/src/uniform_type_info_map.cpp
libcaf_core/src/uniform_type_info_map.cpp
+111
-182
No files found.
libcaf_core/caf/detail/uniform_type_info_map.hpp
View file @
196ae5f6
...
@@ -45,24 +45,8 @@ class uniform_type_info;
...
@@ -45,24 +45,8 @@ class uniform_type_info;
namespace
caf
{
namespace
caf
{
namespace
detail
{
namespace
detail
{
// lookup table for integer types
extern
const
char
*
mapped_int_names
[][
2
];
template
<
class
T
>
constexpr
const
char
*
mapped_int_name
()
{
return
mapped_int_names
[
sizeof
(
T
)][
std
::
is_signed
<
T
>::
value
?
1
:
0
];
}
class
uniform_type_info_map_helper
;
// note: this class is implemented in uniform_type_info.cpp
class
uniform_type_info_map
{
class
uniform_type_info_map
{
friend
class
uniform_type_info_map_helper
;
friend
class
singleton_mixin
<
uniform_type_info_map
>
;
public:
public:
using
pointer
=
const
uniform_type_info
*
;
using
pointer
=
const
uniform_type_info
*
;
virtual
~
uniform_type_info_map
();
virtual
~
uniform_type_info_map
();
...
@@ -79,12 +63,11 @@ public:
...
@@ -79,12 +63,11 @@ public:
static
uniform_type_info_map
*
create_singleton
();
static
uniform_type_info_map
*
create_singleton
();
inline
void
dispose
()
{
delete
this
;
}
void
dispose
();
void
stop
();
void
stop
();
virtual
void
initialize
()
=
0
;
virtual
void
initialize
()
=
0
;
};
};
}
// namespace detail
}
// namespace detail
...
...
libcaf_core/src/uniform_type_info_map.cpp
View file @
196ae5f6
...
@@ -95,89 +95,101 @@ const char* numbered_type_names[] = {
...
@@ -95,89 +95,101 @@ const char* numbered_type_names[] = {
namespace
{
namespace
{
inline
bool
operator
==
(
const
unit_t
&
,
const
unit_t
&
)
{
// might become part of serializer's public API at some point
return
true
;
template
<
class
T
>
void
operator
&
(
serializer
&
sink
,
const
T
&
value
)
{
sink
<<
value
;
}
}
// might become part of deserializer's public API at some point
template
<
class
T
>
template
<
class
T
>
inline
typename
std
::
enable_if
<
detail
::
is_primitive
<
T
>::
value
>::
type
void
operator
&
(
deserializer
&
source
,
T
&
value
)
{
serialize_impl
(
const
T
&
val
,
serializer
*
sink
)
{
source
>>
value
;
sink
->
write_value
(
val
);
}
}
template
<
class
T
>
// primitive types are handled by serializer/deserializer directly
inline
typename
std
::
enable_if
<
detail
::
is_primitive
<
T
>::
value
>::
type
template
<
class
T
,
class
U
>
deserialize_impl
(
T
&
val
,
deserializer
*
source
)
{
typename
std
::
enable_if
<
val
=
source
->
read
<
T
>
();
detail
::
is_primitive
<
U
>::
value
||
std
::
is_same
<
U
,
atom_value
>::
value
>::
type
process
(
T
&
io
,
U
&
x
)
{
io
&
x
;
}
}
inline
void
serialize_impl
(
const
unit_t
&
,
serializer
*
)
{
template
<
class
U
>
// nop
auto
process
(
serializer
&
sink
,
const
U
&
x
)
->
decltype
(
x
.
serialize
(
sink
))
{
x
.
serialize
(
sink
);
}
template
<
class
U
>
auto
process
(
deserializer
&
source
,
U
&
x
)
->
decltype
(
x
.
deserialize
(
source
))
{
x
.
deserialize
(
source
);
}
}
inline
void
deserialize_impl
(
unit_t
&
,
deserializer
*
)
{
template
<
class
T
>
void
process
(
T
&
,
const
unit_t
&
)
{
// nop
// nop
}
}
void
serialize_impl
(
const
actor_addr
&
addr
,
serializer
*
sink
)
{
void
process
(
serializer
&
sink
,
const
actor_addr
&
addr
,
actor_namespace
*
ns
)
{
auto
ns
=
sink
->
get_namespace
();
ns
->
write
(
&
sink
,
addr
);
if
(
!
ns
)
{
throw
std
::
runtime_error
(
"unable to serialize actor_addr: "
"no actor addressing defined"
);
}
ns
->
write
(
sink
,
addr
);
}
}
void
deserialize_impl
(
actor_addr
&
addr
,
deserializer
*
source
)
{
void
process
(
deserializer
&
source
,
actor_addr
&
addr
,
actor_namespace
*
ns
)
{
auto
ns
=
source
->
get_namespace
();
addr
=
ns
->
read
(
&
source
);
if
(
!
ns
)
{
}
throw
std
::
runtime_error
(
"unable to deserialize actor_ptr: "
template
<
class
T
,
class
U
>
"no actor addressing defined"
);
typename
std
::
enable_if
<
}
std
::
is_same
<
typename
std
::
remove_const
<
U
>::
type
,
actor_addr
>::
value
addr
=
ns
->
read
(
source
);
>::
type
process
(
T
&
io
,
U
&
addr
)
{
auto
ns
=
io
.
get_namespace
();
if
(
!
ns
)
throw
std
::
runtime_error
(
"no actor namespace found"
);
process
(
io
,
addr
,
ns
);
}
}
void
serialize_impl
(
const
actor
&
ptr
,
serializer
*
sink
)
{
void
process
(
serializer
&
sink
,
const
actor
&
hdl
)
{
serialize_impl
(
ptr
.
address
(),
sink
);
auto
addr
=
hdl
.
address
();
process
(
sink
,
addr
);
}
}
void
deserialize_impl
(
actor
&
ptr
,
deserializer
*
source
)
{
void
process
(
deserializer
&
source
,
actor
&
hdl
)
{
actor_addr
addr
;
actor_addr
addr
;
deserialize_impl
(
addr
,
source
);
process
(
source
,
addr
);
ptr
=
actor_cast
<
actor
>
(
addr
);
hdl
=
actor_cast
<
actor
>
(
addr
);
}
}
void
serialize_impl
(
const
group
&
gref
,
serializer
*
sink
)
{
void
process
(
serializer
&
sink
,
const
group
&
gref
)
{
if
(
!
gref
)
{
if
(
!
gref
)
{
CAF_LOGF_DEBUG
(
"serialized an invalid group"
);
CAF_LOGF_DEBUG
(
"serialized an invalid group"
);
// write an empty string as module name
// write an empty string as module name
std
::
string
empty_string
;
std
::
string
empty_string
;
sink
->
write_value
(
empty_string
);
sink
.
write_value
(
empty_string
);
}
else
{
}
else
{
sink
->
write_value
(
gref
->
module_name
());
sink
.
write_value
(
gref
->
module_name
());
gref
->
serialize
(
sink
);
gref
->
serialize
(
&
sink
);
}
}
}
}
void
deserialize_impl
(
group
&
gref
,
deserializer
*
source
)
{
void
process
(
deserializer
&
source
,
group
&
gref
)
{
auto
modname
=
source
->
read
<
std
::
string
>
();
auto
modname
=
source
.
read
<
std
::
string
>
();
if
(
modname
.
empty
())
{
if
(
modname
.
empty
())
{
gref
=
invalid_group
;
gref
=
invalid_group
;
}
else
{
}
else
{
gref
=
group
::
get_module
(
modname
)
->
deserialize
(
source
);
gref
=
group
::
get_module
(
modname
)
->
deserialize
(
&
source
);
}
}
}
}
void
serialize_impl
(
const
channel
&
chref
,
serializer
*
sink
)
{
void
process
(
serializer
&
sink
,
const
channel
&
chref
)
{
// abstract_channel is an abstract base class that's either an actor
// abstract_channel is an abstract base class that's either an actor
// or a group; we prefix the serialized data using a flag:
// or a group; we prefix the serialized data using a flag:
// 0 if ptr == nullptr
// 0 if ptr == nullptr
// 1 if ptr points to an actor
// 1 if ptr points to an actor
// 2 if ptr points to a group
// 2 if ptr points to a group
uint8_t
flag
=
0
;
uint8_t
flag
=
0
;
auto
wr_nullptr
=
[
&
]
{
sink
->
write_value
(
flag
);
};
auto
wr_nullptr
=
[
&
]
{
sink
.
write_value
(
flag
);
};
if
(
!
chref
)
{
if
(
!
chref
)
{
// invalid channel
// invalid channel
wr_nullptr
();
wr_nullptr
();
...
@@ -189,20 +201,20 @@ void serialize_impl(const channel& chref, serializer* sink) {
...
@@ -189,20 +201,20 @@ void serialize_impl(const channel& chref, serializer* sink) {
// raw actor pointer
// raw actor pointer
abstract_actor_ptr
aptr
=
static_cast
<
abstract_actor
*>
(
rptr
);
abstract_actor_ptr
aptr
=
static_cast
<
abstract_actor
*>
(
rptr
);
flag
=
1
;
flag
=
1
;
sink
->
write_value
(
flag
);
sink
.
write_value
(
flag
);
serialize_impl
(
actor_cast
<
actor
>
(
aptr
),
sink
);
process
(
sink
,
actor_cast
<
actor
>
(
aptr
)
);
}
else
{
}
else
{
// get raw group pointer and store it inside a group handle
// get raw group pointer and store it inside a group handle
group
tmp
{
static_cast
<
abstract_group
*>
(
rptr
)};
group
tmp
{
static_cast
<
abstract_group
*>
(
rptr
)};
flag
=
2
;
flag
=
2
;
sink
->
write_value
(
flag
);
sink
.
write_value
(
flag
);
serialize_impl
(
tmp
,
sink
);
process
(
sink
,
tmp
);
}
}
}
}
}
}
void
deserialize_impl
(
channel
&
ptrref
,
deserializer
*
source
)
{
void
process
(
deserializer
&
source
,
channel
&
ptrref
)
{
auto
flag
=
source
->
read
<
uint8_t
>
();
auto
flag
=
source
.
read
<
uint8_t
>
();
switch
(
flag
)
{
switch
(
flag
)
{
case
0
:
{
case
0
:
{
ptrref
=
channel
{};
// ptrref.reset();
ptrref
=
channel
{};
// ptrref.reset();
...
@@ -210,13 +222,13 @@ void deserialize_impl(channel& ptrref, deserializer* source) {
...
@@ -210,13 +222,13 @@ void deserialize_impl(channel& ptrref, deserializer* source) {
}
}
case
1
:
{
case
1
:
{
actor
tmp
;
actor
tmp
;
deserialize_impl
(
tmp
,
source
);
process
(
source
,
tmp
);
ptrref
=
actor_cast
<
channel
>
(
tmp
);
ptrref
=
actor_cast
<
channel
>
(
tmp
);
break
;
break
;
}
}
case
2
:
{
case
2
:
{
group
tmp
;
group
tmp
;
deserialize_impl
(
tmp
,
source
);
process
(
source
,
tmp
);
ptrref
=
tmp
;
ptrref
=
tmp
;
break
;
break
;
}
}
...
@@ -227,38 +239,15 @@ void deserialize_impl(channel& ptrref, deserializer* source) {
...
@@ -227,38 +239,15 @@ void deserialize_impl(channel& ptrref, deserializer* source) {
}
}
}
}
void
serialize_impl
(
const
message
&
msg
,
serializer
*
sink
)
{
inline
void
process
(
serializer
&
sink
,
const
duration
&
val
)
{
msg
.
serialize
(
*
sink
);
sink
&
static_cast
<
uint32_t
>
(
val
.
unit
);
}
sink
&
val
.
count
;
void
deserialize_impl
(
message
&
msg
,
deserializer
*
source
)
{
msg
.
deserialize
(
*
source
);
}
void
serialize_impl
(
const
node_id
&
nid
,
serializer
*
sink
)
{
nid
.
serialize
(
*
sink
);
}
void
deserialize_impl
(
node_id
&
nid
,
deserializer
*
source
)
{
nid
.
deserialize
(
*
source
);
}
inline
void
serialize_impl
(
const
atom_value
&
val
,
serializer
*
sink
)
{
sink
->
write_value
(
val
);
}
inline
void
deserialize_impl
(
atom_value
&
val
,
deserializer
*
source
)
{
val
=
source
->
read
<
atom_value
>
();
}
}
inline
void
serialize_impl
(
const
duration
&
val
,
serializer
*
sink
)
{
inline
void
process
(
deserializer
&
source
,
duration
&
val
)
{
sink
->
write_value
(
static_cast
<
uint32_t
>
(
val
.
unit
));
uint32_t
unit_val
;
sink
->
write_value
(
val
.
count
);
source
&
unit_val
;
}
source
&
val
.
count
;
inline
void
deserialize_impl
(
duration
&
val
,
deserializer
*
source
)
{
auto
unit_val
=
source
->
read
<
uint32_t
>
();
auto
count_val
=
source
->
read
<
uint32_t
>
();
switch
(
unit_val
)
{
switch
(
unit_val
)
{
case
1
:
case
1
:
val
.
unit
=
time_unit
::
seconds
;
val
.
unit
=
time_unit
::
seconds
;
...
@@ -273,85 +262,56 @@ inline void deserialize_impl(duration& val, deserializer* source) {
...
@@ -273,85 +262,56 @@ inline void deserialize_impl(duration& val, deserializer* source) {
val
.
unit
=
time_unit
::
invalid
;
val
.
unit
=
time_unit
::
invalid
;
break
;
break
;
}
}
val
.
count
=
count_val
;
}
inline
void
serialize_impl
(
const
bool
&
val
,
serializer
*
sink
)
{
sink
->
write_value
(
val
);
}
inline
void
deserialize_impl
(
bool
&
val
,
deserializer
*
source
)
{
val
=
source
->
read
<
bool
>
();
}
}
// exit_msg & down_msg have the same fields
// exit_msg & down_msg have the same fields
template
<
class
T
>
template
<
class
T
,
class
U
>
typename
std
::
enable_if
<
typename
std
::
enable_if
<
std
::
is_same
<
T
,
down_msg
>::
value
std
::
is_same
<
typename
std
::
remove_const
<
U
>::
type
,
down_msg
>::
value
||
std
::
is_same
<
T
,
exit_msg
>::
value
||
std
::
is_same
<
typename
std
::
remove_const
<
U
>::
type
,
exit_msg
>::
value
||
std
::
is_same
<
T
,
sync_exited_msg
>::
value
||
std
::
is_same
<
typename
std
::
remove_const
<
U
>::
type
,
sync_exited_msg
>::
value
>::
type
>::
type
serialize_impl
(
const
T
&
dm
,
serializer
*
sink
)
{
process
(
T
&
io
,
U
&
x
)
{
serialize_impl
(
dm
.
source
,
sink
);
process
(
io
,
x
.
source
);
sink
->
write_value
(
dm
.
reason
)
;
io
&
x
.
reason
;
}
}
// exit_msg & down_msg have the same fields
template
<
class
T
,
class
U
>
template
<
class
T
>
typename
std
::
enable_if
<
typename
std
::
enable_if
<
std
::
is_same
<
T
,
down_msg
>::
value
std
::
is_same
<
typename
std
::
remove_const
<
U
>::
type
,
group_down_msg
>::
value
||
std
::
is_same
<
T
,
exit_msg
>::
value
||
std
::
is_same
<
T
,
sync_exited_msg
>::
value
>::
type
>::
type
deserialize_impl
(
T
&
dm
,
deserializer
*
source
)
{
process
(
T
&
io
,
U
&
x
)
{
deserialize_impl
(
dm
.
source
,
source
);
process
(
io
,
x
.
source
);
dm
.
reason
=
source
->
read
<
uint32_t
>
();
}
}
inline
void
serialize_impl
(
const
group_down_msg
&
dm
,
serializer
*
sink
)
{
void
process
(
serializer
&
sink
,
const
message_id
&
x
)
{
s
erialize_impl
(
dm
.
source
,
sink
);
s
ink
.
write_value
(
x
.
integer_value
()
);
}
}
inline
void
deserialize_impl
(
group_down_msg
&
dm
,
deserializer
*
source
)
{
void
process
(
deserializer
&
source
,
message_id
&
x
)
{
deserialize_impl
(
dm
.
source
,
source
);
x
=
message_id
::
from_integer_value
(
source
.
read
<
uint64_t
>
()
);
}
}
inline
void
serialize_impl
(
const
message_id
&
dm
,
serializer
*
sink
)
{
template
<
class
T
,
class
U
>
sink
->
write_value
(
dm
.
integer_value
());
typename
std
::
enable_if
<
}
std
::
is_same
<
typename
std
::
remove_const
<
U
>::
type
,
timeout_msg
>::
value
>::
type
inline
void
deserialize_impl
(
message_id
&
dm
,
deserializer
*
source
)
{
process
(
T
&
sink
,
U
&
x
)
{
dm
=
message_id
::
from_integer_value
(
source
->
read
<
uint64_t
>
());
sink
&
x
.
timeout_id
;
}
inline
void
serialize_impl
(
const
timeout_msg
&
tm
,
serializer
*
sink
)
{
sink
->
write_value
(
tm
.
timeout_id
);
}
inline
void
deserialize_impl
(
timeout_msg
&
tm
,
deserializer
*
source
)
{
tm
.
timeout_id
=
source
->
read
<
uint32_t
>
();
}
inline
void
serialize_impl
(
const
sync_timeout_msg
&
,
serializer
*
)
{
// nop
}
inline
void
deserialize_impl
(
const
sync_timeout_msg
&
,
deserializer
*
)
{
// nop
}
}
template
<
class
T
>
template
<
class
T
>
typename
std
::
enable_if
<
is_iterable
<
T
>::
value
>::
type
void
process
(
T
&
,
const
sync_timeout_msg
&
)
{
serialize_impl
(
const
T
&
iterable
,
serializer
*
sink
)
{
// nop
default_serialize_policy
sp
;
sp
(
iterable
,
sink
);
}
}
template
<
class
T
>
template
<
class
T
,
class
U
>
typename
std
::
enable_if
<
is_iterable
<
T
>::
value
>::
type
typename
std
::
enable_if
<
deserialize_impl
(
T
&
iterable
,
deserializer
*
sink
)
{
is_iterable
<
typename
std
::
remove_const
<
U
>::
type
>::
value
>::
type
process
(
T
&
io
,
U
&
iterable
)
{
default_serialize_policy
sp
;
default_serialize_policy
sp
;
sp
(
iterable
,
sink
);
sp
(
iterable
,
&
io
);
}
}
template
<
class
T
>
template
<
class
T
>
...
@@ -382,23 +342,23 @@ public:
...
@@ -382,23 +342,23 @@ public:
return
create_impl
<
T
>
(
other
);
return
create_impl
<
T
>
(
other
);
}
}
static
inline
const
T
&
deref
(
const
void
*
ptr
)
{
void
serialize
(
const
void
*
instance
,
serializer
*
sink
)
const
override
{
return
*
reinterpret_cast
<
const
T
*>
(
ptr
);
process
(
*
sink
,
deref
(
instance
)
);
}
}
static
inline
T
&
deref
(
void
*
ptr
)
{
void
deserialize
(
void
*
instance
,
deserializer
*
source
)
const
override
{
return
*
reinterpret_cast
<
T
*>
(
ptr
);
process
(
*
source
,
deref
(
instance
)
);
}
}
void
serialize
(
const
void
*
instance
,
serializer
*
sink
)
const
override
{
private:
serialize_impl
(
deref
(
instance
),
sink
);
static
inline
const
T
&
deref
(
const
void
*
ptr
)
{
return
*
reinterpret_cast
<
const
T
*>
(
ptr
);
}
}
void
deserialize
(
void
*
instance
,
deserializer
*
source
)
const
override
{
static
inline
T
&
deref
(
void
*
ptr
)
{
deserialize_impl
(
deref
(
instance
),
source
);
return
*
reinterpret_cast
<
T
*>
(
ptr
);
}
}
private:
template
<
class
U
>
template
<
class
U
>
typename
std
::
enable_if
<
std
::
is_floating_point
<
U
>::
value
,
bool
>::
type
typename
std
::
enable_if
<
std
::
is_floating_point
<
U
>::
value
,
bool
>::
type
eq
(
const
U
&
lhs
,
const
U
&
rhs
)
const
{
eq
(
const
U
&
lhs
,
const
U
&
rhs
)
const
{
...
@@ -417,41 +377,6 @@ struct get_uti_impl {
...
@@ -417,41 +377,6 @@ struct get_uti_impl {
using
type
=
uti_impl
<
T
>
;
using
type
=
uti_impl
<
T
>
;
};
};
template
<
class
T
>
class
int_tinfo
:
public
uniform_type_info
{
public:
int_tinfo
()
:
uniform_type_info
(
detail
::
type_nr
<
T
>::
value
)
{
// nop
}
void
serialize
(
const
void
*
instance
,
serializer
*
sink
)
const
override
{
sink
->
write_value
(
deref
(
instance
));
}
void
deserialize
(
void
*
instance
,
deserializer
*
source
)
const
override
{
deref
(
instance
)
=
source
->
read
<
T
>
();
}
const
char
*
name
()
const
override
{
return
static_name
();
}
bool
equals
(
const
void
*
lhs
,
const
void
*
rhs
)
const
override
{
return
deref
(
lhs
)
==
deref
(
rhs
);
}
uniform_value
create
(
const
uniform_value
&
other
)
const
override
{
return
create_impl
<
T
>
(
other
);
}
private:
inline
static
const
T
&
deref
(
const
void
*
ptr
)
{
return
*
reinterpret_cast
<
const
T
*>
(
ptr
);
}
inline
static
T
&
deref
(
void
*
ptr
)
{
return
*
reinterpret_cast
<
T
*>
(
ptr
);
}
static
inline
const
char
*
static_name
()
{
return
mapped_int_name
<
T
>
();
}
};
class
default_meta_message
:
public
uniform_type_info
{
class
default_meta_message
:
public
uniform_type_info
{
public:
public:
explicit
default_meta_message
(
const
std
::
string
&
tname
)
:
name_
(
tname
)
{
explicit
default_meta_message
(
const
std
::
string
&
tname
)
:
name_
(
tname
)
{
...
@@ -693,6 +618,10 @@ uniform_type_info_map* uniform_type_info_map::create_singleton() {
...
@@ -693,6 +618,10 @@ uniform_type_info_map* uniform_type_info_map::create_singleton() {
return
new
utim_impl
;
return
new
utim_impl
;
}
}
void
uniform_type_info_map
::
dispose
()
{
delete
this
;
}
void
uniform_type_info_map
::
stop
()
{
void
uniform_type_info_map
::
stop
()
{
// nop
// nop
}
}
...
...
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