Commit 858cd36d authored by Dominik Charousset's avatar Dominik Charousset

Make make_stage_result a utility trait

parent c693c48d
......@@ -151,13 +151,6 @@ public:
(*this)(x.in(), x.out(), ptr);
}
/// Calls `(*this)(x.in(), x.out(), x.ptr())`.
template <class In, class Result, class Out, class S, class... Ts>
void operator()(make_stage_result<In, Result, Out, S, Ts...>& x) {
stream_manager_ptr ptr{std::move(x.ptr())};
(*this)(x.in(), x.out(), ptr);
}
/// Calls `(*this)(x.in(), 0, x.ptr())`.
template <class T, class P>
void operator()(stream_result<T, P>& x) {
......
......@@ -62,7 +62,6 @@ template <class...> class typed_event_based_actor;
// -- variadic templates with fixed arguments ----------------------------------
template <class, class, class, class, class...> class make_stage_result;
template <class, class, class, class, class...> class stream_stage;
template <class, class, class...> class stream_source;
......
......@@ -33,7 +33,7 @@ namespace caf {
/// `scheduled_actor::make_source`.
template <class Scatterer, class... Ts>
struct make_source_result {
/// Element type.
/// Type of a single element.
using value_type = typename Scatterer::value_type;
/// Fully typed stream manager as returned by `make_source`.
......
......@@ -20,86 +20,38 @@
#define CAF_MAKE_STAGE_RESULT_HPP
#include "caf/fwd.hpp"
#include "caf/output_stream.hpp"
#include "caf/stream_slot.hpp"
#include "caf/stream_stage.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/meta/type_name.hpp"
namespace caf {
/// Identifies an unbound sequence of elements annotated with the additional
/// handshake arguments emitted to the next stage.
template <class In, class Result, class Out, class Scatterer, class... Ts>
/// Helper trait for deducing an `output_stream` from the arguments to
/// `scheduled_actor::make_stage`.
template <class In, class Result, class Scatterer, class... Ts>
class make_stage_result {
public:
// -- member types -----------------------------------------------------------
/// Type of a single element.
using value_type = Out;
using value_type = typename Scatterer::value_type;
/// Fully typed stream manager as returned by `make_stage`.
using ptr_type = stream_stage_ptr<In, Result, Out, Scatterer, Ts...>;
// -- constructors, destructors, and assignment operators --------------------
make_stage_result(make_stage_result&&) = default;
make_stage_result(const make_stage_result&) = default;
make_stage_result(stream_slot in_slot, stream_slot out_slot, ptr_type ptr)
: in_(in_slot),
out_(out_slot),
ptr_(std::move(ptr)) {
// nop
}
// -- properties -------------------------------------------------------------
/// Returns the slot of the origin stream if `ptr()` is a stage or 0 if
/// `ptr()` is a source.
inline stream_slot in() const {
return in_;
}
/// Returns the output slot.
inline stream_slot out() const {
return out_;
}
/// Returns the handler assigned to this stream on this actor.
inline ptr_type& ptr() noexcept {
return ptr_;
}
/// Returns the handler assigned to this stream on this actor.
inline const ptr_type& ptr() const noexcept {
return ptr_;
}
// -- serialization support --------------------------------------------------
template <class Inspector>
friend typename Inspector::result_type inspect(Inspector& f,
make_stage_result& x) {
return f(meta::type_name("make_stage_result"), x.in_, x.out_);
}
using stage_type = stream_stage<In, Result, value_type, Scatterer, Ts...>;
private:
// -- member variables -------------------------------------------------------
/// Pointer to a fully typed stream manager.
using stage_ptr_type = intrusive_ptr<stage_type>;
stream_slot in_;
stream_slot out_;
ptr_type ptr_;
/// The return type for `scheduled_actor::make_sink`.
using type = output_stream<value_type, std::tuple<Ts...>, stage_ptr_type>;
};
/// Helper type for defining a `make_stage_result` from a `Scatterer` plus
/// additional handshake types. Hardwires `message` as result type.
template <class In, class Scatterer, class... Ts>
using make_stage_result_t =
make_stage_result<In, message, typename Scatterer::value_type, Scatterer,
detail::decay_t<Ts>...>;
typename make_stage_result<In, message, Scatterer,
detail::decay_t<Ts>...>::type;
} // namespace caf
......
......@@ -23,8 +23,6 @@
#include "caf/invalid_stream.hpp"
#include "caf/stream_slot.hpp"
#include "caf/meta/type_name.hpp"
namespace caf {
/// Identifies an unbound sequence of elements annotated with the additional
......
......@@ -544,7 +544,7 @@ public:
}
template <class Driver, class In, class... Ts>
typename Driver::make_stage_result_type make_stage(const stream<In>& src,
typename Driver::output_stream_type make_stage(const stream<In>& src,
Ts&&... xs) {
using detail::make_stream_stage;
auto mgr = make_stream_stage<Driver>(this, std::forward<Ts>(xs)...);
......
......@@ -50,9 +50,6 @@ public:
/// Type of the output stream.
using stream_type = stream<output_type>;
/// Type of the output stream including handshake argument types.
using output_stream_type = output_stream<output_type, Ts...>;
/// Tuple for creating the `open_stream_msg` handshake.
using handshake_tuple_type = std::tuple<stream_type, Ts...>;
......@@ -63,10 +60,10 @@ public:
/// Smart pointer to the interface type.
using stage_ptr_type = intrusive_ptr<stage_type>;
/// Wrapper type holding a pointer to `stage_type`.
using make_stage_result_type =
make_stage_result<input_type, result_type, output_type, scatterer_type,
Ts...>;
/// Type of the output stream including handshake argument types.
using output_stream_type = output_stream<output_type, std::tuple<Ts...>,
stage_ptr_type>;
// -- constructors, destructors, and assignment operators --------------------
......
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