9#include "arg_wrappers.hpp"
11#include "data_types.hpp"
12#include "introspect.hpp"
13#include "processor.hpp"
22template <
typename Event,
typename OutEvent,
typename Matcher,
23 bool PassMatched,
typename Downstream>
25 static_assert(processor<Downstream, Event, OutEvent>);
28 Downstream downstream;
31 explicit match(Matcher matcher, Downstream downstream)
32 : matcher(std::move(matcher)), downstream(std::move(downstream)) {}
34 [[nodiscard]]
auto introspect_node() const -> processor_info {
35 return processor_info(
this,
"match");
38 [[nodiscard]]
auto introspect_graph() const -> processor_graph {
39 return downstream.introspect_graph().push_entry_point(
this);
43 requires(std::convertible_to<std::remove_cvref_t<E>, Event> and
44 handler_for<Downstream, std::remove_cvref_t<E>>)
45 void handle(E &&event) {
46 auto const abstime =
event.abstime;
47 bool const matched = matcher(event);
48 bool const pass = PassMatched ? true : not matched;
50 downstream.handle(std::forward<E>(event));
52 downstream.handle(OutEvent{abstime});
56 requires(not std::convertible_to<std::remove_cvref_t<E>, Event> and
57 handler_for<Downstream, std::remove_cvref_t<E>>)
58 void handle(E &&event) {
59 downstream.handle(std::forward<E>(event));
62 void flush() { downstream.flush(); }
82template <
typename Event,
typename OutEvent,
typename Matcher,
85 return internal::match<Event, OutEvent, Matcher, false, Downstream>(
86 std::move(matcher), std::move(downstream));
123template <
typename Event,
typename OutEvent,
typename Matcher,
125auto match(Matcher matcher, Downstream downstream) {
126 return internal::match<Event, OutEvent, Matcher, true, Downstream>(
127 std::move(matcher), std::move(downstream));
138 template <
typename Event>
152 template <
typename Event>
168 typename DataTypes::channel_type channel;
176 : channel(channel.value) {}
179 template <
typename Event>
181 static_assert(std::is_same_v<
decltype(
event.channel),
182 typename DataTypes::channel_type>);
183 return event.channel == channel;
Matcher that matches all events.
Definition match.hpp:135
auto operator()(Event const &) const -> bool
Implements matcher requirement; return true.
Definition match.hpp:139
channel_matcher(arg::channel< typename DataTypes::channel_type > channel)
Construct with the given channel to match.
Definition match.hpp:174
auto operator()(Event const &event) const -> bool
Implements matcher requirement.
Definition match.hpp:180
Matcher that matches no event.
Definition match.hpp:149
auto operator()(Event const &) const -> bool
Implements matcher requirement; return false.
Definition match.hpp:153
auto match(Matcher matcher, Downstream downstream)
Create a processor that detects events matching a criterion.
Definition match.hpp:125
auto match_replace(Matcher matcher, Downstream downstream)
Like tcspc::match(), but do not pass through matched events.
Definition match.hpp:84
libtcspc namespace.
Definition acquire.hpp:29
Function argument wrapper for channel parameter.
Definition arg_wrappers.hpp:77