9#include "arg_wrappers.hpp"
11#include "introspect.hpp"
12#include "numeric_traits.hpp"
13#include "processor.hpp"
30template <
typename T,
typename Event>
32 std::move_constructible<T> &&
requires(T
const &m, Event
const &e) {
33 { m(e) } -> std::same_as<bool>;
38template <
typename Event,
typename OutEvent,
typename Matcher,
39 bool PassMatched,
typename Downstream>
44 Downstream downstream;
47 explicit match(Matcher matcher, Downstream downstream)
48 : matcher(std::move(matcher)), downstream(std::move(downstream)) {}
50 [[nodiscard]]
auto introspect_node() const -> processor_info {
51 return processor_info(
this,
"match");
54 [[nodiscard]]
auto introspect_graph() const -> processor_graph {
55 return downstream.introspect_graph().push_entry_point(
this);
59 requires(std::convertible_to<std::remove_cvref_t<E>, Event> and
60 handler_for<Downstream, std::remove_cvref_t<E>>)
61 void handle(E &&event) {
62 auto const abstime =
event.abstime;
63 bool const matched = matcher(event);
64 bool const pass = PassMatched ? true : not matched;
66 downstream.handle(std::forward<E>(event));
68 downstream.handle(OutEvent{abstime});
72 requires(not std::convertible_to<std::remove_cvref_t<E>, Event> and
73 handler_for<Downstream, std::remove_cvref_t<E>>)
74 void handle(E &&event) {
75 downstream.handle(std::forward<E>(event));
78 void flush() { downstream.flush(); }
98template <
typename Event,
typename OutEvent,
typename Matcher,
101 return internal::match<Event, OutEvent, Matcher, false, Downstream>(
102 std::move(matcher), std::move(downstream));
139template <
typename Event,
typename OutEvent,
typename Matcher,
141auto match(Matcher matcher, Downstream downstream) {
142 return internal::match<Event, OutEvent, Matcher, true, Downstream>(
143 std::move(matcher), std::move(downstream));
154 template <
typename Event>
168 template <
typename Event>
183template <
typename NumericTraits = default_numeric_traits>
185 NumericTraits::channel_type channel;
193 : channel(channel.value) {}
196 template <
typename Event>
198 static_assert(std::is_same_v<
decltype(
event.channel),
199 typename NumericTraits::channel_type>);
200 return event.channel == channel;
Matcher that matches all events.
Definition match.hpp:151
auto operator()(Event const &) const -> bool
Implements matcher requirement; return true.
Definition match.hpp:155
channel_matcher(arg::channel< typename NumericTraits::channel_type > channel)
Construct with the given channel to match.
Definition match.hpp:191
auto operator()(Event const &event) const -> bool
Implements matcher requirement.
Definition match.hpp:197
Matcher that matches no event.
Definition match.hpp:165
auto operator()(Event const &) const -> bool
Implements matcher requirement; return false.
Definition match.hpp:169
Concept that is satisfied when T conforms to the libtcspc matcher interface for event type Event.
Definition match.hpp:31
Concept that is satisfied when a processor handles the given event types and flush.
Definition processor.hpp:119
auto match(Matcher matcher, Downstream downstream)
Create a processor that detects events matching a criterion.
Definition match.hpp:141
auto match_and_consume(Matcher matcher, Downstream downstream)
Like tcspc::match(), but do not pass through matched events.
Definition match.hpp:100
libtcspc namespace.
Definition acquire.hpp:30
Function argument wrapper for channel parameter.
Definition arg_wrappers.hpp:77