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
53e5796f
Commit
53e5796f
authored
Feb 20, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
maintenance
parent
3f194ef3
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
193 additions
and
285 deletions
+193
-285
cppa/detail/abstract_tuple.hpp
cppa/detail/abstract_tuple.hpp
+23
-9
cppa/detail/decorated_tuple.hpp
cppa/detail/decorated_tuple.hpp
+16
-10
cppa/detail/tuple_cast_impl.hpp
cppa/detail/tuple_cast_impl.hpp
+36
-203
cppa/match.hpp
cppa/match.hpp
+87
-45
cppa/tuple_cast.hpp
cppa/tuple_cast.hpp
+5
-2
cppa/util/fixed_vector.hpp
cppa/util/fixed_vector.hpp
+7
-13
cppa/util/type_list.hpp
cppa/util/type_list.hpp
+1
-0
src/abstract_tuple.cpp
src/abstract_tuple.cpp
+2
-0
unit_testing/test__tuple.cpp
unit_testing/test__tuple.cpp
+16
-3
No files found.
cppa/detail/abstract_tuple.hpp
View file @
53e5796f
...
@@ -45,6 +45,9 @@ namespace cppa { namespace detail {
...
@@ -45,6 +45,9 @@ namespace cppa { namespace detail {
struct
abstract_tuple
:
ref_counted
struct
abstract_tuple
:
ref_counted
{
{
abstract_tuple
()
=
default
;
abstract_tuple
(
abstract_tuple
const
&
);
// mutators
// mutators
virtual
void
*
mutable_at
(
size_t
pos
)
=
0
;
virtual
void
*
mutable_at
(
size_t
pos
)
=
0
;
...
@@ -64,17 +67,22 @@ struct abstract_tuple : ref_counted
...
@@ -64,17 +67,22 @@ struct abstract_tuple : ref_counted
{
{
size_t
m_pos
;
size_t
m_pos
;
abstract_tuple
const
&
m_tuple
;
abstract_tuple
const
*
m_tuple
;
public:
public:
const_iterator
(
abstract_tuple
const
&
tup
,
size_t
pos
=
0
)
:
m_pos
(
pos
),
m_tuple
(
tup
)
{
}
inline
const_iterator
(
abstract_tuple
const
*
tup
,
size_t
pos
=
0
)
:
m_pos
(
pos
),
m_tuple
(
tup
)
{
}
const_iterator
(
const_iterator
const
&
)
=
default
;
const_iterator
(
const_iterator
const
&
)
=
default
;
const_iterator
&
operator
=
(
const_iterator
const
&
)
=
default
;
inline
bool
operator
==
(
const_iterator
const
&
other
)
const
inline
bool
operator
==
(
const_iterator
const
&
other
)
const
{
{
CPPA_REQUIRE
(
&
(
other
.
m_tuple
)
==
&
(
other
.
m_tuple
)
);
CPPA_REQUIRE
(
other
.
m_tuple
==
other
.
m_tuple
);
return
other
.
m_pos
==
m_pos
;
return
other
.
m_pos
==
m_pos
;
}
}
...
@@ -122,19 +130,25 @@ struct abstract_tuple : ref_counted
...
@@ -122,19 +130,25 @@ struct abstract_tuple : ref_counted
inline
size_t
position
()
const
{
return
m_pos
;
}
inline
size_t
position
()
const
{
return
m_pos
;
}
void
const
*
value
()
const
{
return
m_tuple
.
at
(
m_pos
);
}
inline
void
const
*
value
()
const
{
return
m_tuple
->
at
(
m_pos
);
}
uniform_type_info
const
*
type
()
const
{
return
m_tuple
.
type_at
(
m_pos
);
}
inline
uniform_type_info
const
*
type
()
const
{
return
m_tuple
->
type_at
(
m_pos
);
}
const_iterator
&
operator
*
()
{
return
*
this
;
}
inline
const_iterator
&
operator
*
()
{
return
*
this
;
}
operator
type_value_pair
()
const
{
return
{
type
(),
value
()};
}
inline
operator
type_value_pair
()
const
{
return
{
type
(),
value
()};
}
};
};
inline
const_iterator
begin
()
const
{
return
{
*
this
};
}
inline
const_iterator
begin
()
const
{
return
{
this
};
}
inline
const_iterator
end
()
const
{
return
{
*
this
,
size
()};
}
inline
const_iterator
end
()
const
{
return
{
this
,
size
()};
}
};
};
...
...
cppa/detail/decorated_tuple.hpp
View file @
53e5796f
...
@@ -82,6 +82,7 @@ class decorated_tuple : public abstract_tuple
...
@@ -82,6 +82,7 @@ class decorated_tuple : public abstract_tuple
virtual
void
*
mutable_at
(
size_t
pos
)
virtual
void
*
mutable_at
(
size_t
pos
)
{
{
CPPA_REQUIRE
(
pos
<
size
());
CPPA_REQUIRE
(
pos
<
size
());
CPPA_REQUIRE
(
m_mapping
[
pos
]
<
m_decorated
->
size
());
return
m_decorated
->
mutable_at
(
m_mapping
[
pos
]);
return
m_decorated
->
mutable_at
(
m_mapping
[
pos
]);
}
}
...
@@ -98,12 +99,14 @@ class decorated_tuple : public abstract_tuple
...
@@ -98,12 +99,14 @@ class decorated_tuple : public abstract_tuple
virtual
void
const
*
at
(
size_t
pos
)
const
virtual
void
const
*
at
(
size_t
pos
)
const
{
{
CPPA_REQUIRE
(
pos
<
size
());
CPPA_REQUIRE
(
pos
<
size
());
CPPA_REQUIRE
(
m_mapping
[
pos
]
<
m_decorated
->
size
());
return
m_decorated
->
at
(
m_mapping
[
pos
]);
return
m_decorated
->
at
(
m_mapping
[
pos
]);
}
}
virtual
uniform_type_info
const
*
type_at
(
size_t
pos
)
const
virtual
uniform_type_info
const
*
type_at
(
size_t
pos
)
const
{
{
CPPA_REQUIRE
(
pos
<
size
());
CPPA_REQUIRE
(
pos
<
size
());
CPPA_REQUIRE
(
m_mapping
[
pos
]
<
m_decorated
->
size
());
return
m_decorated
->
type_at
(
m_mapping
[
pos
]);
return
m_decorated
->
type_at
(
m_mapping
[
pos
]);
}
}
...
@@ -112,21 +115,24 @@ class decorated_tuple : public abstract_tuple
...
@@ -112,21 +115,24 @@ class decorated_tuple : public abstract_tuple
return
typeid
(
decorated_tuple
);
return
typeid
(
decorated_tuple
);
}
}
cow_pointer_type
&
decorated
()
{
return
m_decorated
;
}
cow_pointer_type
const
&
decorated
()
const
{
return
m_decorated
;
}
private:
private:
cow_pointer_type
m_decorated
;
cow_pointer_type
m_decorated
;
vector_type
m_mapping
;
vector_type
m_mapping
;
decorated_tuple
(
cow_pointer_type
const
&
d
)
:
m_decorated
(
d
)
{
}
decorated_tuple
(
cow_pointer_type
&&
d
)
:
m_decorated
(
std
::
move
(
d
))
{
}
decorated_tuple
(
cow_pointer_type
&&
d
)
:
m_decorated
(
std
::
move
(
d
))
{
}
decorated_tuple
(
decorated_tuple
const
&
other
)
decorated_tuple
(
decorated_tuple
const
&
)
=
default
;
:
abstract_tuple
()
,
m_decorated
(
other
.
m_decorated
)
,
m_mapping
(
other
.
m_mapping
)
{
}
decorated_tuple
*
init
(
vector_type
const
&
v
)
decorated_tuple
*
init
(
vector_type
const
&
v
)
{
{
...
@@ -143,7 +149,7 @@ class decorated_tuple : public abstract_tuple
...
@@ -143,7 +149,7 @@ class decorated_tuple : public abstract_tuple
CPPA_REQUIRE
(
m_decorated
->
size
()
>=
sizeof
...(
ElementTypes
));
CPPA_REQUIRE
(
m_decorated
->
size
()
>=
sizeof
...(
ElementTypes
));
size_t
i
=
0
;
size_t
i
=
0
;
m_mapping
.
resize
(
sizeof
...(
ElementTypes
));
m_mapping
.
resize
(
sizeof
...(
ElementTypes
));
std
::
generate
(
m_mapping
.
begin
(),
m_mapping
.
end
(),
[
&
](){
return
i
++
;});
std
::
generate
(
m_mapping
.
begin
(),
m_mapping
.
end
(),
[
&
]()
{
return
i
++
;});
return
this
;
return
this
;
}
}
...
@@ -152,7 +158,7 @@ class decorated_tuple : public abstract_tuple
...
@@ -152,7 +158,7 @@ class decorated_tuple : public abstract_tuple
CPPA_REQUIRE
((
m_decorated
->
size
()
-
offset
)
==
sizeof
...(
ElementTypes
));
CPPA_REQUIRE
((
m_decorated
->
size
()
-
offset
)
==
sizeof
...(
ElementTypes
));
size_t
i
=
offset
;
size_t
i
=
offset
;
m_mapping
.
resize
(
sizeof
...(
ElementTypes
));
m_mapping
.
resize
(
sizeof
...(
ElementTypes
));
std
::
generate
(
m_mapping
.
begin
(),
m_mapping
.
end
(),
[
&
](){
return
i
++
;});
std
::
generate
(
m_mapping
.
begin
(),
m_mapping
.
end
(),
[
&
]()
{
return
i
++
;});
return
this
;
return
this
;
}
}
...
...
cppa/detail/tuple_cast_impl.hpp
View file @
53e5796f
This diff is collapsed.
Click to expand it.
cppa/match.hpp
View file @
53e5796f
This diff is collapsed.
Click to expand it.
cppa/tuple_cast.hpp
View file @
53e5796f
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#include <type_traits>
#include <type_traits>
#include "cppa/match.hpp"
#include "cppa/option.hpp"
#include "cppa/option.hpp"
#include "cppa/pattern.hpp"
#include "cppa/pattern.hpp"
...
@@ -50,7 +51,8 @@ auto tuple_cast(any_tuple const& tup, pattern<T...> const& p)
...
@@ -50,7 +51,8 @@ auto tuple_cast(any_tuple const& tup, pattern<T...> const& p)
{
{
typedef
typename
pattern
<
T
...
>::
filtered_types
filtered_types
;
typedef
typename
pattern
<
T
...
>::
filtered_types
filtered_types
;
typedef
typename
tuple_from_type_list
<
filtered_types
>::
type
tuple_type
;
typedef
typename
tuple_from_type_list
<
filtered_types
>::
type
tuple_type
;
static
constexpr
auto
impl
=
detail
::
select_tuple_cast_impl
<
T
...
>::
value
;
static
constexpr
auto
impl
=
get_pattern_characteristic
<
util
::
type_list
<
T
...
>>
();
return
detail
::
tuple_cast_impl
<
impl
,
tuple_type
,
T
...
>::
_
(
tup
,
p
);
return
detail
::
tuple_cast_impl
<
impl
,
tuple_type
,
T
...
>::
_
(
tup
,
p
);
}
}
...
@@ -67,7 +69,8 @@ auto tuple_cast(any_tuple const& tup)
...
@@ -67,7 +69,8 @@ auto tuple_cast(any_tuple const& tup)
{
{
typedef
decltype
(
tuple_cast
<
T
...
>
(
tup
))
result_type
;
typedef
decltype
(
tuple_cast
<
T
...
>
(
tup
))
result_type
;
typedef
typename
result_type
::
value_type
tuple_type
;
typedef
typename
result_type
::
value_type
tuple_type
;
static
constexpr
auto
impl
=
detail
::
select_tuple_cast_impl
<
T
...
>::
value
;
static
constexpr
auto
impl
=
get_pattern_characteristic
<
util
::
type_list
<
T
...
>>
();
return
detail
::
tuple_cast_impl
<
impl
,
tuple_type
,
T
...
>::
_
(
tup
);
return
detail
::
tuple_cast_impl
<
impl
,
tuple_type
,
T
...
>::
_
(
tup
);
}
}
...
...
cppa/util/fixed_vector.hpp
View file @
53e5796f
...
@@ -73,9 +73,7 @@ class fixed_vector
...
@@ -73,9 +73,7 @@ class fixed_vector
typedef
std
::
reverse_iterator
<
iterator
>
reverse_iterator
;
typedef
std
::
reverse_iterator
<
iterator
>
reverse_iterator
;
typedef
std
::
reverse_iterator
<
const_iterator
>
const_reverse_iterator
;
typedef
std
::
reverse_iterator
<
const_iterator
>
const_reverse_iterator
;
constexpr
fixed_vector
()
:
m_size
(
0
)
constexpr
fixed_vector
()
:
m_size
(
0
)
{
}
{
}
fixed_vector
(
fixed_vector
const
&
other
)
:
m_size
(
other
.
m_size
)
fixed_vector
(
fixed_vector
const
&
other
)
:
m_size
(
other
.
m_size
)
{
{
...
@@ -120,12 +118,6 @@ class fixed_vector
...
@@ -120,12 +118,6 @@ class fixed_vector
m_data
[
m_size
++
]
=
what
;
m_data
[
m_size
++
]
=
what
;
}
}
inline
void
push_back
(
T
&&
what
)
{
CPPA_REQUIRE
(
!
full
());
m_data
[
m_size
++
]
=
std
::
move
(
what
);
}
inline
reference
at
(
size_type
pos
)
inline
reference
at
(
size_type
pos
)
{
{
CPPA_REQUIRE
(
pos
<
m_size
);
CPPA_REQUIRE
(
pos
<
m_size
);
...
@@ -140,11 +132,13 @@ class fixed_vector
...
@@ -140,11 +132,13 @@ class fixed_vector
inline
reference
operator
[](
size_type
pos
)
inline
reference
operator
[](
size_type
pos
)
{
{
CPPA_REQUIRE
(
pos
<
m_size
);
return
at
(
pos
);
return
at
(
pos
);
}
}
inline
const_reference
operator
[](
size_type
pos
)
const
inline
const_reference
operator
[](
size_type
pos
)
const
{
{
CPPA_REQUIRE
(
pos
<
m_size
);
return
at
(
pos
);
return
at
(
pos
);
}
}
...
@@ -165,12 +159,12 @@ class fixed_vector
...
@@ -165,12 +159,12 @@ class fixed_vector
inline
iterator
end
()
inline
iterator
end
()
{
{
return
(
static_cast
<
iterator
>
(
m_data
)
+
m_size
)
;
return
begin
()
+
m_size
;
}
}
inline
const_iterator
end
()
const
inline
const_iterator
end
()
const
{
{
return
(
static_cast
<
const_iterator
>
(
m_data
)
+
m_size
)
;
return
begin
()
+
m_size
;
}
}
inline
const_iterator
cend
()
const
inline
const_iterator
cend
()
const
...
@@ -222,13 +216,13 @@ class fixed_vector
...
@@ -222,13 +216,13 @@ class fixed_vector
inline
reference
back
()
inline
reference
back
()
{
{
CPPA_REQUIRE
(
m_size
>
0
);
CPPA_REQUIRE
(
!
empty
()
);
return
m_data
[
m_size
-
1
];
return
m_data
[
m_size
-
1
];
}
}
inline
const_reference
back
()
const
inline
const_reference
back
()
const
{
{
CPPA_REQUIRE
(
m_size
>
0
);
CPPA_REQUIRE
(
!
empty
()
);
return
m_data
[
m_size
-
1
];
return
m_data
[
m_size
-
1
];
}
}
...
...
cppa/util/type_list.hpp
View file @
53e5796f
...
@@ -378,6 +378,7 @@ struct tl_prepend<type_list<T...>, What>
...
@@ -378,6 +378,7 @@ struct tl_prepend<type_list<T...>, What>
// list list::filter(predicate)
// list list::filter(predicate)
// list list::filter_not(predicate)
template
<
class
List
,
bool
...
Selected
>
template
<
class
List
,
bool
...
Selected
>
struct
tl_filter_impl
;
struct
tl_filter_impl
;
...
...
src/abstract_tuple.cpp
View file @
53e5796f
...
@@ -48,4 +48,6 @@ bool abstract_tuple::equals(const abstract_tuple &other) const
...
@@ -48,4 +48,6 @@ bool abstract_tuple::equals(const abstract_tuple &other) const
return
true
;
return
true
;
}
}
abstract_tuple
::
abstract_tuple
(
abstract_tuple
const
&
)
:
ref_counted
()
{
}
}
}
// namespace cppa::detail
}
}
// namespace cppa::detail
unit_testing/test__tuple.cpp
View file @
53e5796f
...
@@ -32,6 +32,7 @@ size_t test__tuple()
...
@@ -32,6 +32,7 @@ size_t test__tuple()
CPPA_TEST
(
test__tuple
);
CPPA_TEST
(
test__tuple
);
// check type correctness of make_tuple()
// check type correctness of make_tuple()
auto
t0
=
make_tuple
(
"1"
,
2
);
auto
t0
=
make_tuple
(
"1"
,
2
);
CPPA_CHECK
((
std
::
is_same
<
decltype
(
t0
),
cppa
::
tuple
<
std
::
string
,
int
>>::
value
));
auto
t0_0
=
get
<
0
>
(
t0
);
auto
t0_0
=
get
<
0
>
(
t0
);
auto
t0_1
=
get
<
1
>
(
t0
);
auto
t0_1
=
get
<
1
>
(
t0
);
// check implicit type conversion
// check implicit type conversion
...
@@ -51,12 +52,24 @@ size_t test__tuple()
...
@@ -51,12 +52,24 @@ size_t test__tuple()
{
{
auto
&
v0
=
*
v0opt
;
auto
&
v0
=
*
v0opt
;
CPPA_CHECK
((
std
::
is_same
<
decltype
(
v0
),
tuple
<
std
::
string
>&>::
value
));
CPPA_CHECK
((
std
::
is_same
<
decltype
(
v0
),
tuple
<
std
::
string
>&>::
value
));
auto
&
v0_0
=
get
<
0
>
(
v0
);
CPPA_CHECK
((
std
::
is_same
<
decltype
(
get
<
0
>
(
v0
)),
std
::
string
const
&>::
value
));
CPPA_CHECK
((
std
::
is_same
<
decltype
(
v0_0
),
std
::
string
const
&>::
value
));
CPPA_CHECK_EQUAL
(
v0
.
size
(),
1
);
CPPA_CHECK_EQUAL
(
v0
.
size
(),
1
);
CPPA_CHECK_EQUAL
(
v0_0
,
"1"
);
CPPA_CHECK_EQUAL
(
get
<
0
>
(
v0
)
,
"1"
);
CPPA_CHECK_EQUAL
(
get
<
0
>
(
t0
),
get
<
0
>
(
v0
));
CPPA_CHECK_EQUAL
(
get
<
0
>
(
t0
),
get
<
0
>
(
v0
));
// check cow semantics
// check cow semantics
cout
<<
" t0: "
<<
t0
.
vals
().
get
()
<<
endl
<<
" v0: "
<<
v0
.
vals
().
get
()
<<
endl
<<
"*v0: "
<<
dynamic_cast
<
detail
::
decorated_tuple
<
std
::
string
>
const
*>
(
v0
.
vals
().
get
())
->
decorated
().
get
()
<<
endl
<<
"at0: "
<<
at0
.
vals
().
get
()
<<
endl
;
cout
<<
"&get<0>(t0): "
<<
(
&
get
<
0
>
(
t0
))
<<
endl
<<
"&get<0>(v0): "
<<
(
&
get
<
0
>
(
v0
))
<<
endl
<<
" at0.at(0): "
<<
(
at0
.
at
(
0
))
<<
endl
;
CPPA_CHECK_EQUAL
(
&
get
<
0
>
(
t0
),
&
get
<
0
>
(
v0
));
// point to the same
CPPA_CHECK_EQUAL
(
&
get
<
0
>
(
t0
),
&
get
<
0
>
(
v0
));
// point to the same
get_ref
<
0
>
(
t0
)
=
"hello world"
;
// detaches t0 from v0
get_ref
<
0
>
(
t0
)
=
"hello world"
;
// detaches t0 from v0
CPPA_CHECK_EQUAL
(
get
<
0
>
(
t0
),
"hello world"
);
// t0 contains new value
CPPA_CHECK_EQUAL
(
get
<
0
>
(
t0
),
"hello world"
);
// t0 contains new value
...
...
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