10#include "introspect.hpp"
11#include "processor.hpp"
12#include "type_list.hpp"
13#include "variant_event.hpp"
23template <
typename EventList,
typename Downstream>
class multiplex {
24 static_assert(processor<Downstream, variant_event<EventList>>);
26 Downstream downstream;
29 explicit multiplex(Downstream downstream)
30 : downstream(std::move(downstream)) {}
32 [[nodiscard]]
auto introspect_node() const -> processor_info {
33 return processor_info(
this,
"multiplex");
36 [[nodiscard]]
auto introspect_graph() const -> processor_graph {
37 return downstream.introspect_graph().push_entry_point(
this);
40 template <
typename Event>
41 requires convertible_to_type_list_member<std::remove_cvref_t<Event>,
43 void handle(Event &&event) {
45 variant_event<EventList>(std::forward<Event>(event)));
48 void flush() { downstream.flush(); }
51template <
typename Downstream>
class demultiplex {
52 static_assert(flushable<Downstream>);
54 Downstream downstream;
57 explicit demultiplex(Downstream downstream)
58 : downstream(std::move(downstream)) {}
60 [[nodiscard]]
auto introspect_node() const -> processor_info {
61 return processor_info(
this,
"demultiplex");
64 [[nodiscard]]
auto introspect_graph() const -> processor_graph {
65 return downstream.introspect_graph().push_entry_point(
this);
68 template <
typename EL>
70 void handle(variant_event<EL>
const &event) {
71 std::visit([&](
auto const &e) { downstream.handle(e); }, event);
74 template <
typename EL>
76 void handle(variant_event<EL> &&event) {
78 [&]<
typename E>(E &&e) { downstream.handle(std::forward<E>(e)); },
82 void flush() { downstream.flush(); }
111template <
typename EventList,
typename Downstream>
114 "multiplex requires non-empty event list");
115 return internal::multiplex<EventList, Downstream>(std::move(downstream));
142template <
typename Downstream>
auto demultiplex(Downstream downstream) {
143 return internal::demultiplex<Downstream>(std::move(downstream));
constexpr bool handles_event_list_v
Trait variable to check whether a processor handles a list of event types.
Definition processor.hpp:194
auto multiplex(Downstream downstream)
Create a processor that passes events as a single variant type.
Definition multiplex.hpp:112
auto demultiplex(Downstream downstream)
Create a processor that transforms an event variant type back to individual event types.
Definition multiplex.hpp:142
constexpr std::size_t type_list_size_v
Helper variable template for tcspc::type_list_size.
Definition type_list.hpp:97
libtcspc namespace.
Definition acquire.hpp:29