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
e83f6d6a
Commit
e83f6d6a
authored
Nov 14, 2011
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
documentation
parent
f6038a61
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
175 additions
and
85 deletions
+175
-85
cppa/cppa.hpp
cppa/cppa.hpp
+1
-1
cppa/deserializer.hpp
cppa/deserializer.hpp
+2
-2
cppa/local_actor.hpp
cppa/local_actor.hpp
+1
-0
cppa/primitive_type.hpp
cppa/primitive_type.hpp
+27
-7
cppa/primitive_variant.hpp
cppa/primitive_variant.hpp
+132
-58
cppa/serializer.hpp
cppa/serializer.hpp
+1
-5
cppa/uniform_type_info.hpp
cppa/uniform_type_info.hpp
+0
-2
src/primitive_variant.cpp
src/primitive_variant.cpp
+8
-8
unit_testing/test__primitive_variant.cpp
unit_testing/test__primitive_variant.cpp
+3
-2
No files found.
cppa/cppa.hpp
View file @
e83f6d6a
...
...
@@ -303,7 +303,7 @@ inline actor_ptr spawn(F&& what, const Args&... args)
}
/**
* @copydoc
context::quit(std::uint32_t
)
* @copydoc
local_actor::quit(
)
*
* Alias for <tt>self()->quit(reason);</tt>
*/
...
...
cppa/deserializer.hpp
View file @
e83f6d6a
...
...
@@ -12,7 +12,7 @@ namespace cppa {
class
object
;
/**
* @ingroup
Serialize
* @ingroup
TypeSystem
* @brief Technology-independent deserialization interface.
*/
class
deserializer
...
...
@@ -72,7 +72,7 @@ class deserializer
* @brief Reads a tuple of primitive values from the data
* source of the types @p ptypes.
* @param num The size of the tuple.
* @param ptype Array of expected primitive data types.
* @param ptype
s
Array of expected primitive data types.
* @param storage Array of size @p num, storing the result of this function.
*/
virtual
void
read_tuple
(
size_t
num
,
...
...
cppa/local_actor.hpp
View file @
e83f6d6a
...
...
@@ -24,6 +24,7 @@ class local_actor : public actor
* Cause this actor to send an exit signal to all of its
* linked actors, sets its state to @c exited and throws
* {@link actor_exited} to cleanup the stack.
* @param reason Exit reason that will be send to linked actors.
* @throws actor_exited
*/
virtual
void
quit
(
std
::
uint32_t
reason
)
=
0
;
...
...
cppa/primitive_type.hpp
View file @
e83f6d6a
...
...
@@ -4,16 +4,30 @@
namespace
cppa
{
/**
* @brief Includes integers (signed and unsigned), floating points
* and unicode strings (std::string, std::u16string and std::u32string).
* @ingroup TypeSystem
* @brief Represents a type flag of {@link primitive_variant}.
*
* Includes integers (signed and unsigned), floating points
* and unicode strings (std::string, std::u16string and std::u32string).
* @relates primitive_variant
*/
enum
primitive_type
{
pt_int8
,
pt_int16
,
pt_int32
,
pt_int64
,
pt_uint8
,
pt_uint16
,
pt_uint32
,
pt_uint64
,
pt_float
,
pt_double
,
pt_long_double
,
pt_u8string
,
pt_u16string
,
pt_u32string
,
pt_null
pt_int8
,
/**< equivalent of @p std::int8_t */
pt_int16
,
/**< equivalent of @p std::int16_t */
pt_int32
,
/**< equivalent of @p std::int32_t */
pt_int64
,
/**< equivalent of @p std::int64_t */
pt_uint8
,
/**< equivalent of @p std::uint8_t */
pt_uint16
,
/**< equivalent of @p std::uint16_t */
pt_uint32
,
/**< equivalent of @p std::uint32_t */
pt_uint64
,
/**< equivalent of @p std::uint64_t */
pt_float
,
/**< equivalent of @p float */
pt_double
,
/**< equivalent of @p double */
pt_long_double
,
/**< equivalent of <tt>long double</tt> */
pt_u8string
,
/**< equivalent of @p std::string */
pt_u16string
,
/**< equivalent of @p std::u16string */
pt_u32string
,
/**< equivalent of @p std::u32string */
pt_null
/**< equivalent of @p void */
};
constexpr
const
char
*
primitive_type_names
[]
=
...
...
@@ -25,6 +39,12 @@ constexpr const char* primitive_type_names[] =
"pt_null"
};
/**
* @ingroup TypeSystem
* @brief Maps a #primitive_type value to its name.
* @param ptype Requestet @p primitive_type.
* @returns A C-string representation of @p ptype.
*/
constexpr
const
char
*
primitive_type_name
(
primitive_type
ptype
)
{
return
primitive_type_names
[
static_cast
<
int
>
(
ptype
)];
...
...
cppa/primitive_variant.hpp
View file @
e83f6d6a
...
...
@@ -31,13 +31,30 @@ void ptv_set(primitive_type& lhs_type, T& lhs, V&& rhs,
namespace
cppa
{
class
primitive_variant
;
template
<
typename
T
>
const
T
&
get
(
const
primitive_variant
&
pv
);
template
<
typename
T
>
T
&
get_ref
(
primitive_variant
&
pv
);
/**
* @
brief A stack-based union container for
*
{@link primitive_type primitive data types}
.
* @
ingroup TypeSystem
*
@brief An union container for primitive data types
.
*/
class
primitive_variant
{
friend
bool
operator
==
(
const
primitive_variant
&
lhs
,
const
primitive_variant
&
rhs
);
template
<
typename
T
>
friend
const
T
&
get
(
const
primitive_variant
&
pv
);
template
<
typename
T
>
friend
T
&
get_ref
(
primitive_variant
&
pv
);
primitive_type
m_ptype
;
union
...
...
@@ -58,7 +75,7 @@ class primitive_variant
std
::
u32string
s32
;
};
// use static call dispatching to select member
variable
// use static call dispatching to select member
inline
decltype
(
i8
)
&
get
(
util
::
pt_token
<
pt_int8
>
)
{
return
i8
;
}
inline
decltype
(
i16
)
&
get
(
util
::
pt_token
<
pt_int16
>
)
{
return
i16
;
}
inline
decltype
(
i32
)
&
get
(
util
::
pt_token
<
pt_int32
>
)
{
return
i32
;
}
...
...
@@ -103,18 +120,6 @@ class primitive_variant
if
(
m_ptype
!=
PT
)
throw
std
::
logic_error
(
"type check failed"
);
}
public:
template
<
typename
V
>
void
set
(
V
&&
value
)
{
static
constexpr
primitive_type
ptype
=
detail
::
type_to_ptype
<
V
>::
ptype
;
util
::
pt_token
<
ptype
>
token
;
static_assert
(
ptype
!=
pt_null
,
"T is not a primitive type"
);
destroy
();
detail
::
ptv_set
<
ptype
>
(
m_ptype
,
get
(
token
),
std
::
forward
<
V
>
(
value
));
}
template
<
primitive_type
PT
>
typename
detail
::
ptype_to_type
<
PT
>::
type
&
get_as
()
{
...
...
@@ -133,21 +138,7 @@ class primitive_variant
return
const_cast
<
primitive_variant
*>
(
this
)
->
get
(
token
);
}
template
<
typename
T
>
explicit
operator
T
()
{
static
constexpr
primitive_type
ptype
=
detail
::
type_to_ptype
<
T
>::
ptype
;
static_assert
(
ptype
!=
pt_null
,
"V is not a primitive type"
);
return
get_as
<
ptype
>
();
}
template
<
typename
T
>
explicit
operator
T
()
const
{
static
constexpr
primitive_type
ptype
=
detail
::
type_to_ptype
<
T
>::
ptype
;
static_assert
(
ptype
!=
pt_null
,
"V is not a primitive type"
);
return
get_as
<
ptype
>
();
}
public:
template
<
typename
Fun
>
void
apply
(
Fun
&&
f
)
...
...
@@ -162,8 +153,17 @@ class primitive_variant
applier
<
const
primitive_variant
,
Fun
>
(
this
,
f
));
}
/**
* @brief Creates an empty variant.
* @post <tt>ptype() == pt_null && type() == typeid(void)</tt>.
*/
primitive_variant
();
/**
* @brief Creates a variant from @p value.
* @param value A primitive value.
* @pre @p value does have a primitive type.
*/
template
<
typename
V
>
primitive_variant
(
V
&&
value
)
:
m_ptype
(
pt_null
)
{
...
...
@@ -174,88 +174,162 @@ class primitive_variant
std
::
forward
<
V
>
(
value
));
}
primitive_variant
(
primitive_type
ptype
);
/**
* @brief Creates a variant with type pt.
* @param pt Requestet type.
* @post <tt>ptype() == pt</tt>.
*/
primitive_variant
(
primitive_type
pt
);
/**
* @brief Creates a copy from @p other.
* @param other A primitive variant.
*/
primitive_variant
(
const
primitive_variant
&
other
);
/**
* @brief Creates a new variant and move the value from @p other to it.
* @param other A primitive variant rvalue.
*/
primitive_variant
(
primitive_variant
&&
other
);
/**
* @brief Moves @p value to this variant if @p value is an rvalue;
* otherwise copies the value of @p value.
* @param value A primitive value.
* @returns <tt>*this</tt>.
*/
template
<
typename
V
>
primitive_variant
&
operator
=
(
V
&&
value
)
{
static
constexpr
primitive_type
ptype
=
detail
::
type_to_ptype
<
V
>::
ptype
;
static_assert
(
ptype
!=
pt_null
,
"V is not a primitive type"
);
util
::
pt_token
<
ptype
>
token
;
if
(
ptype
==
m_ptype
)
{
util
::
pt_token
<
ptype
>
token
;
get
(
token
)
=
std
::
forward
<
V
>
(
value
);
}
else
{
set
(
std
::
forward
<
V
>
(
value
));
destroy
();
detail
::
ptv_set
<
ptype
>
(
m_ptype
,
get
(
token
),
std
::
forward
<
V
>
(
value
));
//set(std::forward<V>(value));
}
return
*
this
;
}
/**
* @brief Copies the content of @p other to @p this.
* @param other A primitive variant.
* @returns <tt>*this</tt>.
*/
primitive_variant
&
operator
=
(
const
primitive_variant
&
other
);
/**
* @brief Moves the content of @p other to @p this.
* @param other A primitive variant rvalue.
* @returns <tt>*this</tt>.
*/
primitive_variant
&
operator
=
(
primitive_variant
&&
other
);
bool
operator
==
(
const
primitive_variant
&
other
)
const
;
inline
bool
operator
!=
(
const
primitive_variant
&
other
)
const
{
return
!
(
*
this
==
other
);
}
/**
* @brief Gets the {@link primitive_type type} of @p this.
* @returns The {@link primitive_type type} of @p this.
*/
inline
primitive_type
ptype
()
const
{
return
m_ptype
;
}
/**
* @brief Gets the RTTI type of @p this.
* @returns <tt>typeid(void)</tt> if <tt>ptype() == pt_null</tt>;
* otherwise typeid(T) is returned, where T is the C++ type
* of @p this.
*/
const
std
::
type_info
&
type
()
const
;
~
primitive_variant
();
};
/**
* @ingroup TypeSystem
* @brief Casts a primitive variant to its C++ type.
* @relates primitive_variant
* @param pv A primitive variant of type @p T.
* @returns A const reference to the value of @p pv of type @p T.
* @throws <tt>std::logic_error</tt> if @p pv is not of type @p T.
*/
template
<
typename
T
>
T
&
get
(
primitive_variant
&
pv
)
const
T
&
get
(
const
primitive_variant
&
pv
)
{
static
const
primitive_type
ptype
=
detail
::
type_to_ptype
<
T
>::
ptype
;
return
pv
.
get_as
<
ptype
>
();
}
/**
* @ingroup TypeSystem
* @brief Casts a non-const primitive variant to its C++ type.
* @relates primitive_variant
* @param pv A primitive variant of type @p T.
* @returns A reference to the value of @p pv of type @p T.
* @throws <tt>std::logic_error</tt> if @p pv is not of type @p T.
*/
template
<
typename
T
>
const
T
&
get
(
const
primitive_variant
&
pv
)
T
&
get_ref
(
primitive_variant
&
pv
)
{
static
const
primitive_type
ptype
=
detail
::
type_to_ptype
<
T
>::
ptype
;
return
pv
.
get_as
<
ptype
>
();
}
#ifdef CPPA_DOCUMENTATION
/**
* @ingroup TypeSystem
* @brief Casts a primitive variant to its C++ type.
* @relates primitive_variant
* @tparam T C++ type equivalent of @p PT.
* @param pv A primitive variant of type @p T.
* @returns A const reference to the value of @p pv of type @p T.
*/
template
<
primitive_type
PT
>
const
T
&
get_ref
(
const
primitive_variant
&
pv
);
/**
* @ingroup TypeSystem
* @brief Casts a non-const primitive variant to its C++ type.
* @relates primitive_variant
* @tparam T C++ type equivalent of @p PT.
* @param pv A primitive variant of type @p T.
* @returns A reference to the value of @p pv of type @p T.
*/
template
<
primitive_type
PT
>
T
&
get_ref
(
primitive_variant
&
pv
);
#else
template
<
primitive_type
PT
>
typename
detail
::
ptype_to_type
<
PT
>::
type
&
get
(
primitive_variant
&
pv
)
inline
const
typename
detail
::
ptype_to_type
<
PT
>::
type
&
get
(
const
primitive_variant
&
pv
)
{
static_assert
(
PT
!=
pt_null
,
"PT == pt_null"
);
return
pv
.
get_as
<
PT
>
(
);
return
get
<
typename
detail
::
ptype_to_type
<
PT
>::
type
>
(
pv
);
}
template
<
primitive_type
PT
>
const
typename
detail
::
ptype_to_type
<
PT
>::
type
&
get
(
const
primitive_variant
&
pv
)
inline
typename
detail
::
ptype_to_type
<
PT
>::
type
&
get_ref
(
primitive_variant
&
pv
)
{
static_assert
(
PT
!=
pt_null
,
"PT == pt_null"
);
return
pv
.
get_as
<
PT
>
(
);
return
get_ref
<
typename
detail
::
ptype_to_type
<
PT
>::
type
>
(
pv
);
}
template
<
typename
T
>
T
&
get_ref
(
primitive_variant
&
pv
)
{
static
const
primitive_type
ptype
=
detail
::
type_to_ptype
<
T
>::
ptype
;
return
pv
.
get_as
<
ptype
>
();
}
#endif
template
<
primitive_type
PT
>
typename
detail
::
ptype_to_type
<
PT
>::
type
&
get_ref
(
primitive_variant
&
pv
)
bool
operator
==
(
const
primitive_variant
&
lhs
,
const
primitive_variant
&
rhs
);
inline
bool
operator
!=
(
const
primitive_variant
&
lhs
,
const
primitive_variant
&
rhs
)
{
static_assert
(
PT
!=
pt_null
,
"PT == pt_null"
);
return
pv
.
get_as
<
PT
>
();
return
!
(
lhs
==
rhs
);
}
template
<
typename
T
>
...
...
@@ -263,7 +337,7 @@ typename util::enable_if<util::is_primitive<T>, bool>::type
operator
==
(
const
T
&
lhs
,
const
primitive_variant
&
rhs
)
{
static
constexpr
primitive_type
ptype
=
detail
::
type_to_ptype
<
T
>::
ptype
;
static_assert
(
ptype
!=
pt_null
,
"T
couldn't be mapped to an p
type"
);
static_assert
(
ptype
!=
pt_null
,
"T
is an incompatible
type"
);
return
(
rhs
.
ptype
()
==
ptype
)
?
lhs
==
get
<
ptype
>
(
rhs
)
:
false
;
}
...
...
cppa/serializer.hpp
View file @
e83f6d6a
...
...
@@ -9,15 +9,11 @@
namespace
cppa
{
/**
* @defgroup Serialize Serialization of custom data types.
*/
// forward declaration
class
primitive_variant
;
/**
* @ingroup
Serialize
* @ingroup
TypeSystem
* @brief Technology-independent serialization interface.
*/
class
serializer
...
...
cppa/uniform_type_info.hpp
View file @
e83f6d6a
...
...
@@ -97,8 +97,6 @@ const uniform_type_info* uniform_typeid(const std::type_info&);
* an unsupported data structure, you have to implement serialize/deserialize
* by yourself. {@link announce_example_5.cpp Example 5} shows, how to
* announce a tree data structure to the @p libcppa type system.
* Make sure to read the @ref Serialize "serialization section" of
* this documentation before.
*/
/**
...
...
src/primitive_variant.cpp
View file @
e83f6d6a
...
...
@@ -57,7 +57,7 @@ struct comparator
{
if
(
rhs
.
ptype
()
==
PT
)
{
result
=
(
lhs
.
get_as
<
PT
>
()
==
rhs
.
get_as
<
PT
>
(
));
result
=
(
get
<
PT
>
(
lhs
)
==
get
<
PT
>
(
rhs
));
}
}
};
...
...
@@ -72,7 +72,7 @@ struct initializer
inline
void
operator
()(
util
::
pt_token
<
PT
>
)
{
typedef
typename
detail
::
ptype_to_type
<
PT
>::
type
T
;
lhs
.
set
(
T
()
);
lhs
=
T
(
);
}
};
...
...
@@ -85,7 +85,7 @@ struct setter
template
<
typename
T
>
inline
void
operator
()(
const
T
&
rhs
)
{
lhs
.
set
(
rhs
)
;
lhs
=
rhs
;
}
};
...
...
@@ -98,7 +98,7 @@ struct mover
template
<
typename
T
>
inline
void
operator
()(
T
&
rhs
)
{
lhs
.
set
(
std
::
move
(
rhs
)
);
lhs
=
std
::
move
(
rhs
);
}
};
...
...
@@ -135,10 +135,10 @@ primitive_variant& primitive_variant::operator=(primitive_variant&& other)
return
*
this
;
}
bool
primitive_variant
::
operator
==
(
const
primitive_variant
&
other
)
const
bool
operator
==
(
const
primitive_variant
&
lhs
,
const
primitive_variant
&
rhs
)
{
comparator
cmp
(
*
this
,
other
);
util
::
pt_dispatch
(
m_ptype
,
cmp
);
comparator
cmp
(
lhs
,
rhs
);
util
::
pt_dispatch
(
lhs
.
m_ptype
,
cmp
);
return
cmp
.
result
;
}
...
...
@@ -146,7 +146,7 @@ const std::type_info& primitive_variant::type() const
{
type_reader
tr
;
apply
(
tr
);
return
(
tr
.
tinfo
)
?
*
tr
.
tinfo
:
typeid
(
void
)
;
return
(
tr
.
tinfo
==
nullptr
)
?
typeid
(
void
)
:
*
tr
.
tinfo
;
}
primitive_variant
::~
primitive_variant
()
...
...
unit_testing/test__primitive_variant.cpp
View file @
e83f6d6a
...
...
@@ -7,13 +7,14 @@ using namespace cppa;
size_t
test__primitive_variant
()
{
CPPA_TEST
(
test__primitive_variant
);
std
::
uint32_t
forty_two
=
42
;
primitive_variant
v1
(
forty_two
);
primitive_variant
v2
(
pt_uint32
);
// type checking
CPPA_CHECK_EQUAL
(
v1
.
ptype
(),
pt_uint32
);
CPPA_CHECK_EQUAL
(
v2
.
ptype
(),
pt_uint32
);
get
<
std
::
uint32_t
&>
(
v2
)
=
forty_two
;
get
_ref
<
std
::
uint32_t
&>
(
v2
)
=
forty_two
;
CPPA_CHECK_EQUAL
(
v1
,
v2
);
CPPA_CHECK_EQUAL
(
v1
,
forty_two
);
CPPA_CHECK_EQUAL
(
forty_two
,
v2
);
...
...
@@ -23,7 +24,7 @@ size_t test__primitive_variant()
CPPA_CHECK_EQUAL
(
v1
.
ptype
(),
pt_u8string
);
v2
=
"Hello"
;
CPPA_CHECK_EQUAL
(
v2
.
ptype
(),
pt_u8string
);
get
<
std
::
string
>
(
v2
)
+=
" world"
;
get
_ref
<
std
::
string
>
(
v2
)
+=
" world"
;
CPPA_CHECK_EQUAL
(
v1
,
v2
);
v2
=
u"Hello World"
;
CPPA_CHECK
(
v1
!=
v2
);
...
...
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