libtcspc C++ API
Streaming TCSPC and time tag data processing
Loading...
Searching...
No Matches
select.hpp
1/*
2 * This file is part of libtcspc
3 * Copyright 2019-2026 Board of Regents of the University of Wisconsin System
4 * SPDX-License-Identifier: MIT
5 */
6
7#pragma once
8
9#include "common.hpp"
10#include "introspect.hpp"
11#include "processor.hpp"
12#include "type_list.hpp"
13
14#include <type_traits>
15#include <utility>
16
17namespace tcspc {
18
19namespace internal {
20
21template <typename EventList, bool Inverted, typename Downstream>
22class select {
23 static_assert(processor<Downstream>);
24
25 Downstream downstream;
26
27 public:
28 explicit select(Downstream downstream)
29 : downstream(std::move(downstream)) {}
30
31 [[nodiscard]] auto introspect_node() const -> processor_info {
32 return processor_info(this, "select");
33 }
34
35 [[nodiscard]] auto introspect_graph() const -> processor_graph {
36 return downstream.introspect_graph().push_entry_point(this);
37 }
38
39 template <typename AnyEvent>
40 requires(
41 (convertible_to_type_list_member<std::remove_cvref_t<AnyEvent>,
42 EventList> != Inverted) and
43 handler_for<Downstream, std::remove_cvref_t<AnyEvent>>)
44 void handle(AnyEvent &&event) {
45 downstream.handle(std::forward<AnyEvent>(event));
46 }
47
48 template <typename AnyEvent>
49 requires(convertible_to_type_list_member<std::remove_cvref_t<AnyEvent>,
50 EventList> == Inverted)
51 void handle(AnyEvent && /* event */) {}
52
53 void flush() { downstream.flush(); }
54};
55
56} // namespace internal
57
77template <typename EventList, typename Downstream>
78auto select(Downstream downstream) {
79 return internal::select<EventList, false, Downstream>(
80 std::move(downstream));
81}
82
101template <typename Downstream> auto select_none(Downstream downstream) {
102 return internal::select<type_list<>, false, Downstream>(
103 std::move(downstream));
104}
105
125template <typename EventList, typename Downstream>
126auto select_not(Downstream downstream) {
127 return internal::select<EventList, true, Downstream>(
128 std::move(downstream));
129}
130
148template <typename Downstream> auto select_all(Downstream downstream) {
149 return internal::select<type_list<>, true, Downstream>(
150 std::move(downstream));
151}
152
153} // namespace tcspc
auto select_all(Downstream downstream)
Create a processor that passes all events.
Definition select.hpp:148
auto select(Downstream downstream)
Create a processor that passes a given set of events and discards others.
Definition select.hpp:78
auto select_none(Downstream downstream)
Create a processor that passes no events.
Definition select.hpp:101
auto select_not(Downstream downstream)
Create a processor that discards a given set of events and passes others.
Definition select.hpp:126
libtcspc namespace.
Definition acquire.hpp:29