11#include "introspect.hpp"
12#include "numeric_traits.hpp"
13#include "processor.hpp"
27template <
typename Abstime>
class record_abstime_range_accessor {
28 std::function<std::optional<Abstime>()> min_fn;
29 std::function<std::optional<Abstime>()> max_fn;
33 template <
typename FMin,
typename FMax>
34 explicit record_abstime_range_accessor(FMin min_func, FMax max_func)
35 : min_fn(min_func), max_fn(max_func) {}
41 auto min() -> std::optional<Abstime> {
return min_fn(); }
47 auto max() -> std::optional<Abstime> {
return max_fn(); }
52template <
typename NumericTraits,
typename Downstream>
54 using abstime_type =
typename NumericTraits::abstime_type;
56 std::optional<abstime_type> mn;
57 std::optional<abstime_type> mx;
59 Downstream downstream;
62 access_tracker<record_abstime_range_accessor<abstime_type>> trk;
65 explicit record_abstime_range(
66 access_tracker<record_abstime_range_accessor<abstime_type>> &&tracker,
67 Downstream downstream)
68 : downstream(std::move(downstream)), trk(std::move(tracker)) {
69 trk.register_accessor_factory([](
auto &tracker) {
72 return record_abstime_range_accessor<abstime_type>(
73 [self] {
return self->mn; }, [self] {
return self->mx; });
77 [[nodiscard]]
auto introspect_node() const -> processor_info {
78 return processor_info(
this,
"record_abstime_range");
81 [[nodiscard]]
auto introspect_graph() const -> processor_graph {
82 return downstream.introspect_graph().push_entry_point(
this);
86 requires handler_for<Downstream, std::remove_cvref_t<E>>
87 void handle(E &&event) {
88 if constexpr (abstime_stamped<std::remove_cvref_t<E>>) {
90 std::is_same_v<
decltype(
event.abstime), abstime_type>);
91 if (not mn || event.abstime < *mn)
93 if (not mx || event.abstime > *mx)
96 downstream.handle(std::forward<E>(event));
99 void flush() { downstream.flush(); }
133template <
typename NumericTraits = default_numeric_traits,
typename Downstream>
135 typename NumericTraits::abstime_type>> &&tracker,
136 Downstream downstream) {
137 return internal::record_abstime_range<NumericTraits, Downstream>(
138 std::move(tracker), std::move(downstream));
Tracker that mediates access to objects via a tcspc::context.
Definition context.hpp:39
Accessor for tcspc::record_abstime_range() processor data.
Definition record_abstime_range.hpp:27
auto max() -> std::optional< Abstime >
Return the maximum abstime observed, or empty if no abstime-stamped event was observed.
Definition record_abstime_range.hpp:47
auto min() -> std::optional< Abstime >
Return the minimum abstime observed, or empty if no abstime-stamped event was observed.
Definition record_abstime_range.hpp:41
#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_abstime_range(access_tracker< record_abstime_range_accessor< typename NumericTraits::abstime_type > > &&tracker, Downstream downstream)
Create a processor that records the range of abstime observed.
Definition record_abstime_range.hpp:134
libtcspc namespace.
Definition acquire.hpp:30