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
97aff6bf
Commit
97aff6bf
authored
Apr 21, 2011
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
uniform_type_info and object improvements
parent
61cf341e
Changes
26
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
2295 additions
and
315 deletions
+2295
-315
.gitignore
.gitignore
+1
-0
cppa.creator.user
cppa.creator.user
+3
-3
cppa.files
cppa.files
+3
-3
cppa/actor.hpp
cppa/actor.hpp
+3
-3
cppa/deserializer.hpp
cppa/deserializer.hpp
+11
-13
cppa/detail/default_object_impl.hpp
cppa/detail/default_object_impl.hpp
+0
-59
cppa/detail/default_uniform_type_info_impl.hpp
cppa/detail/default_uniform_type_info_impl.hpp
+82
-0
cppa/intrusive_ptr.hpp
cppa/intrusive_ptr.hpp
+3
-3
cppa/object.hpp
cppa/object.hpp
+101
-14
cppa/serializer.hpp
cppa/serializer.hpp
+19
-14
cppa/uniform_type_info.hpp
cppa/uniform_type_info.hpp
+245
-61
cppa/util/callable_trait.hpp
cppa/util/callable_trait.hpp
+4
-4
cppa/util/comparable.hpp
cppa/util/comparable.hpp
+12
-4
cppa/util/default_object_base.hpp
cppa/util/default_object_base.hpp
+0
-46
cppa/util/type_list.hpp
cppa/util/type_list.hpp
+11
-2
cppa/util/void_type.hpp
cppa/util/void_type.hpp
+2
-0
libcppa.Makefile
libcppa.Makefile
+1
-0
libcppa.doxygen
libcppa.doxygen
+1511
-0
src/deserializer.cpp
src/deserializer.cpp
+4
-4
src/object.cpp
src/object.cpp
+87
-0
src/serializer.cpp
src/serializer.cpp
+4
-4
src/to_uniform_name.cpp
src/to_uniform_name.cpp
+2
-0
src/uniform_type_info.cpp
src/uniform_type_info.cpp
+99
-38
unit_testing/test__local_group.cpp
unit_testing/test__local_group.cpp
+15
-0
unit_testing/test__serialization.cpp
unit_testing/test__serialization.cpp
+15
-0
unit_testing/test__uniform_type.cpp
unit_testing/test__uniform_type.cpp
+57
-40
No files found.
.gitignore
View file @
97aff6bf
html/
.DS_Store
.DS_Store
*.o
*.o
*.dylib
*.dylib
...
...
cppa.creator.user
View file @
97aff6bf
...
@@ -60,14 +60,14 @@
...
@@ -60,14 +60,14 @@
<valuemap
type=
"QVariantMap"
>
<valuemap
type=
"QVariantMap"
>
<value
key=
"ProjectExplorer.BuildConfiguration.DisplayName"
type=
"QString"
>
all
</value>
<value
key=
"ProjectExplorer.BuildConfiguration.DisplayName"
type=
"QString"
>
all
</value>
<valuelist
key=
"abstractProcess.Environment"
type=
"QVariantList"
>
<valuelist
key=
"abstractProcess.Environment"
type=
"QVariantList"
>
<value
type=
"QString"
>
Apple_PubSub_Socket_Render=/tmp/launch-
tO8Wwx
/Render
</value>
<value
type=
"QString"
>
Apple_PubSub_Socket_Render=/tmp/launch-
m6Qmev
/Render
</value>
<value
type=
"QString"
>
COMMAND_MODE=unix2003
</value>
<value
type=
"QString"
>
COMMAND_MODE=unix2003
</value>
<value
type=
"QString"
>
DISPLAY=/tmp/launch-
w1qNYf
/org.x:0
</value>
<value
type=
"QString"
>
DISPLAY=/tmp/launch-
Yl5R56
/org.x:0
</value>
<value
type=
"QString"
>
HOME=/Users/neverlord
</value>
<value
type=
"QString"
>
HOME=/Users/neverlord
</value>
<value
type=
"QString"
>
LOGNAME=neverlord
</value>
<value
type=
"QString"
>
LOGNAME=neverlord
</value>
<value
type=
"QString"
>
PATH=/usr/bin:/bin:/usr/sbin:/sbin
</value>
<value
type=
"QString"
>
PATH=/usr/bin:/bin:/usr/sbin:/sbin
</value>
<value
type=
"QString"
>
SHELL=/bin/bash
</value>
<value
type=
"QString"
>
SHELL=/bin/bash
</value>
<value
type=
"QString"
>
SSH_AUTH_SOCK=/tmp/launch-
dnUZas
/Listeners
</value>
<value
type=
"QString"
>
SSH_AUTH_SOCK=/tmp/launch-
3kvI77
/Listeners
</value>
<value
type=
"QString"
>
TMPDIR=/var/folders/SE/SEReyCW0H-yDPCnNCe8mN++++TI/-Tmp-/
</value>
<value
type=
"QString"
>
TMPDIR=/var/folders/SE/SEReyCW0H-yDPCnNCe8mN++++TI/-Tmp-/
</value>
<value
type=
"QString"
>
USER=neverlord
</value>
<value
type=
"QString"
>
USER=neverlord
</value>
<value
type=
"QString"
>
__CF_USER_TEXT_ENCODING=0x1F5:0:3
</value>
<value
type=
"QString"
>
__CF_USER_TEXT_ENCODING=0x1F5:0:3
</value>
...
...
cppa.files
View file @
97aff6bf
...
@@ -73,7 +73,6 @@ cppa/detail/serialize_tuple.hpp
...
@@ -73,7 +73,6 @@ cppa/detail/serialize_tuple.hpp
unit_testing/test__atom.cpp
unit_testing/test__atom.cpp
unit_testing/test__queue_performance.cpp
unit_testing/test__queue_performance.cpp
cppa/detail/actor_public.hpp
cppa/detail/actor_public.hpp
cppa/detail/comparable.hpp
cppa/util/single_reader_queue.hpp
cppa/util/single_reader_queue.hpp
cppa/util/singly_linked_list.hpp
cppa/util/singly_linked_list.hpp
cppa/detail/actor_private.hpp
cppa/detail/actor_private.hpp
...
@@ -116,5 +115,6 @@ cppa/detail/demangle.hpp
...
@@ -116,5 +115,6 @@ cppa/detail/demangle.hpp
src/demangle.cpp
src/demangle.cpp
cppa/detail/to_uniform_name.hpp
cppa/detail/to_uniform_name.hpp
src/to_uniform_name.cpp
src/to_uniform_name.cpp
cppa/util/default_object_base.hpp
cppa/detail/default_uniform_type_info_impl.hpp
cppa/detail/default_object_impl.hpp
src/object.cpp
cppa/util/comparable.hpp
cppa/actor.hpp
View file @
97aff6bf
...
@@ -26,10 +26,10 @@ class actor : public channel
...
@@ -26,10 +26,10 @@ class actor : public channel
typedef
intrusive_ptr
<
actor
>
actor_ptr
;
typedef
intrusive_ptr
<
actor
>
actor_ptr
;
}
// namespace cppa
serializer
&
operator
<<
(
serializer
&
,
const
actor_ptr
&
);
cppa
::
serializer
&
operator
<<
(
cppa
::
serializer
&
,
const
cppa
::
actor_ptr
&
);
deserializer
&
operator
>>
(
deserializer
&
,
actor_ptr
&
);
cppa
::
deserializer
&
operator
>>
(
cppa
::
deserializer
&
,
cppa
::
actor_ptr
&
);
}
// namespace cppa
#endif // ACTOR_HPP
#endif // ACTOR_HPP
cppa/deserializer.hpp
View file @
97aff6bf
...
@@ -17,7 +17,7 @@ namespace cppa { namespace util {
...
@@ -17,7 +17,7 @@ namespace cppa { namespace util {
struct
void_type
;
struct
void_type
;
}
}
// namespace
cppa::
util
}
}
// namespace util
namespace
cppa
{
namespace
cppa
{
...
@@ -37,37 +37,35 @@ class deserializer
...
@@ -37,37 +37,35 @@ class deserializer
};
};
}
// namespace cppa
deserializer
&
operator
>>
(
deserializer
&
,
std
::
string
&
);
cppa
::
deserializer
&
operator
>>
(
cppa
::
deserializer
&
,
std
::
string
&
);
template
<
typename
T
>
template
<
typename
T
>
typename
cppa
::
util
::
enable_if
<
std
::
is_integral
<
T
>
,
cppa
::
deserializer
&>::
type
typename
util
::
enable_if
<
std
::
is_integral
<
T
>
,
deserializer
&>::
type
operator
>>
(
cppa
::
deserializer
&
d
,
T
&
value
)
operator
>>
(
deserializer
&
d
,
T
&
value
)
{
{
d
.
read
(
sizeof
(
T
),
&
value
);
d
.
read
(
sizeof
(
T
),
&
value
);
value
=
cppa
::
detail
::
swap_bytes
(
value
);
value
=
detail
::
swap_bytes
(
value
);
return
d
;
return
d
;
}
}
template
<
typename
T
>
template
<
typename
T
>
typename
cppa
::
util
::
enable_if
<
std
::
is_floating_point
<
T
>
,
typename
util
::
enable_if
<
std
::
is_floating_point
<
T
>
,
deserializer
&>::
type
cppa
::
deserializer
&>::
type
operator
>>
(
deserializer
&
d
,
T
&
value
)
operator
>>
(
cppa
::
deserializer
&
d
,
T
&
value
)
{
{
d
.
read
(
sizeof
(
T
),
&
value
);
d
.
read
(
sizeof
(
T
),
&
value
);
return
d
;
return
d
;
}
}
inline
cppa
::
deserializer
&
operator
>>
(
cppa
::
deserializer
&
d
,
inline
deserializer
&
operator
>>
(
deserializer
&
d
,
util
::
void_type
&
)
cppa
::
util
::
void_type
&
)
{
{
return
d
;
return
d
;
}
}
inline
cppa
::
deserializer
&
operator
>>
(
cppa
::
deserializer
&
d
,
cppa
::
any_type
&
)
inline
deserializer
&
operator
>>
(
deserializer
&
d
,
any_type
&
)
{
{
return
d
;
return
d
;
}
}
}
// namespace cppa
#endif // DESERIALIZER_HPP
#endif // DESERIALIZER_HPP
cppa/detail/default_object_impl.hpp
deleted
100644 → 0
View file @
61cf341e
#ifndef DEFAULT_OBJECT_IMPL_HPP
#define DEFAULT_OBJECT_IMPL_HPP
#include <sstream>
#include "cppa/serializer.hpp"
#include "cppa/deserializer.hpp"
#include "cppa/util/default_object_base.hpp"
namespace
cppa
{
namespace
detail
{
template
<
typename
T
>
class
default_object_impl
:
public
util
::
default_object_base
<
T
>
{
typedef
util
::
default_object_base
<
T
>
super
;
public:
default_object_impl
(
const
uniform_type_info
*
uti
,
const
T
&
val
=
T
())
:
super
(
uti
,
val
)
{
}
object
*
copy
/*[[override]]*/
()
const
{
return
new
default_object_impl
(
this
->
type
(),
this
->
m_value
);
}
std
::
string
to_string
/*[[override]]*/
()
const
{
std
::
ostringstream
sstr
;
sstr
<<
this
->
m_value
;
return
sstr
.
str
();
}
void
from_string
/*[[override]]*/
(
const
std
::
string
&
str
)
{
T
tmp
;
std
::
istringstream
istr
(
str
);
istr
>>
tmp
;
this
->
m_value
=
std
::
move
(
tmp
);
}
void
deserialize
/*[[override]]*/
(
deserializer
&
d
)
{
d
>>
this
->
m_value
;
}
void
serialize
/*[[override]]*/
(
serializer
&
s
)
const
{
s
<<
this
->
m_value
;
}
};
}
}
// namespace cppa::detail
#endif // DEFAULT_OBJECT_IMPL_HPP
cppa/detail/default_uniform_type_info_impl.hpp
0 → 100644
View file @
97aff6bf
#ifndef DEFAULT_UNIFORM_TYPE_INFO_IMPL_HPP
#define DEFAULT_UNIFORM_TYPE_INFO_IMPL_HPP
#include <sstream>
#include "cppa/uniform_type_info.hpp"
namespace
cppa
{
namespace
detail
{
template
<
typename
T
>
class
default_uniform_type_info_impl
:
public
uniform_type_info
{
inline
T
&
to_ref
(
object
&
what
)
const
{
return
*
reinterpret_cast
<
T
*>
(
this
->
value_of
(
what
));
}
inline
const
T
&
to_ref
(
const
object
&
what
)
const
{
return
*
reinterpret_cast
<
const
T
*>
(
this
->
value_of
(
what
));
}
protected:
object
copy
(
const
object
&
what
)
const
{
return
{
new
T
(
to_ref
(
what
)),
this
};
}
object
from_string
(
const
std
::
string
&
str
)
const
{
std
::
istringstream
istr
(
str
);
T
tmp
;
istr
>>
tmp
;
return
{
new
T
(
tmp
),
this
};
}
void
destroy
(
object
&
what
)
const
{
delete
reinterpret_cast
<
T
*>
(
value_of
(
what
));
value_of
(
what
)
=
nullptr
;
}
void
deserialize
(
deserializer
&
d
,
object
&
what
)
const
{
d
>>
to_ref
(
what
);
}
std
::
string
to_string
(
const
object
&
obj
)
const
{
std
::
ostringstream
ostr
;
ostr
<<
to_ref
(
obj
);
return
ostr
.
str
();
}
bool
equal
(
const
object
&
lhs
,
const
object
&
rhs
)
const
{
return
(
lhs
.
type
()
==
*
this
&&
rhs
.
type
()
==
*
this
)
?
to_ref
(
lhs
)
==
to_ref
(
rhs
)
:
false
;
}
void
serialize
(
serializer
&
s
,
const
object
&
what
)
const
{
s
<<
to_ref
(
what
);
}
public:
default_uniform_type_info_impl
()
:
cppa
::
uniform_type_info
(
typeid
(
T
))
{
}
object
create
()
const
{
return
{
new
T
,
this
};
}
};
}
}
// namespace detail
#endif // DEFAULT_UNIFORM_TYPE_INFO_IMPL_HPP
cppa/intrusive_ptr.hpp
View file @
97aff6bf
...
@@ -6,13 +6,13 @@
...
@@ -6,13 +6,13 @@
#include <stdexcept>
#include <stdexcept>
#include <type_traits>
#include <type_traits>
#include <cppa/
deta
il/comparable.hpp>
#include <cppa/
ut
il/comparable.hpp>
namespace
cppa
{
namespace
cppa
{
template
<
typename
T
>
template
<
typename
T
>
class
intrusive_ptr
:
deta
il
::
comparable
<
intrusive_ptr
<
T
>
,
T
*>
,
class
intrusive_ptr
:
ut
il
::
comparable
<
intrusive_ptr
<
T
>
,
T
*>
,
deta
il
::
comparable
<
intrusive_ptr
<
T
>>
ut
il
::
comparable
<
intrusive_ptr
<
T
>>
{
{
T
*
m_ptr
;
T
*
m_ptr
;
...
...
cppa/object.hpp
View file @
97aff6bf
...
@@ -2,31 +2,118 @@
...
@@ -2,31 +2,118 @@
#define OBJECT_HPP
#define OBJECT_HPP
#include <string>
#include <string>
#include "cppa/ref_counted.hpp"
#include <typeinfo>
#include <stdexcept>
namespace
cppa
{
namespace
cppa
{
class
object
;
class
uniform_type_info
;
class
uniform_type_info
;
class
serializer
;
class
deserializer
;
class
object
:
public
ref_counted
template
<
typename
T
>
T
&
object_cast
(
object
&
obj
);
template
<
typename
T
>
const
T
&
object_cast
(
const
object
&
obj
);
/**
* @brief foobar.
*/
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
);
void
*
m_value
;
const
uniform_type_info
*
m_type
;
void
swap
(
object
&
other
);
object
copy
()
const
;
public:
public:
// mutators
/**
virtual
void
*
mutable_value
()
=
0
;
* @brief Create an object of type @p utinfo with value @p val.
virtual
void
deserialize
(
deserializer
&
)
=
0
;
* @warning {@link object} takes ownership of @p val.
virtual
void
from_string
(
const
std
::
string
&
)
=
0
;
* @pre {@code val != nullptr && utinfo != nullptr}
// accessors
*/
virtual
object
*
copy
()
const
=
0
;
object
(
void
*
val
,
const
uniform_type_info
*
utinfo
);
virtual
const
uniform_type_info
*
type
()
const
=
0
;
virtual
const
void
*
value
()
const
=
0
;
/**
virtual
std
::
string
to_string
()
const
=
0
;
* @brief Create a void object.
virtual
void
serialize
(
serializer
&
)
const
=
0
;
* @post {@code type() == uniform_typeid<util::void_type>()}
*/
object
();
~
object
();
/**
* @brief Create an object and move type and value from @p other to this.
* @post {@code other.type() == uniform_typeid<util::void_type>()}
*/
object
(
object
&&
other
);
/**
* @brief Create a copy of @p other.
*/
object
(
const
object
&
other
);
/**
* @brief Move the content from @p other to this.
* @post {@code other.type() == nullptr}
*/
object
&
operator
=
(
object
&&
other
);
object
&
operator
=
(
const
object
&
other
);
bool
equal
(
const
object
&
other
)
const
;
const
uniform_type_info
&
type
()
const
;
std
::
string
to_string
()
const
;
};
};
// forward declaration of the == operator
bool
operator
==
(
const
uniform_type_info
&
lhs
,
const
std
::
type_info
&
rhs
);
template
<
typename
T
>
T
&
object_cast
(
object
&
obj
)
{
// if (!(obj.type() == typeid(T)))
if
(
!
operator
==
(
obj
.
type
(),
typeid
(
T
)))
{
throw
std
::
logic_error
(
"object type doesnt match T"
);
}
return
*
reinterpret_cast
<
T
*>
(
obj
.
m_value
);
}
template
<
typename
T
>
const
T
&
object_cast
(
const
object
&
obj
)
{
if
(
!
(
obj
.
type
()
==
typeid
(
T
)))
{
throw
std
::
logic_error
(
"object type doesnt match T"
);
}
return
*
reinterpret_cast
<
const
T
*>
(
obj
.
m_value
);
}
}
// namespace cppa
}
// namespace cppa
inline
bool
operator
==
(
const
cppa
::
object
&
lhs
,
const
cppa
::
object
&
rhs
)
{
return
lhs
.
equal
(
rhs
);
}
inline
bool
operator
!=
(
const
cppa
::
object
&
lhs
,
const
cppa
::
object
&
rhs
)
{
return
!
(
lhs
==
rhs
);
}
#endif // OBJECT_HPP
#endif // OBJECT_HPP
cppa/serializer.hpp
View file @
97aff6bf
...
@@ -17,7 +17,7 @@ namespace cppa { namespace util {
...
@@ -17,7 +17,7 @@ namespace cppa { namespace util {
struct
void_type
;
struct
void_type
;
}
}
// namespace
cppa::
util
}
}
// namespace util
namespace
cppa
{
namespace
cppa
{
...
@@ -35,39 +35,44 @@ class serializer
...
@@ -35,39 +35,44 @@ class serializer
m_sink
->
write
(
buf_size
,
buf
);
m_sink
->
write
(
buf_size
,
buf
);
}
}
};
template
<
typename
T
>
typename
util
::
enable_if
<
std
::
is_integral
<
T
>
,
void
>::
type
write_int
(
const
T
&
value
)
{
T
tmp
=
detail
::
swap_bytes
(
value
);
write
(
sizeof
(
T
),
&
tmp
);
}
}
// namespace cppa
}
;
cppa
::
serializer
&
operator
<<
(
cppa
::
serializer
&
,
const
std
::
string
&
);
serializer
&
operator
<<
(
serializer
&
,
const
std
::
string
&
);
template
<
typename
T
>
template
<
typename
T
>
typename
cppa
::
util
::
enable_if
<
std
::
is_integral
<
T
>
,
cppa
::
serializer
&>::
type
typename
util
::
enable_if
<
std
::
is_integral
<
T
>
,
serializer
&>::
type
operator
<<
(
cppa
::
serializer
&
s
,
const
T
&
value
)
operator
<<
(
serializer
&
s
,
const
T
&
value
)
{
{
T
tmp
=
cppa
::
detail
::
swap_bytes
(
value
);
s
.
write_int
(
value
);
s
.
write
(
sizeof
(
T
),
&
tmp
);
return
s
;
return
s
;
}
}
template
<
typename
T
>
template
<
typename
T
>
typename
cppa
::
util
::
enable_if
<
std
::
is_floating_point
<
T
>
,
typename
util
::
enable_if
<
std
::
is_floating_point
<
T
>
,
serializer
&>::
type
cppa
::
serializer
&>::
type
operator
<<
(
serializer
&
s
,
const
T
&
value
)
operator
<<
(
cppa
::
serializer
&
s
,
const
T
&
value
)
{
{
s
.
write
(
sizeof
(
T
),
&
value
);
s
.
write
(
sizeof
(
T
),
&
value
);
return
s
;
return
s
;
}
}
inline
cppa
::
serializer
&
operator
<<
(
cppa
::
serializer
&
s
,
inline
serializer
&
operator
<<
(
serializer
&
s
,
const
util
::
void_type
&
)
const
cppa
::
util
::
void_type
&
)
{
{
return
s
;
return
s
;
}
}
inline
cppa
::
serializer
&
operator
<<
(
cppa
::
serializer
&
s
,
const
cppa
::
any_type
&
)
inline
serializer
&
operator
<<
(
serializer
&
s
,
const
any_type
&
)
{
{
return
s
;
return
s
;
}
}
}
// namespace cppa
#endif // SERIALIZER_HPP
#endif // SERIALIZER_HPP
cppa/uniform_type_info.hpp
View file @
97aff6bf
This diff is collapsed.
Click to expand it.
cppa/util/callable_trait.hpp
View file @
97aff6bf
...
@@ -12,28 +12,28 @@ template<class C, typename Result, typename... Args>
...
@@ -12,28 +12,28 @@ template<class C, typename Result, typename... Args>
struct
callable_trait
<
Result
(
C
::*
)(
Args
...)
const
>
struct
callable_trait
<
Result
(
C
::*
)(
Args
...)
const
>
{
{
typedef
Result
result_type
;
typedef
Result
result_type
;
typedef
util
::
type_list
<
Args
...
>
arg_types
;
typedef
type_list
<
Args
...
>
arg_types
;
};
};
template
<
class
C
,
typename
Result
,
typename
...
Args
>
template
<
class
C
,
typename
Result
,
typename
...
Args
>
struct
callable_trait
<
Result
(
C
::*
)(
Args
...)
>
struct
callable_trait
<
Result
(
C
::*
)(
Args
...)
>
{
{
typedef
Result
result_type
;
typedef
Result
result_type
;
typedef
util
::
type_list
<
Args
...
>
arg_types
;
typedef
type_list
<
Args
...
>
arg_types
;
};
};
template
<
typename
Result
,
typename
...
Args
>
template
<
typename
Result
,
typename
...
Args
>
struct
callable_trait
<
Result
(
Args
...)
>
struct
callable_trait
<
Result
(
Args
...)
>
{
{
typedef
Result
result_type
;
typedef
Result
result_type
;
typedef
util
::
type_list
<
Args
...
>
arg_types
;
typedef
type_list
<
Args
...
>
arg_types
;
};
};
template
<
typename
Result
,
typename
...
Args
>
template
<
typename
Result
,
typename
...
Args
>
struct
callable_trait
<
Result
(
*
)(
Args
...)
>
struct
callable_trait
<
Result
(
*
)(
Args
...)
>
{
{
typedef
Result
result_type
;
typedef
Result
result_type
;
typedef
util
::
type_list
<
Args
...
>
arg_types
;
typedef
type_list
<
Args
...
>
arg_types
;
};
};
}
}
// namespace cppa::util
}
}
// namespace cppa::util
...
...
cppa/
deta
il/comparable.hpp
→
cppa/
ut
il/comparable.hpp
View file @
97aff6bf
#ifndef COMPARABLE_HPP
#ifndef COMPARABLE_HPP
#define COMPARABLE_HPP
#define COMPARABLE_HPP
namespace
cppa
{
namespace
detail
{
namespace
cppa
{
namespace
util
{
// Barton–Nackman trick
/**
* @brief Barton–Nackman trick implementation.
*
* @p Subclass must provide a @c compare member function that compares
* to instances of @p T and returns an integer @c x with:
* - <tt>x < 0</tt> if <tt>this < other</tt>
* - <tt>x > 0</tt> if <tt>this > other</tt>
* - <tt>x == 0</tt> if <tt>this == other</tt>
*/
template
<
typename
Subclass
,
typename
T
=
Subclass
>
template
<
typename
Subclass
,
typename
T
=
Subclass
>
class
comparable
class
comparable
{
{
...
@@ -106,6 +114,6 @@ class comparable<Subclass, Subclass>
...
@@ -106,6 +114,6 @@ class comparable<Subclass, Subclass>
};
};
}
}
// cppa::
deta
il
}
}
// cppa::
ut
il
#endif // COMPARABLE_HPP
#endif // COMPARABLE_HPP
cppa/util/default_object_base.hpp
deleted
100644 → 0
View file @
61cf341e
#ifndef DEFAULT_OBJECT_BASE_HPP
#define DEFAULT_OBJECT_BASE_HPP
#include "cppa/object.hpp"
#include "cppa/uniform_type_info.hpp"
namespace
cppa
{
namespace
util
{
template
<
typename
T
>
class
default_object_base
:
public
object
{
const
uniform_type_info
*
m_type
;
protected:
T
m_value
;
public:
default_object_base
(
const
uniform_type_info
*
uti
,
const
T
&
val
=
T
())
:
m_type
(
uti
),
m_value
(
val
)
{
}
// mutators
void
*
mutable_value
/*[[override]]*/
()
{
return
&
m_value
;
}
const
uniform_type_info
*
type
/*[[override]]*/
()
const
{
return
m_type
;
}
const
void
*
value
/*[[override]]*/
()
const
{
return
&
m_value
;
}
};
}
}
// namespace cppa::util
#endif // DEFAULT_OBJECT_BASE_HPP
cppa/util/type_list.hpp
View file @
97aff6bf
#ifndef LIBCPPA_UTIL_TYPE_LIST_HPP
#ifndef LIBCPPA_UTIL_TYPE_LIST_HPP
#define LIBCPPA_UTIL_TYPE_LIST_HPP
#define LIBCPPA_UTIL_TYPE_LIST_HPP
#include <typeinfo>
#include "cppa/any_type.hpp"
#include "cppa/any_type.hpp"
#include "cppa/uniform_type_info.hpp"
//
#include "cppa/uniform_type_info.hpp"
#include "cppa/util/void_type.hpp"
#include "cppa/util/void_type.hpp"
#include "cppa/util/abstract_type_list.hpp"
#include "cppa/util/abstract_type_list.hpp"
namespace
cppa
{
// forward declarations
class
uniform_type_info
;
uniform_type_info
*
uniform_typeid
(
const
std
::
type_info
&
tinfo
);
}
// namespace cppa
namespace
cppa
{
namespace
util
{
namespace
cppa
{
namespace
util
{
template
<
typename
...
Types
>
struct
type_list
;
template
<
typename
...
Types
>
struct
type_list
;
...
@@ -54,7 +63,7 @@ struct type_list<Head, Tail...> : abstract_type_list
...
@@ -54,7 +63,7 @@ struct type_list<Head, Tail...> : abstract_type_list
template
<
typename
TypeList
>
template
<
typename
TypeList
>
static
void
init
(
const
uniform_type_info
**
what
)
static
void
init
(
const
uniform_type_info
**
what
)
{
{
what
[
0
]
=
uniform_typeid
<
typename
TypeList
::
head_type
>
(
);
what
[
0
]
=
uniform_typeid
(
typeid
(
typename
TypeList
::
head_type
)
);
if
(
TypeList
::
type_list_size
>
1
)
if
(
TypeList
::
type_list_size
>
1
)
{
{
++
what
;
++
what
;
...
...
cppa/util/void_type.hpp
View file @
97aff6bf
...
@@ -12,6 +12,8 @@ struct void_type
...
@@ -12,6 +12,8 @@ struct void_type
typedef
type_list
<>
tail_type
;
typedef
type_list
<>
tail_type
;
};
};
inline
bool
operator
==
(
const
void_type
&
,
const
void_type
&
)
{
return
true
;
}
}
}
// namespace cppa::util
}
}
// namespace cppa::util
#endif // LIBCPPA_UTIL_VOID_TYPE_HPP
#endif // LIBCPPA_UTIL_VOID_TYPE_HPP
libcppa.Makefile
View file @
97aff6bf
...
@@ -72,6 +72,7 @@ SOURCES = src/actor_behavior.cpp \
...
@@ -72,6 +72,7 @@ SOURCES = src/actor_behavior.cpp \
src/deserializer.cpp \
src/deserializer.cpp \
src/group.cpp \
src/group.cpp \
src/mock_scheduler.cpp \
src/mock_scheduler.cpp \
src/object.cpp \
src/scheduler.cpp \
src/scheduler.cpp \
src/serializer.cpp \
src/serializer.cpp \
src/to_uniform_name.cpp \
src/to_uniform_name.cpp \
...
...
libcppa.doxygen
0 → 100644
View file @
97aff6bf
This diff is collapsed.
Click to expand it.
src/deserializer.cpp
View file @
97aff6bf
...
@@ -9,14 +9,12 @@ deserializer::deserializer(const intrusive_ptr<util::source>& src) : m_src(src)
...
@@ -9,14 +9,12 @@ deserializer::deserializer(const intrusive_ptr<util::source>& src) : m_src(src)
{
{
}
}
}
// namespace cppa
deserializer
&
operator
>>
(
deserializer
&
d
,
actor_ptr
&
)
cppa
::
deserializer
&
operator
>>
(
cppa
::
deserializer
&
d
,
cppa
::
actor_ptr
&
)
{
{
return
d
;
return
d
;
}
}
cppa
::
deserializer
&
operator
>>
(
cppa
::
deserializer
&
d
,
std
::
string
&
str
)
deserializer
&
operator
>>
(
deserializer
&
d
,
std
::
string
&
str
)
{
{
std
::
uint32_t
str_size
;
std
::
uint32_t
str_size
;
d
>>
str_size
;
d
>>
str_size
;
...
@@ -27,3 +25,5 @@ cppa::deserializer& operator>>(cppa::deserializer& d, std::string& str)
...
@@ -27,3 +25,5 @@ cppa::deserializer& operator>>(cppa::deserializer& d, std::string& str)
delete
[]
cbuf
;
delete
[]
cbuf
;
return
d
;
return
d
;
}
}
}
// namespace cppa
src/object.cpp
0 → 100644
View file @
97aff6bf
#include <algorithm>
#include "cppa/object.hpp"
#include "cppa/uniform_type_info.hpp"
#include "cppa/util/void_type.hpp"
namespace
{
cppa
::
util
::
void_type
s_void
;
}
// namespace <anonymous>
namespace
cppa
{
void
object
::
swap
(
object
&
other
)
{
std
::
swap
(
m_value
,
other
.
m_value
);
std
::
swap
(
m_type
,
other
.
m_type
);
}
object
object
::
copy
()
const
{
return
(
m_value
)
?
m_type
->
copy
(
*
this
)
:
object
();
}
object
::
object
(
void
*
val
,
const
uniform_type_info
*
utype
)
:
m_value
(
val
),
m_type
(
utype
)
{
if
(
val
&&
!
utype
)
{
throw
std
::
invalid_argument
(
"val && !utype"
);
}
}
object
::
object
()
:
m_value
(
&
s_void
),
m_type
(
uniform_typeid
<
util
::
void_type
>
())
{
}
object
::~
object
()
{
if
(
m_value
!=
&
s_void
)
m_type
->
destroy
(
*
this
);
}
object
::
object
(
const
object
&
other
)
:
m_value
(
&
s_void
),
m_type
(
uniform_typeid
<
util
::
void_type
>
())
{
object
tmp
=
other
.
copy
();
swap
(
tmp
);
}
object
::
object
(
object
&&
other
)
:
m_value
(
&
s_void
),
m_type
(
uniform_typeid
<
util
::
void_type
>
())
{
swap
(
other
);
}
object
&
object
::
operator
=
(
object
&&
other
)
{
object
tmp
(
std
::
move
(
other
));
swap
(
tmp
);
return
*
this
;
}
object
&
object
::
operator
=
(
const
object
&
other
)
{
object
tmp
=
other
.
copy
();
swap
(
tmp
);
return
*
this
;
}
bool
object
::
equal
(
const
object
&
other
)
const
{
return
m_type
->
equal
(
*
this
,
other
);
}
const
uniform_type_info
&
object
::
type
()
const
{
return
*
m_type
;
}
std
::
string
object
::
to_string
()
const
{
return
m_type
->
to_string
(
*
this
);
}
}
// namespace cppa
src/serializer.cpp
View file @
97aff6bf
...
@@ -9,17 +9,17 @@ serializer::serializer(const intrusive_ptr<util::sink>& dsink) : m_sink(dsink)
...
@@ -9,17 +9,17 @@ serializer::serializer(const intrusive_ptr<util::sink>& dsink) : m_sink(dsink)
{
{
}
}
}
// namespace cppa
serializer
&
operator
<<
(
serializer
&
s
,
const
actor_ptr
&
)
cppa
::
serializer
&
operator
<<
(
cppa
::
serializer
&
s
,
const
cppa
::
actor_ptr
&
)
{
{
return
s
;
return
s
;
}
}
cppa
::
serializer
&
operator
<<
(
cppa
::
serializer
&
s
,
const
std
::
string
&
str
)
serializer
&
operator
<<
(
serializer
&
s
,
const
std
::
string
&
str
)
{
{
auto
str_size
=
static_cast
<
std
::
uint32_t
>
(
str
.
size
());
auto
str_size
=
static_cast
<
std
::
uint32_t
>
(
str
.
size
());
s
<<
str_size
;
s
<<
str_size
;
s
.
write
(
str
.
size
(),
str
.
c_str
());
s
.
write
(
str
.
size
(),
str
.
c_str
());
return
s
;
return
s
;
}
}
}
// namespace cppa
src/to_uniform_name.cpp
View file @
97aff6bf
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include <stdexcept>
#include <stdexcept>
#include <algorithm>
#include <algorithm>
#include "cppa/util/void_type.hpp"
#include "cppa/detail/demangle.hpp"
#include "cppa/detail/demangle.hpp"
#include "cppa/detail/to_uniform_name.hpp"
#include "cppa/detail/to_uniform_name.hpp"
...
@@ -74,6 +75,7 @@ std::string to_uniform_name_impl(Iterator begin, Iterator end,
...
@@ -74,6 +75,7 @@ std::string to_uniform_name_impl(Iterator begin, Iterator end,
{
demangled
<
wchar_t
>
(),
mapped_int_name
<
wchar_t
>
()
},
{
demangled
<
wchar_t
>
(),
mapped_int_name
<
wchar_t
>
()
},
{
demangled
<
char16_t
>
(),
mapped_int_name
<
char16_t
>
()
},
{
demangled
<
char16_t
>
(),
mapped_int_name
<
char16_t
>
()
},
{
demangled
<
char32_t
>
(),
mapped_int_name
<
char32_t
>
()
},
{
demangled
<
char32_t
>
(),
mapped_int_name
<
char32_t
>
()
},
{
demangled
<
cppa
::
util
::
void_type
>
(),
"@0"
},
{
demangled
<
std
::
wstring
>
(),
"@wstr"
},
{
demangled
<
std
::
wstring
>
(),
"@wstr"
},
{
demangled
<
std
::
string
>
(),
"@str"
}
{
demangled
<
std
::
string
>
(),
"@str"
}
};
};
...
...
src/uniform_type_info.cpp
View file @
97aff6bf
#include <map>
#include <map>
#include <set>
#include <set>
#include <locale>
#include <string>
#include <string>
#include <atomic>
#include <atomic>
#include <limits>
#include <limits>
...
@@ -14,19 +15,24 @@
...
@@ -14,19 +15,24 @@
#include "cppa/intrusive_ptr.hpp"
#include "cppa/intrusive_ptr.hpp"
#include "cppa/uniform_type_info.hpp"
#include "cppa/uniform_type_info.hpp"
#include "cppa/util/
default_object_bas
e.hpp"
#include "cppa/util/
void_typ
e.hpp"
#include "cppa/detail/demangle.hpp"
#include "cppa/detail/demangle.hpp"
#include "cppa/detail/to_uniform_name.hpp"
#include "cppa/detail/to_uniform_name.hpp"
#include "cppa/detail/default_object_impl.hpp"
#include "cppa/detail/default_uniform_type_info_impl.hpp"
using
cppa
::
util
::
void_type
;
namespace
std
{
namespace
std
{
inline
ostream
&
operator
<<
(
ostream
&
o
,
const
cppa
::
any_type
&
)
{
return
o
;
}
ostream
&
operator
<<
(
ostream
&
o
,
const
cppa
::
any_type
&
)
{
return
o
;
}
inline
istream
&
operator
>>
(
istream
&
i
,
cppa
::
any_type
&
)
{
return
i
;
}
istream
&
operator
>>
(
istream
&
i
,
cppa
::
any_type
&
)
{
return
i
;
}
ostream
&
operator
<<
(
ostream
&
o
,
const
cppa
::
actor_ptr
&
)
{
return
o
;
}
istream
&
operator
>>
(
istream
&
i
,
cppa
::
actor_ptr
&
)
{
return
i
;
}
inline
ostream
&
operator
<<
(
ostream
&
o
,
const
cppa
::
actor_ptr
&
)
{
return
o
;
}
ostream
&
operator
<<
(
ostream
&
o
,
const
cppa
::
util
::
void_type
&
)
{
return
o
;
}
i
nline
istream
&
operator
>>
(
istream
&
i
,
cppa
::
actor_ptr
&
)
{
return
i
;
}
i
stream
&
operator
>>
(
istream
&
i
,
cppa
::
util
::
void_type
&
)
{
return
i
;
}
}
// namespace std
}
// namespace std
...
@@ -41,37 +47,78 @@ inline const char* raw_name(const std::type_info& tinfo)
...
@@ -41,37 +47,78 @@ inline const char* raw_name(const std::type_info& tinfo)
#endif
#endif
}
}
class
wstring_
obj
:
public
cppa
::
util
::
default_object_base
<
std
::
wstring
>
class
wstring_
utype
:
public
cppa
::
uniform_type_info
{
{
typedef
cppa
::
util
::
default_object_base
<
std
::
wstring
>
super
;
typedef
std
::
ctype
<
wchar_t
>
wchar_ctype
;
public:
inline
std
::
wstring
&
to_ref
(
cppa
::
object
&
what
)
const
{
return
*
reinterpret_cast
<
std
::
wstring
*>
(
this
->
value_of
(
what
));
}
inline
const
std
::
wstring
&
to_ref
(
const
cppa
::
object
&
what
)
const
{
return
*
reinterpret_cast
<
const
std
::
wstring
*>
(
this
->
value_of
(
what
));
}
wstring_obj
(
const
cppa
::
uniform_type_info
*
uti
)
:
super
(
uti
)
{
}
const
wchar_ctype
&
m_facet
;
void
deserialize
(
cppa
::
deserializer
&
)
protected:
cppa
::
object
copy
(
const
cppa
::
object
&
what
)
const
{
return
{
new
std
::
wstring
(
to_ref
(
what
)),
this
};
}
cppa
::
object
from_string
(
const
std
::
string
&
str
)
const
{
{
std
::
vector
<
wchar_t
>
wstr_buf
(
str
.
size
());
m_facet
.
widen
(
str
.
data
(),
str
.
data
()
+
str
.
size
(),
&
wstr_buf
[
0
]);
return
{
new
std
::
wstring
(
&
wstr_buf
[
0
],
wstr_buf
.
size
()),
this
};
}
std
::
string
to_string
(
const
cppa
::
object
&
obj
)
const
{
const
std
::
wstring
&
wstr
=
to_ref
(
obj
);
std
::
string
result
(
wstr
.
size
(),
' '
);
m_facet
.
narrow
(
wstr
.
c_str
(),
wstr
.
c_str
()
+
wstr
.
size
(),
'?'
,
&
result
[
0
]);
return
std
::
move
(
result
);
}
void
destroy
(
cppa
::
object
&
what
)
const
{
delete
reinterpret_cast
<
std
::
wstring
*>
(
value_of
(
what
));
value_of
(
what
)
=
nullptr
;
}
}
void
from_string
(
const
std
::
string
&
)
void
deserialize
(
cppa
::
deserializer
&
d
,
cppa
::
object
&
what
)
const
{
{
}
bool
equal
(
const
cppa
::
object
&
lhs
,
const
cppa
::
object
&
rhs
)
const
{
return
(
lhs
.
type
()
==
*
this
&&
rhs
.
type
()
==
*
this
)
?
to_ref
(
lhs
)
==
to_ref
(
rhs
)
:
false
;
}
}
cppa
::
object
*
copy
(
)
const
void
serialize
(
cppa
::
serializer
&
s
,
const
cppa
::
object
&
what
)
const
{
{
return
new
wstring_obj
(
type
());
}
}
std
::
string
to_string
()
const
public:
wstring_utype
()
:
cppa
::
uniform_type_info
(
typeid
(
std
::
wstring
))
,
m_facet
(
std
::
use_facet
<
wchar_ctype
>
(
std
::
locale
()))
{
{
return
""
;
}
}
void
serialize
(
cppa
::
serializer
&
)
const
cppa
::
object
create
(
)
const
{
{
return
{
new
std
::
wstring
,
this
};
}
}
};
};
...
@@ -126,15 +173,12 @@ class uniform_type_info_map
...
@@ -126,15 +173,12 @@ class uniform_type_info_map
// maps uniform names to uniform type informations
// maps uniform names to uniform type informations
uti_map
m_by_uname
;
uti_map
m_by_uname
;
template
<
typename
ObjImpl
>
void
insert
(
uniform_type_info
*
uti
,
const
std
::
set
<
std
::
string
>&
tnames
)
void
insert
(
const
std
::
set
<
std
::
string
>&
tnames
)
{
{
if
(
tnames
.
empty
())
if
(
tnames
.
empty
())
{
{
throw
std
::
logic_error
(
"tnames.empty()"
);
throw
std
::
logic_error
(
"tnames.empty()"
);
}
}
std
::
string
uname
=
to_uniform_name
(
demangle
(
tnames
.
begin
()
->
c_str
()));
auto
uti
=
new
default_uniform_type_info_impl
<
ObjImpl
>
(
uname
);
for
(
const
std
::
string
&
tname
:
tnames
)
for
(
const
std
::
string
&
tname
:
tnames
)
{
{
m_by_tname
.
insert
(
std
::
make_pair
(
tname
,
uti
));
m_by_tname
.
insert
(
std
::
make_pair
(
tname
,
uti
));
...
@@ -143,10 +187,15 @@ class uniform_type_info_map
...
@@ -143,10 +187,15 @@ class uniform_type_info_map
}
}
template
<
typename
T
>
template
<
typename
T
>
void
insert
()
inline
void
insert
(
const
std
::
set
<
std
::
string
>&
tnames
)
{
insert
(
new
default_uniform_type_info_impl
<
T
>
(),
tnames
);
}
template
<
typename
T
>
inline
void
insert
()
{
{
std
::
string
tname
(
raw_name
<
T
>
());
insert
<
T
>
({
std
::
string
(
raw_name
<
T
>
())
});
insert
<
default_object_impl
<
T
>>
({
tname
});
}
}
public:
public:
...
@@ -154,13 +203,15 @@ class uniform_type_info_map
...
@@ -154,13 +203,15 @@ class uniform_type_info_map
uniform_type_info_map
()
uniform_type_info_map
()
{
{
insert
<
std
::
string
>
();
insert
<
std
::
string
>
();
insert
<
wstring_obj
>
({
std
::
string
(
raw_name
<
std
::
wstring
>
())});
//insert<wstring_obj>({std::string(raw_name<std::wstring>())});
insert
(
new
wstring_utype
,
{
std
::
string
(
raw_name
<
std
::
wstring
>
())
});
insert
<
float
>
();
insert
<
float
>
();
insert
<
cppa
::
util
::
void_type
>
();
if
(
sizeof
(
double
)
==
sizeof
(
long
double
))
if
(
sizeof
(
double
)
==
sizeof
(
long
double
))
{
{
std
::
string
dbl
=
raw_name
<
double
>
();
std
::
string
dbl
=
raw_name
<
double
>
();
std
::
string
ldbl
=
raw_name
<
long
double
>
();
std
::
string
ldbl
=
raw_name
<
long
double
>
();
insert
<
d
efault_object_impl
<
double
>
>
({
dbl
,
ldbl
});
insert
<
d
ouble
>
({
dbl
,
ldbl
});
}
}
else
else
{
{
...
@@ -196,15 +247,14 @@ class uniform_type_info_map
...
@@ -196,15 +247,14 @@ class uniform_type_info_map
wchar_t
,
wchar_t
,
char16_t
,
char16_t
,
char32_t
>
(
ints
);
char32_t
>
(
ints
);
insert
<
default_object_impl
<
std
::
int8_t
>>
(
ints
[
sizeof
(
std
::
int8_t
)].
first
);
insert
<
std
::
int8_t
>
(
ints
[
sizeof
(
std
::
int8_t
)].
first
);
insert
<
default_object_impl
<
std
::
uint8_t
>>
(
ints
[
sizeof
(
std
::
uint8_t
)].
second
);
insert
<
std
::
uint8_t
>
(
ints
[
sizeof
(
std
::
uint8_t
)].
second
);
insert
<
default_object_impl
<
std
::
int16_t
>>
(
ints
[
sizeof
(
std
::
int16_t
)].
first
);
insert
<
std
::
int16_t
>
(
ints
[
sizeof
(
std
::
int16_t
)].
first
);
insert
<
default_object_impl
<
std
::
uint16_t
>>
(
ints
[
sizeof
(
std
::
uint16_t
)].
second
);
insert
<
std
::
uint16_t
>
(
ints
[
sizeof
(
std
::
uint16_t
)].
second
);
insert
<
default_object_impl
<
std
::
int32_t
>>
(
ints
[
sizeof
(
std
::
int32_t
)].
first
);
insert
<
std
::
int32_t
>
(
ints
[
sizeof
(
std
::
int32_t
)].
first
);
insert
<
default_object_impl
<
std
::
uint32_t
>>
(
ints
[
sizeof
(
std
::
uint32_t
)].
second
);
insert
<
std
::
uint32_t
>
(
ints
[
sizeof
(
std
::
uint32_t
)].
second
);
insert
<
default_object_impl
<
std
::
int64_t
>>
(
ints
[
sizeof
(
std
::
int64_t
)].
first
);
insert
<
std
::
int64_t
>
(
ints
[
sizeof
(
std
::
int64_t
)].
first
);
insert
<
default_object_impl
<
std
::
uint64_t
>>
(
ints
[
sizeof
(
std
::
uint64_t
)].
second
);
insert
<
std
::
uint64_t
>
(
ints
[
sizeof
(
std
::
uint64_t
)].
second
);
//insert<std::wstring>();
}
}
uniform_type_info
*
by_raw_name
(
const
std
::
string
&
name
)
uniform_type_info
*
by_raw_name
(
const
std
::
string
&
name
)
...
@@ -277,8 +327,9 @@ inline int next_id() { return s_ids.fetch_add(1); }
...
@@ -277,8 +327,9 @@ inline int next_id() { return s_ids.fetch_add(1); }
namespace
cppa
{
namespace
cppa
{
uniform_type_info
::
uniform_type_info
(
const
std
::
string
&
uniform_type_name
)
uniform_type_info
::
uniform_type_info
(
const
std
::
type_info
&
tinfo
)
:
m_id
(
next_id
()),
m_name
(
uniform_type_name
)
:
m_id
(
next_id
())
,
m_name
(
detail
::
to_uniform_name
(
detail
::
demangle
(
raw_name
(
tinfo
))))
{
{
}
}
...
@@ -319,9 +370,19 @@ bool uniform_type_info::announce(const std::type_info& plain_type,
...
@@ -319,9 +370,19 @@ bool uniform_type_info::announce(const std::type_info& plain_type,
return
true
;
return
true
;
}
}
std
::
vector
<
uniform_type_info
*>
uniform_type_info
::
get_all
()
std
::
vector
<
uniform_type_info
*>
uniform_type_info
::
instances
()
{
{
return
detail
::
s_uniform_type_info_map
().
get_all
();
return
detail
::
s_uniform_type_info_map
().
get_all
();
}
}
uniform_type_info
*
uniform_typeid
(
const
std
::
type_info
&
tinfo
)
{
return
uniform_type_info
::
by_type_info
(
tinfo
);
}
bool
operator
==
(
const
uniform_type_info
&
lhs
,
const
std
::
type_info
&
rhs
)
{
return
lhs
==
*
uniform_typeid
(
rhs
);
}
}
// namespace cppa
}
// namespace cppa
unit_testing/test__local_group.cpp
View file @
97aff6bf
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
using
std
::
cout
;
using
std
::
cout
;
using
std
::
endl
;
using
std
::
endl
;
/*
using namespace cppa;
using namespace cppa;
namespace {
namespace {
...
@@ -154,3 +156,16 @@ std::size_t test__local_group()
...
@@ -154,3 +156,16 @@ std::size_t test__local_group()
return CPPA_TEST_RESULT;
return CPPA_TEST_RESULT;
}
}
*/
std
::
size_t
test__local_group
()
{
CPPA_TEST
(
test__local_group
);
CPPA_CHECK_EQUAL
(
true
,
true
);
return
CPPA_TEST_RESULT
;
}
unit_testing/test__serialization.cpp
View file @
97aff6bf
...
@@ -24,6 +24,8 @@ using std::cout;
...
@@ -24,6 +24,8 @@ using std::cout;
using
std
::
cerr
;
using
std
::
cerr
;
using
std
::
endl
;
using
std
::
endl
;
/*
using namespace cppa;
using namespace cppa;
using namespace cppa::util;
using namespace cppa::util;
...
@@ -528,3 +530,16 @@ std::size_t test__serialization()
...
@@ -528,3 +530,16 @@ std::size_t test__serialization()
return CPPA_TEST_RESULT;
return CPPA_TEST_RESULT;
}
}
*/
std
::
size_t
test__serialization
()
{
CPPA_TEST
(
test__serialization
);
CPPA_CHECK_EQUAL
(
true
,
true
);
return
CPPA_TEST_RESULT
;
}
unit_testing/test__uniform_type.cpp
View file @
97aff6bf
#include <map>
#include <map>
#include <set>
#include <set>
#include <memory>
#include <cctype>
#include <cctype>
#include <atomic>
#include <atomic>
#include <vector>
#include <vector>
...
@@ -14,12 +15,17 @@
...
@@ -14,12 +15,17 @@
#include "test.hpp"
#include "test.hpp"
#include "cppa/serializer.hpp"
#include "cppa/deserializer.hpp"
#include "cppa/uniform_type_info.hpp"
#include "cppa/uniform_type_info.hpp"
#include "cppa/util/default_object_base.hpp"
#include "cppa/util/disjunction.hpp"
#include "cppa/util/callable_trait.hpp"
using
std
::
cout
;
using
std
::
cout
;
using
std
::
endl
;
using
std
::
endl
;
using
cppa
::
object
;
using
cppa
::
uniform_type_info
;
using
cppa
::
uniform_type_info
;
namespace
{
namespace
{
...
@@ -27,51 +33,41 @@ namespace {
...
@@ -27,51 +33,41 @@ namespace {
struct
foo
struct
foo
{
{
int
value
;
int
value
;
foo
(
int
val
=
0
)
:
value
(
val
)
{
}
explicit
foo
(
int
val
=
0
)
:
value
(
val
)
{
}
};
};
class
foo_object
:
public
cppa
::
util
::
default_object_base
<
foo
>
bool
operator
==
(
const
foo
&
lhs
,
const
foo
&
rhs
)
{
{
return
lhs
.
value
==
rhs
.
value
;
}
typedef
default_object_base
<
foo
>
super
;
}
// namespace <anonymous>
public:
foo_object
(
const
uniform_type_info
*
uti
,
const
foo
&
val
=
foo
())
:
super
(
uti
,
val
)
{
}
object
*
copy
/*[[override]]*/
()
const
{
return
new
foo_object
(
type
(),
m_value
);
}
std
::
string
to_string
/*[[override]]*/
()
const
namespace
{
{
std
::
ostringstream
sstr
;
sstr
<<
m_value
.
value
;
return
sstr
.
str
();
}
void
from_string
/*[[override]]*/
(
const
std
::
string
&
str
)
static
bool
unused1
=
{
cppa
::
uniform_type_info
::
announce
<
foo
>
(
int
tmp
;
[]
(
cppa
::
serializer
&
s
,
const
foo
&
f
)
{
s
<<
f
.
value
;
},
[]
(
cppa
::
deserializer
&
d
,
foo
&
f
)
{
d
>>
f
.
value
;
},
[]
(
const
foo
&
f
)
->
std
::
string
{
std
::
ostringstream
ostr
;
ostr
<<
f
.
value
;
return
ostr
.
str
();
},
[]
(
const
std
::
string
&
str
)
->
foo
*
{
std
::
istringstream
istr
(
str
);
std
::
istringstream
istr
(
str
);
int
tmp
;
istr
>>
tmp
;
istr
>>
tmp
;
m_value
.
value
=
tmp
;
return
new
foo
(
tmp
)
;
}
}
);
void
deserialize
(
cppa
::
deserializer
&
)
{
}
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>);
void
serialize
(
cppa
::
serializer
&
)
const
{
}
bool
unused4
=
false
;
//= cppa::uniform_type_info::announce(typeid(foo), new uti_impl<foo>);
};
bool
unused1
=
cppa
::
uniform_type_info
::
announce
<
foo_object
>
(
typeid
(
foo
));
bool
unused2
=
cppa
::
uniform_type_info
::
announce
<
foo_object
>
(
typeid
(
foo
));
bool
unused3
=
cppa
::
uniform_type_info
::
announce
<
foo_object
>
(
typeid
(
foo
));
bool
unused4
=
cppa
::
uniform_type_info
::
announce
<
foo_object
>
(
typeid
(
foo
));
typedef
cppa
::
intrusive_ptr
<
cppa
::
object
>
obj_ptr
;
}
// namespace <anonymous>
}
// namespace <anonymous>
...
@@ -79,6 +75,24 @@ std::size_t test__uniform_type()
...
@@ -79,6 +75,24 @@ std::size_t test__uniform_type()
{
{
CPPA_TEST
(
test__uniform_type
);
CPPA_TEST
(
test__uniform_type
);
{
//bar.create_object();
object
obj1
=
cppa
::
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!"
);
CPPA_CHECK_EQUAL
(
wstr_obj1
,
wstr_obj2
);
// couldn't be converted to ASCII
cppa
::
object_cast
<
std
::
wstring
>
(
wstr_obj1
)
=
L"hello wstring
\x05D4
"
;
std
::
string
narrowed
=
wstr_obj1
.
to_string
();
CPPA_CHECK_EQUAL
(
narrowed
,
"hello wstring?"
);
}
int
successful_announces
=
(
unused1
?
1
:
0
)
int
successful_announces
=
(
unused1
?
1
:
0
)
+
(
unused2
?
1
:
0
)
+
(
unused2
?
1
:
0
)
+
(
unused3
?
1
:
0
)
+
(
unused3
?
1
:
0
)
...
@@ -87,11 +101,13 @@ std::size_t test__uniform_type()
...
@@ -87,11 +101,13 @@ std::size_t test__uniform_type()
CPPA_CHECK_EQUAL
(
successful_announces
,
1
);
CPPA_CHECK_EQUAL
(
successful_announces
,
1
);
// test foo_object implementation
// test foo_object implementation
/*
obj_ptr o = cppa::uniform_typeid<foo>()->create();
obj_ptr o = cppa::uniform_typeid<foo>()->create();
o->from_string("123");
o->from_string("123");
CPPA_CHECK_EQUAL(o->to_string(), "123");
CPPA_CHECK_EQUAL(o->to_string(), "123");
int val = reinterpret_cast<const foo*>(o->value())->value;
int val = reinterpret_cast<const foo*>(o->value())->value;
CPPA_CHECK_EQUAL(val, 123);
CPPA_CHECK_EQUAL(val, 123);
*/
// these types (and only those) are present if the uniform_type_info
// these types (and only those) are present if the uniform_type_info
// implementation is correct
// implementation is correct
...
@@ -102,6 +118,7 @@ std::size_t test__uniform_type()
...
@@ -102,6 +118,7 @@ std::size_t test__uniform_type()
"@u8"
,
"@u16"
,
"@u32"
,
"@u64"
,
// unsigned integer names
"@u8"
,
"@u16"
,
"@u32"
,
"@u64"
,
// unsigned integer names
"@str"
,
"@wstr"
,
// strings
"@str"
,
"@wstr"
,
// strings
"float"
,
"double"
,
// floating points
"float"
,
"double"
,
// floating points
"@0"
,
// cppa::util::void_type
// default announced cppa types
// default announced cppa types
"cppa::any_type"
,
"cppa::any_type"
,
"cppa::intrusive_ptr<cppa::actor>"
"cppa::intrusive_ptr<cppa::actor>"
...
@@ -117,7 +134,7 @@ std::size_t test__uniform_type()
...
@@ -117,7 +134,7 @@ std::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
=
cppa
::
uniform_type_info
::
get_all
();
auto
types
=
cppa
::
uniform_type_info
::
instances
();
for
(
cppa
::
uniform_type_info
*
tinfo
:
types
)
for
(
cppa
::
uniform_type_info
*
tinfo
:
types
)
{
{
found
.
insert
(
tinfo
->
name
());
found
.
insert
(
tinfo
->
name
());
...
...
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