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
cc1a1fc6
Commit
cc1a1fc6
authored
Apr 25, 2011
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
serialization testing
parent
97aff6bf
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
1444 additions
and
608 deletions
+1444
-608
cppa.creator.user
cppa.creator.user
+120
-102
cppa/detail/default_uniform_type_info_impl.hpp
cppa/detail/default_uniform_type_info_impl.hpp
+1
-1
cppa/object.hpp
cppa/object.hpp
+86
-27
cppa/util/callable_trait.hpp
cppa/util/callable_trait.hpp
+16
-16
cppa/util/enable_if.hpp
cppa/util/enable_if.hpp
+2
-2
src/uniform_type_info.cpp
src/uniform_type_info.cpp
+1
-1
unit_testing/test__serialization.cpp
unit_testing/test__serialization.cpp
+1179
-437
unit_testing/test__type_list.cpp
unit_testing/test__type_list.cpp
+0
-1
unit_testing/test__uniform_type.cpp
unit_testing/test__uniform_type.cpp
+39
-21
No files found.
cppa.creator.user
View file @
cc1a1fc6
This diff is collapsed.
Click to expand it.
cppa/detail/default_uniform_type_info_impl.hpp
View file @
cc1a1fc6
...
...
@@ -72,7 +72,7 @@ class default_uniform_type_info_impl : public uniform_type_info
object
create
()
const
{
return
{
new
T
,
this
};
return
{
new
T
()
,
this
};
}
};
...
...
cppa/object.hpp
View file @
cc1a1fc6
...
...
@@ -4,17 +4,17 @@
#include <string>
#include <typeinfo>
#include <stdexcept>
#include <type_traits>
#include "cppa/util/disjunction.hpp"
namespace
cppa
{
// forward declarations
class
object
;
class
uniform_type_info
;
template
<
typename
T
>
T
&
object_cast
(
object
&
obj
);
template
<
typename
T
>
const
T
&
object_cast
(
const
object
&
obj
);
namespace
detail
{
template
<
typename
T
>
struct
object_caster
;
}
bool
operator
==
(
const
uniform_type_info
&
lhs
,
const
std
::
type_info
&
rhs
);
/**
* @brief foobar.
...
...
@@ -25,10 +25,7 @@ class object
friend
class
uniform_type_info
;
template
<
typename
T
>
friend
T
&
object_cast
(
object
&
obj
);
template
<
typename
T
>
friend
const
T
&
object_cast
(
const
object
&
obj
);
friend
struct
detail
::
object_caster
;
void
*
m_value
;
const
uniform_type_info
*
m_type
;
...
...
@@ -80,40 +77,102 @@ public:
};
// forward declaration of the == operator
bool
operator
==
(
const
uniform_type_info
&
lhs
,
const
std
::
type_info
&
rhs
);
inline
bool
operator
==
(
const
object
&
lhs
,
const
object
&
rhs
)
{
return
lhs
.
equal
(
rhs
);
}
template
<
typename
T
>
T
&
object_cast
(
object
&
obj
)
inline
bool
operator
!=
(
const
object
&
lhs
,
const
object
&
rhs
)
{
// if (!(obj.type() == typeid(T)))
if
(
!
operator
==
(
obj
.
type
(),
typeid
(
T
)))
return
!
(
lhs
==
rhs
);
}
namespace
detail
{
inline
void
assert_type
(
const
object
&
obj
,
const
std
::
type_info
&
tinfo
)
{
if
(
!
(
obj
.
type
()
==
tinfo
))
{
throw
std
::
logic_error
(
"object type doesnt match T"
);
}
return
*
reinterpret_cast
<
T
*>
(
obj
.
m_value
);
}
// get a const reference
template
<
typename
T
>
const
T
&
object_cast
(
const
object
&
obj
)
struct
object_caster
<
const
T
&>
{
if
(
!
(
obj
.
type
()
==
typeid
(
T
))
)
static
const
T
&
_
(
const
object
&
obj
)
{
throw
std
::
logic_error
(
"object type doesnt match T"
);
}
assert_type
(
obj
,
typeid
(
T
));
return
*
reinterpret_cast
<
const
T
*>
(
obj
.
m_value
);
}
}
};
}
// namespace cppa
// get a mutable reference
template
<
typename
T
>
struct
object_caster
<
T
&>
{
static
T
&
_
(
object
&
obj
)
{
assert_type
(
obj
,
typeid
(
T
));
return
*
reinterpret_cast
<
T
*>
(
obj
.
m_value
);
}
};
inline
bool
operator
==
(
const
cppa
::
object
&
lhs
,
const
cppa
::
object
&
rhs
)
// get a const pointer
template
<
typename
T
>
struct
object_caster
<
const
T
*>
{
return
lhs
.
equal
(
rhs
);
static
const
T
*
_
(
const
object
&
obj
)
{
assert_type
(
obj
,
typeid
(
T
));
return
reinterpret_cast
<
const
T
*>
(
obj
.
m_value
);
}
};
// get a mutable pointer
template
<
typename
T
>
struct
object_caster
<
T
*>
{
static
T
*
_
(
object
&
obj
)
{
assert_type
(
obj
,
typeid
(
T
));
return
reinterpret_cast
<
T
*>
(
obj
.
m_value
);
}
};
template
<
typename
T
>
struct
is_const_reference
:
std
::
false_type
{
};
template
<
typename
T
>
struct
is_const_reference
<
const
T
&>
:
std
::
true_type
{
};
template
<
typename
T
>
struct
is_const_pointer
:
std
::
false_type
{
};
template
<
typename
T
>
struct
is_const_pointer
<
const
T
*>
:
std
::
true_type
{
};
}
inline
bool
operator
!=
(
const
cppa
::
object
&
lhs
,
const
cppa
::
object
&
rhs
)
template
<
typename
T
>
T
object_cast
(
object
&
obj
)
{
return
!
(
lhs
==
rhs
);
static_assert
(
util
::
disjunction
<
std
::
is_pointer
<
T
>
,
std
::
is_reference
<
T
>>::
value
,
"T is neither a reference nor a pointer type."
);
return
detail
::
object_caster
<
T
>::
_
(
obj
);
}
template
<
typename
T
>
const
T
&
object_cast
(
const
object
&
obj
)
{
static_assert
(
util
::
disjunction
<
detail
::
is_const_pointer
<
T
>
,
detail
::
is_const_reference
<
T
>>::
value
,
"T is neither a const reference nor a const pointer type."
);
return
detail
::
object_caster
<
T
>::
_
(
obj
);
}
}
// namespace cppa
#endif // OBJECT_HPP
cppa/util/callable_trait.hpp
View file @
cc1a1fc6
...
...
@@ -8,31 +8,31 @@ namespace cppa { namespace util {
template
<
typename
Signature
>
struct
callable_trait
;
template
<
class
C
,
typename
Result
,
typename
...
Args
>
struct
callable_trait
<
Result
(
C
::*
)(
Args
...)
const
>
template
<
class
C
,
typename
Result
Type
,
typename
...
Args
>
struct
callable_trait
<
Result
Type
(
C
::*
)(
Args
...)
const
>
{
typedef
Result
result_type
;
typedef
ResultType
result_type
;
typedef
type_list
<
Args
...
>
arg_types
;
};
template
<
class
C
,
typename
Result
,
typename
...
Args
>
struct
callable_trait
<
Result
(
C
::*
)(
Args
...)
>
template
<
class
C
,
typename
Result
Type
,
typename
...
Args
>
struct
callable_trait
<
Result
Type
(
C
::*
)(
Args
...)
>
{
typedef
Result
result_type
;
typedef
ResultType
result_type
;
typedef
type_list
<
Args
...
>
arg_types
;
};
template
<
typename
Result
,
typename
...
Args
>
struct
callable_trait
<
Result
(
Args
...)
>
template
<
typename
Result
Type
,
typename
...
Args
>
struct
callable_trait
<
Result
Type
(
Args
...)
>
{
typedef
Result
result_type
;
typedef
ResultType
result_type
;
typedef
type_list
<
Args
...
>
arg_types
;
};
template
<
typename
Result
,
typename
...
Args
>
struct
callable_trait
<
Result
(
*
)(
Args
...)
>
template
<
typename
Result
Type
,
typename
...
Args
>
struct
callable_trait
<
Result
Type
(
*
)(
Args
...)
>
{
typedef
Result
result_type
;
typedef
ResultType
result_type
;
typedef
type_list
<
Args
...
>
arg_types
;
};
...
...
cppa/util/enable_if.hpp
View file @
cc1a1fc6
...
...
@@ -3,7 +3,7 @@
namespace
cppa
{
namespace
util
{
template
<
bool
Stmt
,
typename
T
>
template
<
bool
Stmt
,
typename
T
=
void
>
struct
enable_if_c
{
};
template
<
typename
T
>
...
...
@@ -12,7 +12,7 @@ struct enable_if_c<true, T>
typedef
T
type
;
};
template
<
class
Trait
,
typename
T
>
template
<
class
Trait
,
typename
T
=
void
>
struct
enable_if
:
enable_if_c
<
Trait
::
value
,
T
>
{
};
...
...
src/uniform_type_info.cpp
View file @
cc1a1fc6
...
...
@@ -314,7 +314,7 @@ uniform_type_info_map& s_uniform_type_info_map()
return
s_utimap
;
}
}
}
}
// namespace detail::<anonymous>
}
}
}
// namespace
cppa::
detail::<anonymous>
namespace
{
...
...
unit_testing/test__serialization.cpp
View file @
cc1a1fc6
This diff is collapsed.
Click to expand it.
unit_testing/test__type_list.cpp
View file @
cc1a1fc6
...
...
@@ -60,7 +60,6 @@ std::size_t test__type_list()
++
i
;
CPPA_CHECK
((
i
==
ifc
.
end
()));
return
CPPA_TEST_RESULT
;
}
unit_testing/test__uniform_type.cpp
View file @
cc1a1fc6
...
...
@@ -25,9 +25,6 @@
using
std
::
cout
;
using
std
::
endl
;
using
cppa
::
object
;
using
cppa
::
uniform_type_info
;
namespace
{
struct
foo
...
...
@@ -43,14 +40,16 @@ bool operator==(const foo& lhs, const foo& rhs)
}
// namespace <anonymous>
using
namespace
cppa
;
namespace
{
static
bool
unused1
=
cppa
::
uniform_type_info
::
announce
<
foo
>
(
[]
(
cppa
::
serializer
&
s
,
const
foo
&
f
)
{
uniform_type_info
::
announce
<
foo
>
(
[]
(
serializer
&
s
,
const
foo
&
f
)
{
s
<<
f
.
value
;
},
[]
(
cppa
::
deserializer
&
d
,
foo
&
f
)
{
[]
(
deserializer
&
d
,
foo
&
f
)
{
d
>>
f
.
value
;
},
[]
(
const
foo
&
f
)
->
std
::
string
{
...
...
@@ -65,9 +64,9 @@ static bool unused1 =
return
new
foo
(
tmp
);
}
);
bool
unused2
=
false
;
// =
cppa::
uniform_type_info::announce(typeid(foo), new uti_impl<foo>);
bool
unused3
=
false
;
//=
cppa::
uniform_type_info::announce(typeid(foo), new uti_impl<foo>);
bool
unused4
=
false
;
//=
cppa::
uniform_type_info::announce(typeid(foo), new uti_impl<foo>);
bool
unused2
=
false
;
// = uniform_type_info::announce(typeid(foo), new uti_impl<foo>);
bool
unused3
=
false
;
//= uniform_type_info::announce(typeid(foo), new uti_impl<foo>);
bool
unused4
=
false
;
//= uniform_type_info::announce(typeid(foo), new uti_impl<foo>);
}
// namespace <anonymous>
...
...
@@ -77,18 +76,21 @@ std::size_t test__uniform_type()
{
//bar.create_object();
object
obj1
=
cppa
::
uniform_typeid
<
foo
>
()
->
create
();
object
obj1
=
uniform_typeid
<
foo
>
()
->
create
();
object
obj2
(
obj1
);
CPPA_CHECK_EQUAL
(
obj1
,
obj2
);
}
{
object
wstr_obj1
=
cppa
::
uniform_typeid
<
std
::
wstring
>
()
->
create
();
cppa
::
object_cast
<
std
::
wstring
>
(
wstr_obj1
)
=
L"hello wstring!"
;
object
wstr_obj2
=
cppa
::
uniform_typeid
<
std
::
wstring
>
()
->
from_string
(
"hello wstring!"
);
object
wstr_obj1
=
uniform_typeid
<
std
::
wstring
>
()
->
create
();
object_cast
<
std
::
wstring
&
>
(
wstr_obj1
)
=
L"hello wstring!"
;
object
wstr_obj2
=
uniform_typeid
<
std
::
wstring
>
()
->
from_string
(
"hello wstring!"
);
CPPA_CHECK_EQUAL
(
wstr_obj1
,
wstr_obj2
);
const
object
&
obj2_ref
=
wstr_obj2
;
CPPA_CHECK_EQUAL
(
object_cast
<
std
::
wstring
&>
(
wstr_obj1
),
object_cast
<
const
std
::
wstring
&>
(
obj2_ref
));
// couldn't be converted to ASCII
cppa
::
object_cast
<
std
::
wstring
>
(
wstr_obj1
)
=
L"hello wstring
\x05D4
"
;
object_cast
<
std
::
wstring
&
>
(
wstr_obj1
)
=
L"hello wstring
\x05D4
"
;
std
::
string
narrowed
=
wstr_obj1
.
to_string
();
CPPA_CHECK_EQUAL
(
narrowed
,
"hello wstring?"
);
}
...
...
@@ -102,15 +104,15 @@ std::size_t test__uniform_type()
// test foo_object implementation
/*
obj_ptr o =
cppa::
uniform_typeid<foo>()->create();
obj_ptr o = uniform_typeid<foo>()->create();
o->from_string("123");
CPPA_CHECK_EQUAL(o->to_string(), "123");
int val = reinterpret_cast<const foo*>(o->value())->value;
CPPA_CHECK_EQUAL(val, 123);
*/
// these types (and only those) are present if
the uniform_type_info
// implementation is correct
// these types (and only those) are present if
//
the uniform_type_info
implementation is correct
std
::
set
<
std
::
string
>
expected
=
{
"@_::foo"
,
// name of <anonymous namespace>::foo
...
...
@@ -118,7 +120,7 @@ std::size_t test__uniform_type()
"@u8"
,
"@u16"
,
"@u32"
,
"@u64"
,
// unsigned integer names
"@str"
,
"@wstr"
,
// strings
"float"
,
"double"
,
// floating points
"@0"
,
//
cppa::
util::void_type
"@0"
,
// util::void_type
// default announced cppa types
"cppa::any_type"
,
"cppa::intrusive_ptr<cppa::actor>"
...
...
@@ -134,8 +136,8 @@ std::size_t test__uniform_type()
std
::
set
<
std
::
string
>
found
;
// fetch all available type names
auto
types
=
cppa
::
uniform_type_info
::
instances
();
for
(
cppa
::
uniform_type_info
*
tinfo
:
types
)
auto
types
=
uniform_type_info
::
instances
();
for
(
uniform_type_info
*
tinfo
:
types
)
{
found
.
insert
(
tinfo
->
name
());
}
...
...
@@ -145,7 +147,23 @@ std::size_t test__uniform_type()
if
(
expected
.
size
()
==
found
.
size
())
{
CPPA_CHECK
((
std
::
equal
(
found
.
begin
(),
found
.
end
(),
expected
.
begin
())));
bool
expected_equals_found
=
std
::
equal
(
found
.
begin
(),
found
.
end
(),
expected
.
begin
());
CPPA_CHECK
(
expected_equals_found
);
if
(
!
expected_equals_found
)
{
cout
<<
"found:"
<<
endl
;
for
(
const
std
::
string
&
tname
:
found
)
{
cout
<<
" - "
<<
tname
<<
endl
;
}
cout
<<
"expected: "
<<
endl
;
for
(
const
std
::
string
&
tname
:
expected
)
{
cout
<<
" - "
<<
tname
<<
endl
;
}
}
}
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