10#include "introspect.hpp"
11#include "processor.hpp"
25template <
typename Event>
class record_last_accessor {
26 std::function<std::optional<Event>()> get_fn;
31 explicit record_last_accessor(F get_func) : get_fn(get_func) {}
34 auto get() -> std::optional<Event> {
return get_fn(); }
39template <
typename Event,
typename Downstream>
class record_last {
40 std::optional<Event> last;
42 Downstream downstream;
45 access_tracker<record_last_accessor<Event>> trk;
48 explicit record_last(access_tracker<record_last_accessor<Event>> &&tracker,
49 Downstream downstream)
50 : downstream(std::move(downstream)), trk(std::move(tracker)) {
51 trk.register_accessor_factory([](
auto &tracker) {
54 return record_last_accessor<Event>([self] {
return self->last; });
58 [[nodiscard]]
auto introspect_node() const -> processor_info {
59 return processor_info(
this,
"record_last");
62 [[nodiscard]]
auto introspect_graph() const -> processor_graph {
63 return downstream.introspect_graph().push_entry_point(
this);
67 requires handler_for<Downstream, std::remove_cvref_t<E>>
68 void handle(E &&event) {
69 if constexpr (std::is_same_v<std::remove_cvref_t<E>, Event>)
71 downstream.handle(std::forward<E>(event));
74 void flush() { downstream.flush(); }
112template <
typename Event,
typename Downstream>
114 Downstream downstream) {
115 return internal::record_last<Event, Downstream>(std::move(tracker),
116 std::move(downstream));
Tracker that mediates access to objects via a tcspc::context.
Definition context.hpp:39
Accessor for tcspc::record_last() processor data.
Definition record_last.hpp:25
auto get() -> std::optional< Event >
Return the last event observed, or empty if none was.
Definition record_last.hpp:34
#define LIBTCSPC_OBJECT_FROM_TRACKER(obj_type, tracker_field_name, tracker)
Recover the object address from a tcspc::access_tracker embedded in the object.
Definition context.hpp:255
auto record_last(access_tracker< record_last_accessor< Event > > &&tracker, Downstream downstream)
Create a processor that remembers the last event of a given type.
Definition record_last.hpp:113
libtcspc namespace.
Definition acquire.hpp:30