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
5c7a8d71
Commit
5c7a8d71
authored
Jun 12, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
maintenance
parent
f45f4591
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
102 deletions
+85
-102
cppa/detail/uniform_type_info_map.hpp
cppa/detail/uniform_type_info_map.hpp
+7
-3
cppa/uniform_type_info.hpp
cppa/uniform_type_info.hpp
+2
-2
src/uniform_type_info.cpp
src/uniform_type_info.cpp
+67
-89
unit_testing/test__pattern.cpp
unit_testing/test__pattern.cpp
+3
-3
unit_testing/test__serialization.cpp
unit_testing/test__serialization.cpp
+3
-3
unit_testing/test__uniform_type.cpp
unit_testing/test__uniform_type.cpp
+3
-2
No files found.
cppa/detail/uniform_type_info_map.hpp
View file @
5c7a8d71
...
@@ -35,6 +35,8 @@
...
@@ -35,6 +35,8 @@
#include <string>
#include <string>
#include <utility> // std::pair
#include <utility> // std::pair
#include "cppa/detail/default_uniform_type_info_impl.hpp"
namespace
cppa
{
class
uniform_type_info
;
}
namespace
cppa
{
class
uniform_type_info
;
}
namespace
cppa
{
namespace
detail
{
namespace
cppa
{
namespace
detail
{
...
@@ -62,11 +64,11 @@ class uniform_type_info_map {
...
@@ -62,11 +64,11 @@ class uniform_type_info_map {
return
m_ints
;
return
m_ints
;
}
}
uniform_type_info
*
by_raw_name
(
const
std
::
string
&
name
)
const
;
const
uniform_type_info
*
by_raw_name
(
const
std
::
string
&
name
)
const
;
uniform_type_info
*
by_uniform_name
(
const
std
::
string
&
name
)
const
;
const
uniform_type_info
*
by_uniform_name
(
const
std
::
string
&
name
)
const
;
std
::
vector
<
uniform_type_info
*>
get_all
()
const
;
std
::
vector
<
const
uniform_type_info
*>
get_all
()
const
;
// NOT thread safe!
// NOT thread safe!
bool
insert
(
const
std
::
set
<
std
::
string
>&
raw_names
,
uniform_type_info
*
uti
);
bool
insert
(
const
std
::
set
<
std
::
string
>&
raw_names
,
uniform_type_info
*
uti
);
...
@@ -82,6 +84,8 @@ class uniform_type_info_map {
...
@@ -82,6 +84,8 @@ class uniform_type_info_map {
// maps sizeof(-integer_type-) to { signed-names-set, unsigned-names-set }
// maps sizeof(-integer_type-) to { signed-names-set, unsigned-names-set }
int_map
m_ints
;
int_map
m_ints
;
};
};
}
}
// namespace cppa::detail
}
}
// namespace cppa::detail
...
...
cppa/uniform_type_info.hpp
View file @
5c7a8d71
...
@@ -170,7 +170,7 @@ class uniform_type_info {
...
@@ -170,7 +170,7 @@ class uniform_type_info {
* @returns The instance associated to @p uniform_name.
* @returns The instance associated to @p uniform_name.
* @throws std::runtime_error if no type named @p uniform_name was found.
* @throws std::runtime_error if no type named @p uniform_name was found.
*/
*/
static
uniform_type_info
*
from
(
const
std
::
string
&
uniform_name
);
static
const
uniform_type_info
*
from
(
const
std
::
string
&
uniform_name
);
/**
/**
* @brief Get instance by std::type_info.
* @brief Get instance by std::type_info.
...
@@ -184,7 +184,7 @@ class uniform_type_info {
...
@@ -184,7 +184,7 @@ class uniform_type_info {
* @brief Get all instances.
* @brief Get all instances.
* @returns A vector with all known (announced) instances.
* @returns A vector with all known (announced) instances.
*/
*/
static
std
::
vector
<
uniform_type_info
*>
instances
();
static
std
::
vector
<
const
uniform_type_info
*>
instances
();
/**
/**
* @brief Get the internal @p libcppa name for this type.
* @brief Get the internal @p libcppa name for this type.
...
...
src/uniform_type_info.cpp
View file @
5c7a8d71
...
@@ -641,100 +641,78 @@ class int_tinfo : public detail::default_uniform_type_info_impl<T> {
...
@@ -641,100 +641,78 @@ class int_tinfo : public detail::default_uniform_type_info_impl<T> {
};
};
using
std
::
is_integral
;
using
std
::
enable_if
;
class
uniform_type_info_map_helper
{
class
uniform_type_info_map_helper
{
friend
class
uniform_type_info_map
;
public:
typedef
uniform_type_info_map
*
this_ptr
;
static
void
insert
(
this_ptr
d
,
uniform_type_info_map_helper
(
uniform_type_info_map
*
umap
)
:
d
(
umap
)
{
}
uniform_type_info
*
uti
,
const
std
::
set
<
std
::
string
>&
tnames
)
{
CPPA_REQUIRE
(
tnames
.
empty
()
==
false
);
for
(
const
std
::
string
&
tname
:
tnames
)
{
d
->
m_by_rname
.
insert
(
std
::
make_pair
(
tname
,
uti
));
}
CPPA_REQUIRE
(
d
->
m_by_uname
.
find
(
uti
->
name
())
==
d
->
m_by_uname
.
end
());
d
->
m_by_uname
.
insert
(
std
::
make_pair
(
uti
->
name
(),
uti
));
}
template
<
typename
T
>
template
<
typename
T
>
static
inline
void
insert
(
this_ptr
d
,
inline
void
insert_int
()
{
const
std
::
set
<
std
::
string
>&
tnames
,
d
->
insert
(
d
->
m_ints
[
sizeof
(
T
)].
first
,
new
int_tinfo
<
T
>
);
typename
enable_if
<
is_integral
<
T
>::
value
>::
type
*
=
0
)
{
insert
(
d
,
new
int_tinfo
<
T
>
,
tnames
);
}
}
template
<
typename
T
>
template
<
typename
T
>
static
inline
void
insert
(
this_ptr
d
,
inline
void
insert_uint
()
{
const
std
::
set
<
std
::
string
>&
tnames
,
d
->
insert
(
d
->
m_ints
[
sizeof
(
T
)].
second
,
new
int_tinfo
<
T
>
);
typename
enable_if
<!
is_integral
<
T
>::
value
>::
type
*
=
0
)
{
insert
(
d
,
new
default_uniform_type_info_impl
<
T
>
(),
tnames
);
}
}
template
<
typename
T
>
template
<
typename
T
>
static
inline
void
insert
(
this_ptr
d
)
{
inline
void
insert_builtin
()
{
insert
<
T
>
(
d
,
{
std
::
string
(
raw_name
<
T
>
())});
d
->
insert
({
raw_name
<
T
>
()},
new
default_uniform_type_info_impl
<
T
>
);
}
static
void
init
(
this_ptr
d
)
{
insert
<
std
::
string
>
(
d
);
insert
<
std
::
u16string
>
(
d
);
insert
<
std
::
u32string
>
(
d
);
insert
(
d
,
new
duration_tinfo
,
{
raw_name
<
util
::
duration
>
()
});
insert
(
d
,
new
any_tuple_tinfo
,
{
raw_name
<
any_tuple
>
()
});
insert
(
d
,
new
actor_ptr_tinfo
,
{
raw_name
<
actor_ptr
>
()
});
insert
(
d
,
new
group_ptr_tinfo
,
{
raw_name
<
actor_ptr
>
()
});
insert
(
d
,
new
channel_ptr_tinfo
,
{
raw_name
<
channel_ptr
>
()
});
insert
(
d
,
new
atom_value_tinfo
,
{
raw_name
<
atom_value
>
()
});
insert
(
d
,
new
addr_msg_tinfo
,
{
raw_name
<
detail
::
addressed_message
>
()
});
insert
(
d
,
new
void_type_tinfo
,
{
raw_name
<
void_type
>
()
});
insert
(
d
,
new
process_info_ptr_tinfo
,
{
raw_name
<
process_information_ptr
>
()});
insert
<
float
>
(
d
);
insert
<
double
>
(
d
);
// first: signed
// second: unsigned
push
<
char
,
signed
char
,
unsigned
char
,
short
,
signed
short
,
unsigned
short
,
short
int
,
signed
short
int
,
unsigned
short
int
,
int
,
signed
int
,
unsigned
int
,
long
int
,
signed
long
int
,
unsigned
long
int
,
long
,
signed
long
,
unsigned
long
,
long
long
,
signed
long
long
,
unsigned
long
long
,
wchar_t
,
char16_t
,
char32_t
>
(
d
->
m_ints
);
insert
<
std
::
int8_t
>
(
d
,
d
->
m_ints
[
sizeof
(
std
::
int8_t
)].
first
);
insert
<
std
::
uint8_t
>
(
d
,
d
->
m_ints
[
sizeof
(
std
::
uint8_t
)].
second
);
insert
<
std
::
int16_t
>
(
d
,
d
->
m_ints
[
sizeof
(
std
::
int16_t
)].
first
);
insert
<
std
::
uint16_t
>
(
d
,
d
->
m_ints
[
sizeof
(
std
::
uint16_t
)].
second
);
insert
<
std
::
int32_t
>
(
d
,
d
->
m_ints
[
sizeof
(
std
::
int32_t
)].
first
);
insert
<
std
::
uint32_t
>
(
d
,
d
->
m_ints
[
sizeof
(
std
::
uint32_t
)].
second
);
insert
<
std
::
int64_t
>
(
d
,
d
->
m_ints
[
sizeof
(
std
::
int64_t
)].
first
);
insert
<
std
::
uint64_t
>
(
d
,
d
->
m_ints
[
sizeof
(
std
::
uint64_t
)].
second
);
}
}
private:
uniform_type_info_map
*
d
;
};
};
uniform_type_info_map
::
uniform_type_info_map
()
{
uniform_type_info_map
::
uniform_type_info_map
()
{
uniform_type_info_map_helper
::
init
(
this
);
push
<
char
,
signed
char
,
unsigned
char
,
short
,
signed
short
,
unsigned
short
,
short
int
,
signed
short
int
,
unsigned
short
int
,
int
,
signed
int
,
unsigned
int
,
long
int
,
signed
long
int
,
unsigned
long
int
,
long
,
signed
long
,
unsigned
long
,
long
long
,
signed
long
long
,
unsigned
long
long
,
wchar_t
,
std
::
int8_t
,
std
::
uint8_t
,
std
::
int16_t
,
std
::
uint16_t
,
std
::
int32_t
,
std
::
uint32_t
,
std
::
int64_t
,
std
::
uint64_t
,
char16_t
,
char32_t
,
size_t
,
ptrdiff_t
,
intptr_t
>
(
m_ints
);
// insert integers
uniform_type_info_map_helper
helper
{
this
};
helper
.
insert_int
<
std
::
int8_t
>
();
helper
.
insert_int
<
std
::
int16_t
>
();
helper
.
insert_int
<
std
::
int32_t
>
();
helper
.
insert_int
<
std
::
int64_t
>
();
helper
.
insert_uint
<
std
::
uint8_t
>
();
helper
.
insert_uint
<
std
::
uint16_t
>
();
helper
.
insert_uint
<
std
::
uint32_t
>
();
helper
.
insert_uint
<
std
::
uint64_t
>
();
// insert built-in types
helper
.
insert_builtin
<
float
>
();
helper
.
insert_builtin
<
double
>
();
helper
.
insert_builtin
<
std
::
string
>
();
helper
.
insert_builtin
<
std
::
u16string
>
();
helper
.
insert_builtin
<
std
::
u32string
>
();
// insert cppa types
insert
({
raw_name
<
util
::
duration
>
()},
new
duration_tinfo
);
insert
({
raw_name
<
any_tuple
>
()},
new
any_tuple_tinfo
);
insert
({
raw_name
<
actor_ptr
>
()},
new
actor_ptr_tinfo
);
insert
({
raw_name
<
group_ptr
>
()},
new
group_ptr_tinfo
);
insert
({
raw_name
<
channel_ptr
>
()},
new
channel_ptr_tinfo
);
insert
({
raw_name
<
atom_value
>
()},
new
atom_value_tinfo
);
insert
({
raw_name
<
detail
::
addressed_message
>
()},
new
addr_msg_tinfo
);
insert
({
raw_name
<
void_type
>
()},
new
void_type_tinfo
);
insert
({
raw_name
<
process_information_ptr
>
()},
new
process_info_ptr_tinfo
);
}
}
uniform_type_info_map
::~
uniform_type_info_map
()
{
uniform_type_info_map
::~
uniform_type_info_map
()
{
...
@@ -746,7 +724,7 @@ uniform_type_info_map::~uniform_type_info_map() {
...
@@ -746,7 +724,7 @@ uniform_type_info_map::~uniform_type_info_map() {
m_by_uname
.
clear
();
m_by_uname
.
clear
();
}
}
uniform_type_info
*
uniform_type_info_map
::
by_raw_name
(
const
std
::
string
&
name
)
const
{
const
uniform_type_info
*
uniform_type_info_map
::
by_raw_name
(
const
std
::
string
&
name
)
const
{
auto
i
=
m_by_rname
.
find
(
name
);
auto
i
=
m_by_rname
.
find
(
name
);
if
(
i
!=
m_by_rname
.
end
())
{
if
(
i
!=
m_by_rname
.
end
())
{
return
i
->
second
;
return
i
->
second
;
...
@@ -754,7 +732,7 @@ uniform_type_info* uniform_type_info_map::by_raw_name(const std::string& name) c
...
@@ -754,7 +732,7 @@ uniform_type_info* uniform_type_info_map::by_raw_name(const std::string& name) c
return
nullptr
;
return
nullptr
;
}
}
uniform_type_info
*
uniform_type_info_map
::
by_uniform_name
(
const
std
::
string
&
name
)
const
{
const
uniform_type_info
*
uniform_type_info_map
::
by_uniform_name
(
const
std
::
string
&
name
)
const
{
auto
i
=
m_by_uname
.
find
(
name
);
auto
i
=
m_by_uname
.
find
(
name
);
if
(
i
!=
m_by_uname
.
end
())
{
if
(
i
!=
m_by_uname
.
end
())
{
return
i
->
second
;
return
i
->
second
;
...
@@ -768,9 +746,9 @@ bool uniform_type_info_map::insert(const std::set<std::string>& raw_names,
...
@@ -768,9 +746,9 @@ bool uniform_type_info_map::insert(const std::set<std::string>& raw_names,
delete
what
;
delete
what
;
return
false
;
return
false
;
}
}
m_by_uname
.
insert
(
std
::
make_pair
(
what
->
name
(),
what
)
);
m_by_uname
.
emplace
(
what
->
name
(),
what
);
for
(
const
std
::
string
&
plain_name
:
raw_names
)
{
for
(
auto
&
plain_name
:
raw_names
)
{
if
(
!
m_by_rname
.
insert
(
std
::
make_pair
(
plain_name
,
what
)
).
second
)
{
if
(
!
m_by_rname
.
emplace
(
plain_name
,
what
).
second
)
{
std
::
string
error_str
=
plain_name
;
std
::
string
error_str
=
plain_name
;
error_str
+=
" already mapped to an uniform_type_info"
;
error_str
+=
" already mapped to an uniform_type_info"
;
throw
std
::
runtime_error
(
error_str
);
throw
std
::
runtime_error
(
error_str
);
...
@@ -779,8 +757,8 @@ bool uniform_type_info_map::insert(const std::set<std::string>& raw_names,
...
@@ -779,8 +757,8 @@ bool uniform_type_info_map::insert(const std::set<std::string>& raw_names,
return
true
;
return
true
;
}
}
std
::
vector
<
uniform_type_info
*>
uniform_type_info_map
::
get_all
()
const
{
std
::
vector
<
const
uniform_type_info
*>
uniform_type_info_map
::
get_all
()
const
{
std
::
vector
<
uniform_type_info
*>
result
;
std
::
vector
<
const
uniform_type_info
*>
result
;
result
.
reserve
(
m_by_uname
.
size
());
result
.
reserve
(
m_by_uname
.
size
());
for
(
const
uti_map
::
value_type
&
i
:
m_by_uname
)
{
for
(
const
uti_map
::
value_type
&
i
:
m_by_uname
)
{
result
.
push_back
(
i
.
second
);
result
.
push_back
(
i
.
second
);
...
@@ -809,7 +787,7 @@ object uniform_type_info::create() const {
...
@@ -809,7 +787,7 @@ object uniform_type_info::create() const {
const
uniform_type_info
*
const
uniform_type_info
*
uniform_type_info
::
from
(
const
std
::
type_info
&
tinf
)
{
uniform_type_info
::
from
(
const
std
::
type_info
&
tinf
)
{
auto
result
=
uti_map
().
by_raw_name
(
raw_name
(
tinf
));
auto
result
=
uti_map
().
by_raw_name
(
raw_name
(
tinf
));
if
(
!
result
)
{
if
(
result
==
nullptr
)
{
std
::
string
error
=
"uniform_type_info::by_type_info(): "
;
std
::
string
error
=
"uniform_type_info::by_type_info(): "
;
error
+=
detail
::
to_uniform_name
(
tinf
);
error
+=
detail
::
to_uniform_name
(
tinf
);
error
+=
" is an unknown typeid name"
;
error
+=
" is an unknown typeid name"
;
...
@@ -818,9 +796,9 @@ uniform_type_info::from(const std::type_info& tinf) {
...
@@ -818,9 +796,9 @@ uniform_type_info::from(const std::type_info& tinf) {
return
result
;
return
result
;
}
}
uniform_type_info
*
uniform_type_info
::
from
(
const
std
::
string
&
name
)
{
const
uniform_type_info
*
uniform_type_info
::
from
(
const
std
::
string
&
name
)
{
auto
result
=
uti_map
().
by_uniform_name
(
name
);
auto
result
=
uti_map
().
by_uniform_name
(
name
);
if
(
!
result
)
{
if
(
result
==
nullptr
)
{
throw
std
::
runtime_error
(
name
+
" is an unknown typeid name"
);
throw
std
::
runtime_error
(
name
+
" is an unknown typeid name"
);
}
}
return
result
;
return
result
;
...
@@ -832,7 +810,7 @@ object uniform_type_info::deserialize(deserializer* from) const {
...
@@ -832,7 +810,7 @@ object uniform_type_info::deserialize(deserializer* from) const {
return
{
ptr
,
this
};
return
{
ptr
,
this
};
}
}
std
::
vector
<
uniform_type_info
*>
uniform_type_info
::
instances
()
{
std
::
vector
<
const
uniform_type_info
*>
uniform_type_info
::
instances
()
{
return
uti_map
().
get_all
();
return
uti_map
().
get_all
();
}
}
...
...
unit_testing/test__pattern.cpp
View file @
5c7a8d71
...
@@ -39,10 +39,10 @@ string plot(const Arr& arr) {
...
@@ -39,10 +39,10 @@ string plot(const Arr& arr) {
return
oss
.
str
();
return
oss
.
str
();
}
}
typedef
std
::
pair
<
int
,
in
t
>
foobar
;
typedef
std
::
pair
<
std
::
int32_t
,
std
::
int32_
t
>
foobar
;
static
detail
::
types_array
<
int
,
anything
,
float
>
arr1
;
static
detail
::
types_array
<
int
,
anything
,
float
>
arr1
;
static
detail
::
types_array
<
int
,
anything
,
foobar
>
arr2
;
static
detail
::
types_array
<
int
,
anything
,
foobar
>
arr2
;
template
<
typename
T
>
template
<
typename
T
>
void
match_test
(
const
T
&
value
)
{
void
match_test
(
const
T
&
value
)
{
...
...
unit_testing/test__serialization.cpp
View file @
5c7a8d71
unit_testing/test__uniform_type.cpp
View file @
5c7a8d71
...
@@ -47,7 +47,8 @@ size_t test__uniform_type() {
...
@@ -47,7 +47,8 @@ size_t test__uniform_type() {
bool
announce1
=
announce
<
foo
>
(
&
foo
::
value
);
bool
announce1
=
announce
<
foo
>
(
&
foo
::
value
);
bool
announce2
=
announce
<
foo
>
(
&
foo
::
value
);
bool
announce2
=
announce
<
foo
>
(
&
foo
::
value
);
bool
announce3
=
announce
<
foo
>
(
&
foo
::
value
);
bool
announce3
=
announce
<
foo
>
(
&
foo
::
value
);
bool
announce4
=
announce
<
foo
>
(
&
foo
::
value
);
{
bool
announce4
=
announce
<
foo
>
(
&
foo
::
value
);
{
//bar.create_object();
//bar.create_object();
object
obj1
=
uniform_typeid
<
foo
>
()
->
create
();
object
obj1
=
uniform_typeid
<
foo
>
()
->
create
();
object
obj2
(
obj1
);
object
obj2
(
obj1
);
...
@@ -86,7 +87,7 @@ size_t test__uniform_type() {
...
@@ -86,7 +87,7 @@ size_t test__uniform_type() {
std
::
set
<
std
::
string
>
found
;
std
::
set
<
std
::
string
>
found
;
// fetch all available type names
// fetch all available type names
auto
types
=
uniform_type_info
::
instances
();
auto
types
=
uniform_type_info
::
instances
();
for
(
uniform_type_info
*
tinfo
:
types
)
{
for
(
auto
tinfo
:
types
)
{
found
.
insert
(
tinfo
->
name
());
found
.
insert
(
tinfo
->
name
());
}
}
// compare the two sets
// compare the two sets
...
...
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