Commit 78bcec72 authored by Dominik Charousset's avatar Dominik Charousset

Remove deprecated headers

parent 3c873350
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CPPA_ANY_TUPLE_HPP
#define CPPA_ANY_TUPLE_HPP
#include "caf/message.hpp"
namespace caf {
using any_tuple = message;
template <class... Ts>
any_tuple make_any_tuple(Ts&&... ts) {
return make_message(std::forward<Ts>(ts)...);
}
} // namespace caf
#endif // CPPA_ANY_TUPLE_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CPPA_COW_TUPLE_HPP
#define CPPA_COW_TUPLE_HPP
// <backward_compatibility version="0.9" whole_file="yes">
#include <cstddef>
#include <string>
#include <typeinfo>
#include <type_traits>
#include "caf/message.hpp"
#include "caf/ref_counted.hpp"
#include "caf/detail/tuple_vals.hpp"
#include "caf/detail/decorated_tuple.hpp"
#include "caf/detail/implicit_conversions.hpp"
namespace caf {
template <class... Ts>
class cow_tuple;
template <class Head, class... Tail>
class cow_tuple<Head, Tail...> {
static_assert(detail::tl_forall<detail::type_list<Head, Tail...>,
detail::is_legal_tuple_type
>::value,
"illegal types in cow_tuple definition: "
"pointers and references are prohibited");
using data_type =
detail::tuple_vals<typename detail::strip_and_convert<Head>::type,
typename detail::strip_and_convert<Tail>::type...>;
using data_ptr = detail::message_data::ptr;
public:
using types = detail::type_list<Head, Tail...>;
static constexpr size_t num_elements = sizeof...(Tail) + 1;
cow_tuple() : m_vals(new data_type) {
// nop
}
template <class... Ts>
cow_tuple(Head arg, Ts&&... args)
: m_vals(new data_type(std::move(arg), std::forward<Ts>(args)...)) {
// nop
}
cow_tuple(cow_tuple&&) = default;
cow_tuple(const cow_tuple&) = default;
cow_tuple& operator=(cow_tuple&&) = default;
cow_tuple& operator=(const cow_tuple&) = default;
inline size_t size() const {
return sizeof...(Tail) + 1;
}
inline const void* at(size_t p) const {
return m_vals->at(p);
}
inline void* mutable_at(size_t p) {
return m_vals->mutable_at(p);
}
inline const uniform_type_info* type_at(size_t p) const {
return m_vals->type_at(p);
}
inline cow_tuple<Tail...> drop_left() const {
return cow_tuple<Tail...>::offset_subtuple(m_vals, 1);
}
inline operator message() const {
return message{m_vals};
}
static cow_tuple from(message& msg) {
return cow_tuple(msg.vals());
}
private:
cow_tuple(data_ptr ptr) : m_vals(ptr) { }
data_type* ptr() {
return static_cast<data_type*>(m_vals.get());
}
const data_type* ptr() const {
return static_cast<data_type*>(m_vals.get());
}
data_ptr m_vals;
};
template <size_t N, class... Ts>
const typename detail::type_at<N, Ts...>::type&
get(const cow_tuple<Ts...>& tup) {
using result_type = typename detail::type_at<N, Ts...>::type;
return *reinterpret_cast<const result_type*>(tup.at(N));
}
template <size_t N, class... Ts>
typename detail::type_at<N, Ts...>::type&
get_ref(cow_tuple<Ts...>& tup) {
using result_type = typename detail::type_at<N, Ts...>::type;
return *reinterpret_cast<result_type*>(tup.mutable_at(N));
}
template <class... Ts>
cow_tuple<typename detail::strip_and_convert<Ts>::type...>
make_cow_tuple(Ts&&... args) {
return {std::forward<Ts>(args)...};
}
template <class TypeList>
struct cow_tuple_from_type_list;
template <class... Ts>
struct cow_tuple_from_type_list<detail::type_list<Ts...>> {
typedef cow_tuple<Ts...> type;
};
} // namespace caf
// </backward_compatibility>
#endif // CPPA_COW_TUPLE_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CPPA_CPPA_HPP
#define CPPA_CPPA_HPP
// <backward_compatibility version="0.9" whole_file="yes">
// include new header
#include "caf/all.hpp"
// include compatibility headers
#include "cppa/opt.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/cow_tuple.hpp"
#include "cppa/tuple_cast.hpp"
#include "cppa/publish_local_groups.hpp"
// headers for classes and functions that have been moved
#include "caf/io/all.hpp"
// be nice to code using legacy macros
#define CPPA_VERSION CAF_VERSION
// set old namespace to new namespace
namespace cppa = caf;
// re-import a couple of moved things backinto the global CAF namespace
namespace caf {
using io::accept_handle;
using io::connection_handle;
using io::publish;
using io::remote_actor;
using io::max_msg_size;
using io::typed_publish;
using io::typed_remote_actor;
using io::publish_local_groups;
using io::new_connection_msg;
using io::new_data_msg;
using io::connection_closed_msg;
using io::acceptor_closed_msg;
} // namespace caf
// </backward_compatibility>
#endif // CPPA_CPPA_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CPPA_CPPA_FWD_HPP
#define CPPA_CPPA_FWD_HPP
// <backward_compatibility version="0.9" whole_file="yes">
#include "caf/fwd.hpp"
namespace caf {
using any_tuple = message;
template <class... Ts>
class cow_tuple;
} // namespace caf
// </backward_compatibility>
#endif // CPPA_CPPA_FWD_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CPPA_OPT_HPP
#define CPPA_OPT_HPP
// <backward_compatibility version="0.9" whole_file="yes">
#include <map>
#include <string>
#include <vector>
#include <iomanip>
#include <sstream>
#include <iostream>
#include <functional>
#include "caf/on.hpp"
#include "caf/optional.hpp"
#include "cppa/opt_impls.hpp"
namespace caf {
using string_proj = std::function<optional<std::string> (const std::string&)>;
inline string_proj extract_longopt_arg(const std::string& prefix) {
return [prefix](const std::string& arg) -> optional<std::string> {
if (arg.compare(0, prefix.size(), prefix) == 0) {
return std::string(arg.begin() + static_cast<ptrdiff_t>(prefix.size()),
arg.end());
}
return none;
};
}
/**
* Right-hand side of a match expression for a program option
* reading an argument of type `T`.
*/
template <class T>
detail::rd_arg_functor<T> rd_arg(T& storage) {
return {storage};
}
/**
* Right-hand side of a match expression for a program option
* adding an argument of type `T` to `storage`.
*/
template <class T>
detail::add_arg_functor<T> add_arg(std::vector<T>& storage) {
return {storage};
}
/**
* Right-hand side of a match expression for a program option
* reading a boolean flag.
*/
inline std::function<void()> set_flag(bool& storage) {
return [&] { storage = true; };
}
/**
* Stores a help text along with the number of expected arguments.
*/
struct option_info {
std::string help_text;
size_t num_args;
};
/**
* Stores a help text for program options with option groups.
*/
using options_description =
std::map<
std::string,
std::map<
std::pair<char, std::string>,
option_info
>
>;
using opt_rvalue_builder =
decltype(on(std::function<optional<std::string> (const std::string&)>{})
|| on(std::string{}, val<std::string>));
using opt0_rvalue_builder = decltype(on(std::string{}) || on(std::string{}));
/**
* Left-hand side of a match expression for a program option with one argument.
*/
inline opt_rvalue_builder on_opt1(char short_opt,
std::string long_opt,
options_description* desc = nullptr,
std::string help_text = "",
std::string help_group = "general options") {
if (desc) {
option_info oinf{move(help_text), 1};
(*desc)[help_group].insert(std::make_pair(
std::make_pair(short_opt, long_opt),
std::move(oinf)));
}
const char short_flag_arr[] = {'-', short_opt, '\0' };
const char* lhs_str = short_flag_arr;
std::string prefix = "--";
prefix += std::move(long_opt);
prefix += "=";
return on(extract_longopt_arg(prefix)) || on(lhs_str, val<std::string>);
}
/**
* Left-hand side of a match expression for a program option with no argument.
*/
inline opt0_rvalue_builder on_opt0(char short_opt,
std::string long_opt,
options_description* desc = nullptr,
std::string help_text = "",
std::string help_group = "general options") {
if (desc) {
option_info oinf{help_text, 0};
(*desc)[help_group].insert(std::make_pair(std::make_pair(short_opt,
long_opt),
std::move(oinf)));
}
const char short_flag_arr[] = {'-', short_opt, '\0' };
std::string short_opt_string = short_flag_arr;
return on("--" + long_opt) || on(short_opt_string);
}
/**
* Returns a function that prints the help text of `desc` to `out`.
*/
inline std::function<void()> print_desc(options_description* desc,
std::ostream& out = std::cout) {
return [&out, desc] {
if (!desc) return;
if (desc->empty()) {
out << "please use '-h' or '--help' for a list "
"of available program options\n";
}
for (auto& opt_group : *desc) {
out << opt_group.first << ":\n";
for (auto& opt : opt_group.second) {
out << " ";
out << std::setw(40) << std::left;
std::ostringstream tmp;
auto& names = opt.first;
if (names.first != '\0') {
tmp << "-" << names.first;
for (size_t num = 1; num <= opt.second.num_args; ++num) {
tmp << " <arg" << num << ">";
}
tmp << " | ";
}
tmp << "--" << names.second;
if (opt.second.num_args > 0) {
tmp << "=<arg1>";
}
for (size_t num = 2; num <= opt.second.num_args; ++num) {
tmp << ", <arg" << num << ">";
}
out << tmp.str() << opt.second.help_text << "\n";
}
out << "\n";
}
};
}
/**
* Returns a function that prints the help text of `desc` to `out`
* and then calls `exit(exit_reason).
*/
inline std::function<void()> print_desc_and_exit(options_description* desc,
std::ostream& out = std::cout,
int exit_reason = 0) {
auto fun = print_desc(desc, out);
return [=] {
fun();
exit(exit_reason);
};
}
} // namespace caf
// </backward_compatibility>
#endif // CPPA_OPT_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CPPA_DETAIL_OPT_IMPLS_HPP
#define CPPA_DETAIL_OPT_IMPLS_HPP
#include <sstream>
#include "caf/on.hpp"
#include "caf/optional.hpp"
// this header contains implementation details for opt.hpp
namespace caf {
namespace detail {
template <class T>
struct conv_arg_impl {
using result_type = optional<T>;
static inline result_type _(const std::string& arg) {
std::istringstream iss(arg);
T result;
if (iss >> result && iss.eof()) {
return result;
}
return none;
}
};
template <>
struct conv_arg_impl<std::string> {
using result_type = optional<std::string>;
static inline result_type _(const std::string& arg) { return arg; }
};
template <class T>
struct conv_arg_impl<optional<T>> {
using result_type = optional<T>;
static inline result_type _(const std::string& arg) {
return conv_arg_impl<T>::_(arg);
}
};
template <bool>
class opt1_rvalue_builder;
template <class T>
struct rd_arg_storage : ref_counted {
T& storage;
bool set;
std::string arg_name;
rd_arg_storage(T& r) : storage(r), set(false) {
// nop
}
};
template <class T>
class rd_arg_functor {
public:
template <bool>
friend class opt1_rvalue_builder;
using storage_type = rd_arg_storage<T>;
rd_arg_functor(const rd_arg_functor&) = default;
rd_arg_functor(T& storage) : m_storage(new storage_type(storage)) {
// nop
}
bool operator()(const std::string& arg) const {
if (m_storage->set) {
std::cerr << "*** error: " << m_storage->arg_name
<< " already defined" << std::endl;
return false;
}
auto opt = conv_arg_impl<T>::_(arg);
if (!opt) {
std::cerr << "*** error: cannot convert \"" << arg << "\" to "
<< typeid(T).name()
<< " [option: \"" << m_storage->arg_name << "\"]"
<< std::endl;
return false;
}
m_storage->storage = *opt;
m_storage->set = true;
return true;
}
private:
intrusive_ptr<storage_type> m_storage;
};
template <class T>
class add_arg_functor {
public:
template <bool>
friend class opt1_rvalue_builder;
using value_type = std::vector<T>;
using storage_type = rd_arg_storage<value_type>;
add_arg_functor(const add_arg_functor&) = default;
add_arg_functor(value_type& storage) : m_storage(new storage_type(storage)) {
// nop
}
bool operator()(const std::string& arg) const {
auto opt = conv_arg_impl<T>::_(arg);
if (!opt) {
std::cerr << "*** error: cannot convert \"" << arg << "\" to "
<< typeid(T).name()
<< " [option: \"" << m_storage->arg_name << "\"]"
<< std::endl;
return false;
}
m_storage->storage.push_back(*opt);
return true;
}
private:
intrusive_ptr<storage_type> m_storage;
};
template <class T>
struct is_rd_arg : std::false_type { };
template <class T>
struct is_rd_arg<rd_arg_functor<T>> : std::true_type { };
template <class T>
struct is_rd_arg<add_arg_functor<T>> : std::true_type { };
using opt0_rvalue_builder = decltype(on<std::string>());
template <bool HasShortOpt = true>
class opt1_rvalue_builder {
public:
using left_type = decltype(on<std::string, std::string>());
using right_type =
decltype(on(std::function<optional<std::string> (const std::string&)>()));
template <class Left, typename Right>
opt1_rvalue_builder(char sopt, std::string lopt, Left&& lhs, Right&& rhs)
: m_short(sopt),
m_long(std::move(lopt)),
m_left(std::forward<Left>(lhs)),
m_right(std::forward<Right>(rhs)) {
// nop
}
template <class Expr>
auto operator>>(Expr expr)
-> decltype((*(static_cast<left_type*>(nullptr)) >> expr).or_else(
*(static_cast<right_type*>(nullptr)) >> expr)) const {
inject_arg_name(expr);
return (m_left >> expr).or_else(m_right >> expr);
}
private:
template <class T>
void inject_arg_name(rd_arg_functor<T>& expr) {
expr.m_storage->arg_name = m_long;
}
template <class T>
void inject_arg_name(const T&) {
// using opts without rd_arg() or similar functor
}
char m_short;
std::string m_long;
left_type m_left;
right_type m_right;
};
template <>
class opt1_rvalue_builder<false> {
public:
using sub_type =
decltype(on(std::function<optional<std::string> (const std::string&)>()));
template <class SubType>
opt1_rvalue_builder(std::string lopt, SubType&& sub)
: m_long(std::move(lopt)),
m_sub(std::forward<SubType>(sub)) {
// nop
}
template <class Expr>
auto operator>>(Expr expr)
-> decltype(*static_cast<sub_type*>(nullptr) >> expr) const {
inject_arg_name(expr);
return m_sub >> expr;
}
private:
template <class T>
inline void inject_arg_name(rd_arg_functor<T>& expr) {
expr.m_storage->arg_name = m_long;
}
template <class T>
inline void inject_arg_name(const T&) {
// using opts without rd_arg() or similar functor
}
std::string m_long;
sub_type m_sub;
};
} // namespace detail
} // namespace caf
#endif // CPPA_DETAIL_OPT_IMPLS_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CPPA_PUBLISH_LOCAL_GROUPS_HPP
#define CPPA_PUBLISH_LOCAL_GROUPS_HPP
// <backward_compatibility version="0.9" whole_file="yes">
#include "caf/io/publish_local_groups.hpp"
namespace caf {
// import into caf for the sake of backwart compatibility
using io::publish_local_groups;
} // namespace caf
// </backward_compatibility>
#endif // CPPA_PUBLISH_LOCAL_GROUPS_HPP
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/io/spawn_io.hpp"
namespace caf {
// import io::spawn_io for backward compatbility reasons
using io::spawn_io;
} // namespace caf
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2014 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CPPA_TUPLE_CAST_HPP
#define CPPA_TUPLE_CAST_HPP
// <backward_compatibility version="0.9" whole_file="yes">
#include <type_traits>
#include "caf/message.hpp"
#include "caf/optional.hpp"
#include "caf/wildcard_position.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/detail/types_array.hpp"
#include "caf/detail/decorated_tuple.hpp"
#include "cppa/cow_tuple.hpp"
namespace caf {
template <class TupleIter, class PatternIter,
class Push, class Commit, class Rollback>
bool dynamic_match(TupleIter tbegin, TupleIter tend,
PatternIter pbegin, PatternIter pend,
Push& push, Commit& commit, Rollback& rollback) {
while (!(pbegin == pend && tbegin == tend)) {
if (pbegin == pend) {
// reached end of pattern while some values remain unmatched
return false;
}
else if (*pbegin == nullptr) { // nullptr == wildcard (anything)
// perform submatching
++pbegin;
// always true at the end of the pattern
if (pbegin == pend) return true;
// safe current mapping as fallback
commit();
// iterate over tuple values until we found a match
for (; tbegin != tend; ++tbegin) {
if (dynamic_match(tbegin, tend, pbegin, pend,
push, commit, rollback)) {
return true;
}
// restore mapping to fallback (delete invalid mappings)
rollback();
}
return false; // no submatch found
}
// compare types
else if (tbegin.type() == *pbegin) push(tbegin);
// no match
else return false;
// next iteration
++tbegin;
++pbegin;
}
return true; // pbegin == pend && tbegin == tend
}
template <class... T>
auto moving_tuple_cast(message& tup)
-> optional<
typename cow_tuple_from_type_list<
typename detail::tl_filter_not<detail::type_list<T...>,
is_anything>::type
>::type> {
using result_type =
typename cow_tuple_from_type_list<
typename detail::tl_filter_not<detail::type_list<T...>, is_anything>::type
>::type;
using types = detail::type_list<T...>;
static constexpr auto impl =
get_wildcard_position<detail::type_list<T...>>();
auto& tarr = detail::static_types_array<T...>::arr;
const uniform_type_info* const* arr_pos = tarr.begin();
message sub;
switch (impl) {
case wildcard_position::nil: {
sub = tup;
break;
}
case wildcard_position::trailing: {
sub = tup.take(sizeof...(T) - 1);
break;
}
case wildcard_position::leading: {
++arr_pos; // skip leading 'anything'
sub = tup.take_right(sizeof...(T) - 1);
break;
}
case wildcard_position::in_between:
case wildcard_position::multiple: {
constexpr size_t wc_count =
detail::tl_count<detail::type_list<T...>, is_anything>::value;
if (tup.size() >= (sizeof...(T) - wc_count)) {
std::vector<size_t> mv; // mapping vector
size_t commited_size = 0;
auto fpush = [&](const typename message::const_iterator& iter) {
mv.push_back(iter.position());
};
auto fcommit = [&] {
commited_size = mv.size();
};
auto frollback = [&] {
mv.resize(commited_size);
};
if (dynamic_match(tup.begin(), tup.end(),
tarr.begin(), tarr.end(),
fpush, fcommit, frollback)) {
message msg{detail::decorated_tuple::create(
tup.vals(), std::move(mv))};
return result_type::from(msg);
}
return none;
}
break;
}
}
// same for nil, leading, and trailing
auto eq = [](const detail::message_iterator& lhs,
const uniform_type_info* rhs) {
return lhs.type() == rhs;
};
if (std::equal(sub.begin(), sub.end(), arr_pos, eq)) {
return result_type::from(sub);
}
return none;
}
template <class... T>
auto moving_tuple_cast(message& tup, const detail::type_list<T...>&)
-> decltype(moving_tuple_cast<T...>(tup)) {
return moving_tuple_cast<T...>(tup);
}
template <class... T>
auto tuple_cast(message tup)
-> optional<
typename cow_tuple_from_type_list<
typename detail::tl_filter_not<detail::type_list<T...>,
is_anything>::type
>::type> {
return moving_tuple_cast<T...>(tup);
}
template <class... T>
auto tuple_cast(message tup, const detail::type_list<T...>&)
-> decltype(tuple_cast<T...>(tup)) {
return moving_tuple_cast<T...>(tup);
}
template <class... T>
auto unsafe_tuple_cast(message& tup, const detail::type_list<T...>&)
-> decltype(tuple_cast<T...>(tup)) {
return tuple_cast<T...>(tup);
}
} // namespace caf
// </backward_compatibility>
#endif // 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