Commit 013df02d authored by Dominik Charousset's avatar Dominik Charousset

got rid of class `pattern`

the class `pattern` is no longer used by libcppa, since we use
match_expr and guards instead
parent 394c4f74
......@@ -129,7 +129,6 @@ set(LIBCPPA_SRC
src/object_array.cpp
src/opt.cpp
src/partial_function.cpp
src/pattern.cpp
src/primitive_variant.cpp
src/process_information.cpp
src/protocol.cpp
......
......@@ -100,7 +100,6 @@ cppa/object.hpp
cppa/on.hpp
cppa/option.hpp
cppa/partial_function.hpp
cppa/pattern.hpp
cppa/primitive_type.hpp
cppa/primitive_variant.hpp
cppa/process_information.hpp
......@@ -195,7 +194,6 @@ src/local_actor.cpp
src/object.cpp
src/object_array.cpp
src/partial_function.cpp
src/pattern.cpp
src/primitive_variant.cpp
src/process_information.cpp
src/receive.cpp
......@@ -297,3 +295,4 @@ cppa/actor_companion_mixin.hpp
cppa/detail/singleton_mixin.hpp
cppa/response_handle.hpp
src/response_handle.cpp
cppa/wildcard_position.hpp
......@@ -35,7 +35,6 @@
#include "cppa/config.hpp"
#include "cppa/either.hpp"
#include "cppa/pattern.hpp"
#include "cppa/detail/receive_policy.hpp"
#include "cppa/detail/behavior_stack.hpp"
......
......@@ -32,8 +32,9 @@
#define CPPA_MATCHES_HPP
#include <numeric>
#include "cppa/pattern.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/wildcard_position.hpp"
#include "cppa/util/type_list.hpp"
......@@ -68,11 +69,6 @@ struct matcher<wildcard_position::nil, Tuple, T...> {
}
return false;
}
static inline bool vmatch(const Tuple& tup, const pattern<T...>& ptrn) {
CPPA_REQUIRE(tup.size() == sizeof...(T));
return ptrn._matches_values(tup);
}
};
template<class Tuple, typename... T>
......@@ -98,10 +94,6 @@ struct matcher<wildcard_position::trailing, Tuple, T...> {
}
return false;
}
static inline bool vmatch(const Tuple& tup, const pattern<T...>& ptrn) {
return ptrn._matches_values(tup);
}
};
template<class Tuple>
......@@ -112,9 +104,6 @@ struct matcher<wildcard_position::leading, Tuple, anything> {
static inline bool tmatch(const Tuple&, util::fixed_vector<size_t, 0>&) {
return true;
}
static inline bool vmatch(const Tuple&, const pattern<anything>&) {
return true;
}
};
template<class Tuple, typename... T>
......@@ -142,10 +131,6 @@ struct matcher<wildcard_position::leading, Tuple, T...> {
}
return false;
}
static inline bool vmatch(const Tuple& tup, const pattern<T...>& ptrn) {
return ptrn._matches_values(tup);
}
};
template<class Tuple, typename... T>
......@@ -192,10 +177,6 @@ struct matcher<wildcard_position::in_between, Tuple, T...> {
}
return false;
}
static inline bool vmatch(const Tuple& tup, const pattern<T...>& ptrn) {
return ptrn._matches_values(tup);
}
};
template<class Tuple, typename... T>
......@@ -271,12 +252,6 @@ struct matcher<wildcard_position::multiple, Tuple, T...> {
}
return false;
}
static inline bool vmatch(const Tuple& tup,
const pattern<T...>& ptrn,
const typename pattern<T...>::mapping_vector& mv) {
return ptrn._matches_values(tup, &mv);
}
};
// implementation for zero or one wildcards
......@@ -291,21 +266,6 @@ struct match_impl {
util::fixed_vector<size_t, Size>& mv) {
return matcher<PC, Tuple, Ts...>::tmatch(tup, mv);
}
static inline bool _(const Tuple& tup,
const pattern<Ts...>& p) {
return matcher<PC, Tuple, Ts...>::tmatch(tup)
&& ( p.has_values() == false
|| matcher<PC, Tuple, Ts...>::vmatch(tup, p));
}
static inline bool _(const Tuple& tup,
const pattern<Ts...>& p,
typename pattern<Ts...>::mapping_vector& mv) {
return matcher<PC, Tuple, Ts...>::tmatch(tup, mv)
&& ( p.has_values() == false
|| matcher<PC, Tuple, Ts...>::vmatch(tup, p));
}
};
// implementation for multiple wildcards
......@@ -323,24 +283,6 @@ struct match_impl<wildcard_position::multiple, Tuple, Ts...> {
return matcher<PC, Tuple, Ts...>::tmatch(tup, mv);
}
static inline bool _(const Tuple& tup, const pattern<Ts...>& p) {
if (p.has_values()) {
typename pattern<Ts...>::mapping_vector mv;
return matcher<PC, Tuple, Ts...>::tmatch(tup, mv)
&& matcher<PC, Tuple, Ts...>::vmatch(tup, p, mv);
}
return matcher<PC, Tuple, Ts...>::tmatch(tup);
}
static inline bool _(const Tuple& tup, const pattern<Ts...>& p,
typename pattern<Ts...>::mapping_vector& mv) {
if (p.has_values()) {
typename pattern<Ts...>::mapping_vector mv;
return matcher<PC, Tuple, Ts...>::tmatch(tup, mv)
&& matcher<PC, Tuple, Ts...>::vmatch(tup, p, mv);
}
return matcher<PC, Tuple, Ts...>::tmatch(tup, mv);
}
};
template<class Tuple, class List>
......@@ -379,27 +321,6 @@ bool matches(const any_tuple& tup,
::_(tup, mv);
}
/*
* @brief Returns true if this tuple matches @p pn.
*/
template<typename... Ts>
bool matches(const any_tuple& tup, const pattern<Ts...>& pn) {
typedef util::type_list<Ts...> tl;
return match_impl<get_wildcard_position<tl>(), any_tuple, Ts...>
::_(tup, pn);
}
/*
* @brief Returns true if this tuple matches @p pn.
*/
template<typename... Ts>
bool matches(const any_tuple& tup, const pattern<Ts...>& pn,
typename pattern<Ts...>::mapping_vector& mv) {
typedef util::type_list<Ts...> tl;
return match_impl<get_wildcard_position<tl>(), any_tuple, Ts...>
::_(tup, pn, mv);
}
// support for type_list based matching
template<typename... Ts>
inline bool matches(const any_tuple& tup, const util::type_list<Ts...>&) {
......@@ -416,15 +337,6 @@ inline bool matches(const any_tuple& tup, const util::type_list<Ts...>&,
return matches<Ts...>(tup, mv);
}
/*
* @brief Returns true if this tuple matches the pattern <tt>{Ts...}</tt>
* (does not match for values).
*/
template<typename... Ts>
inline bool matches_types(const any_tuple& tup, const pattern<Ts...>&) {
return matches<Ts...>(tup);
}
template<typename... Ts>
inline bool matches_types(const any_tuple& tup, const util::type_list<Ts...>&) {
return matches<Ts...>(tup);
......
......@@ -31,7 +31,6 @@
#ifndef CPPA_TUPLE_CAST_IMPL_HPP
#define CPPA_TUPLE_CAST_IMPL_HPP
#include "cppa/pattern.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/detail/matches.hpp"
......@@ -65,49 +64,6 @@ struct tuple_cast_impl {
mv)};
return {};
}
static inline option<Result> safe(any_tuple& tup, const pattern<T...>& p) {
mapping_vector mv;
if (matches(tup, p, mv)) return {Result::from(std::move(tup.vals()),
mv)};
return {};
}
static inline option<Result> unsafe(any_tuple& tup, const pattern<T...>& p) {
mapping_vector mv;
if (WP == wildcard_position::in_between) {
if (!p.has_values() || matcher<WP, any_tuple, T...>::vmatch(tup, p)) {
// first range
mv.resize(size);
auto begin = mv.begin();
std::iota(begin, begin + first_wc, 0);
// second range
begin = mv.begin() + first_wc;
std::iota(begin, mv.end(), tup.size() - (size - first_wc));
return {Result::from(std::move(tup.vals()), mv)};
}
}
else {
if (matches(tup, p, mv)) return {Result::from(std::move(tup.vals()),
mv)};
}
return {};
}
static inline Result force(any_tuple& tup, const pattern<T...>& p) {
mapping_vector mv;
if (WP == wildcard_position::in_between) {
// first range
mv.resize(size);
auto begin = mv.begin();
std::iota(begin, begin + first_wc, 0);
// second range
begin = mv.begin() + first_wc;
std::iota(begin, mv.end(), tup.size() - (size - first_wc));
return {Result::from(std::move(tup.vals()), mv)};
}
else {
matches(tup, p, mv);
return {Result::from(std::move(tup.vals()), mv)};
}
}
};
template<class Result, typename... T>
......@@ -116,38 +72,11 @@ struct tuple_cast_impl<wildcard_position::nil, Result, T...> {
if (matches<T...>(tup)) return {Result::from(std::move(tup.vals()))};
return {};
}
static inline option<Result> safe(any_tuple& tup, const pattern<T...>& p) {
if (matches(tup, p)) {
return {Result::from(std::move(tup.vals()))};
}
return {};
}
static inline option<Result> unsafe(any_tuple& tup, const pattern<T...>& p) {
if ( p.has_values() == false
|| matcher<wildcard_position::nil, any_tuple, T...>::vmatch(tup, p)) {
return {Result::from(std::move(tup.vals()))};
}
return {};
}
static inline Result force(any_tuple& tup, const pattern<T...>&) {
return {Result::from(std::move(tup.vals()))};
}
};
template<class Result, typename... T>
struct tuple_cast_impl<wildcard_position::trailing, Result, T...>
: tuple_cast_impl<wildcard_position::nil, Result, T...> {
static inline option<Result> unsafe(any_tuple& tup, const pattern<T...>& p) {
if ( p.has_values() == false
|| matcher<wildcard_position::trailing, any_tuple, T...>
::vmatch(tup, p)) {
return {Result::from(std::move(tup.vals()))};
}
return {};
}
static inline Result force(any_tuple& tup, const pattern<T...>&) {
return {Result::from(std::move(tup.vals()))};
}
};
template<class Result, typename... T>
......@@ -157,24 +86,6 @@ struct tuple_cast_impl<wildcard_position::leading, Result, T...> {
if (matches<T...>(tup)) return {Result::offset_subtuple(tup.vals(), o)};
return {};
}
static inline option<Result> safe(any_tuple& tup, const pattern<T...>& p) {
size_t o = tup.size() - (sizeof...(T) - 1);
if (matches(tup, p)) return {Result::offset_subtuple(tup.vals(), o)};
return {};
}
static inline option<Result> unsafe(any_tuple& tup, const pattern<T...>& p) {
if ( p.has_values() == false
|| matcher<wildcard_position::leading, any_tuple, T...>
::vmatch(tup, p)) {
size_t o = tup.size() - (sizeof...(T) - 1);
return Result::offset_subtuple(tup.vals(), o);
}
return {};
}
static inline Result force(any_tuple& tup, const pattern<T...>&) {
size_t o = tup.size() - (sizeof...(T) - 1);
return Result::offset_subtuple(tup.vals(), o);
}
};
} }
......
......@@ -38,7 +38,6 @@
#include "cppa/config.hpp"
#include "cppa/either.hpp"
#include "cppa/pattern.hpp"
#include "cppa/behavior.hpp"
#include "cppa/detail/receive_policy.hpp"
#include "cppa/detail/behavior_stack.hpp"
......
......@@ -32,7 +32,6 @@
#define CPPA_MATCH_EXPR_HPP
#include "cppa/option.hpp"
#include "cppa/pattern.hpp"
#include "cppa/guard_expr.hpp"
#include "cppa/partial_function.hpp"
#include "cppa/tpartial_function.hpp"
......
......@@ -36,7 +36,6 @@
#include <type_traits>
#include "cppa/atom.hpp"
#include "cppa/pattern.hpp"
#include "cppa/anything.hpp"
#include "cppa/behavior.hpp"
#include "cppa/any_tuple.hpp"
......
This diff is collapsed.
......@@ -44,7 +44,6 @@
#include "cppa/atom.hpp"
#include "cppa/either.hpp"
#include "cppa/pattern.hpp"
#include "cppa/local_actor.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/intrusive_ptr.hpp"
......
......@@ -34,7 +34,8 @@
#include <type_traits>
#include "cppa/option.hpp"
#include "cppa/pattern.hpp"
#include "cppa/util/type_list.hpp"
#include "cppa/detail/matches.hpp"
#include "cppa/detail/tuple_cast_impl.hpp"
......@@ -43,17 +44,6 @@ namespace cppa {
#ifdef CPPA_DOCUMENTATION
/**
* @brief Tries to cast @p tup to {@link cow_tuple cow_tuple<T...>} and moves
* the content of @p tup to the returned tuple on success.
* @param tup Dynamically typed tuple.
* @param pttrn Requested types with optional guard values.
* @returns An {@link option} for a {@link cow_tuple} with the types
* deduced from @p pttrn.
* @relates any_tuple
*/
auto moving_tuple_cast(any_tuple& tup, const pattern<T...>& pttrn);
/**
* @brief Tries to cast @p tup to {@link cow_tuple cow_tuple<T...>} and moves
* the content of @p tup to the returned tuple on success.
......@@ -76,17 +66,6 @@ auto moving_tuple_cast(any_tuple& tup);
template<typename... T>
auto moving_tuple_cast(any_tuple& tup, const util::type_list<T...>&);
/**
* @brief Tries to cast @p tup to {@link cow_tuple cow_tuple<T...>}.
* @param tup Dynamically typed tuple.
* @param pttrn Requested types with optional guard values.
* @returns An {@link option} for a {@link cow_tuple} with the types
* deduced from @p pttrn.
* @relates any_tuple
*/
template<typename... T>
auto tuple_cast(any_tuple tup, const pattern<T...>& pttrn);
/**
* @brief Tries to cast @p tup to {@link cow_tuple cow_tuple<T...>}.
* @param tup Dynamically typed tuple.
......@@ -109,18 +88,6 @@ auto tuple_cast(any_tuple tup, const util::type_list<T...>&);
#else
template<typename... T>
auto moving_tuple_cast(any_tuple& tup, const pattern<T...>& pttrn)
-> option<
typename cow_tuple_from_type_list<
typename pattern<T...>::filtered_types
>::type> {
typedef typename pattern<T...>::filtered_types filtered_types;
typedef typename cow_tuple_from_type_list<filtered_types>::type tuple_type;
static constexpr auto impl = get_wildcard_position<util::type_list<T...>>();
return detail::tuple_cast_impl<impl, tuple_type, T...>::safe(tup, pttrn);
}
template<typename... T>
auto moving_tuple_cast(any_tuple& tup)
-> option<
......@@ -141,15 +108,6 @@ auto moving_tuple_cast(any_tuple& tup, const util::type_list<T...>&)
return moving_tuple_cast<T...>(tup);
}
template<typename... T>
auto tuple_cast(any_tuple tup, const pattern<T...>& pttrn)
-> option<
typename cow_tuple_from_type_list<
typename pattern<T...>::filtered_types
>::type> {
return moving_tuple_cast(tup, pttrn);
}
template<typename... T>
auto tuple_cast(any_tuple tup)
-> option<
......@@ -168,39 +126,12 @@ auto tuple_cast(any_tuple tup, const util::type_list<T...>&)
// ************************ for in-library use only! ************************ //
// (moving) cast using a pattern; does not perform type checking
template<typename... T>
auto unsafe_tuple_cast(any_tuple& tup, const pattern<T...>& p)
-> option<
typename cow_tuple_from_type_list<
typename pattern<T...>::filtered_types
>::type> {
typedef typename pattern<T...>::filtered_types filtered_types;
typedef typename cow_tuple_from_type_list<filtered_types>::type tuple_type;
static constexpr auto impl =
get_wildcard_position<util::type_list<T...>>();
return detail::tuple_cast_impl<impl, tuple_type, T...>::unsafe(tup, p);
}
template<typename... T>
auto unsafe_tuple_cast(any_tuple& tup, const util::type_list<T...>&)
-> decltype(tuple_cast<T...>(tup)) {
return tuple_cast<T...>(tup);
}
// cast using a pattern; does neither perform type checking nor checks values
template<typename... T>
auto forced_tuple_cast(any_tuple& tup, const pattern<T...>& p)
-> typename cow_tuple_from_type_list<
typename pattern<T...>::filtered_types
>::type {
typedef typename pattern<T...>::filtered_types filtered_types;
typedef typename cow_tuple_from_type_list<filtered_types>::type tuple_type;
static constexpr auto impl =
get_wildcard_position<util::type_list<T...>>();
return detail::tuple_cast_impl<impl, tuple_type, T...>::force(tup, p);
}
#endif // CPPA_DOCUMENTATION
} // namespace cppa
......
......@@ -28,14 +28,46 @@
\******************************************************************************/
#include "cppa/pattern.hpp"
#ifndef CPPA_WILDCARD_POSITION_HPP
#define CPPA_WILDCARD_POSITION_HPP
#include <type_traits>
#include "cppa/anything.hpp"
#include "cppa/util/type_list.hpp"
namespace cppa {
value_matcher::~value_matcher() { }
/**
* @brief Denotes the position of {@link cppa::anything anything} in a
* template parameter pack.
*/
enum class wildcard_position {
nil,
trailing,
leading,
in_between,
multiple
};
bool dummy_matcher::operator()(const any_tuple&) const {
return true;
/**
* @brief Gets the position of {@link cppa::anything anything} from the
* type list @p Types.
* @tparam A template parameter pack as {@link cppa::util::type_list type_list}.
*/
template<typename Types>
constexpr wildcard_position get_wildcard_position() {
return util::tl_exists<Types, is_anything>::value
? ((util::tl_count<Types, is_anything>::value == 1)
? (std::is_same<typename Types::head, anything>::value
? wildcard_position::leading
: (std::is_same<typename Types::back, anything>::value
? wildcard_position::trailing
: wildcard_position::in_between))
: wildcard_position::multiple)
: wildcard_position::nil;
}
} // namespace cppa
#endif // CPPA_WILDCARD_POSITION_HPP
......@@ -7,10 +7,9 @@
#include "cppa/on.hpp"
#include "cppa/atom.hpp"
#include "cppa/match.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/option.hpp"
#include "cppa/pattern.hpp"
#include "cppa/announce.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/tuple_cast.hpp"
#include "cppa/partial_function.hpp"
......@@ -65,6 +64,7 @@ void invoke_test(std::vector<any_tuple>& test_tuples, Testee& x) {
int main() {
CPPA_TEST(test__pattern);
/*
pattern<int, anything, int> i3;
any_tuple i3_any_tup = make_cow_tuple(1, 2, 3);
......@@ -170,6 +170,7 @@ int main() {
}
);
CPPA_CHECK_EQUAL(true, invoked);
*/
/*
CPPA_CHECK(p0(x));
......
......@@ -14,7 +14,6 @@
#include "cppa/on.hpp"
#include "cppa/cppa.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/pattern.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/to_string.hpp"
#include "cppa/tuple_cast.hpp"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment