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>
22 requires processor<Downstream>
23class select {
24 Downstream downstream;
25
26 public:
27 explicit select(Downstream downstream)
28 : downstream(std::move(downstream)) {}
29
30 [[nodiscard]] auto introspect_node() const -> processor_info {
31 return processor_info(this, "select");
32 }
33
34 [[nodiscard]] auto introspect_graph() const -> processor_graph {
35 return downstream.introspect_graph().push_entry_point(this);
36 }
37
38 template <typename AnyEvent>
39 requires(
40 (convertible_to_type_list_member<std::remove_cvref_t<AnyEvent>,
41 EventList> != Inverted) and
42 handler_for<Downstream, std::remove_cvref_t<AnyEvent>>)
43 void handle(AnyEvent &&event) {
44 downstream.handle(std::forward<AnyEvent>(event));
45 }
46
47 template <typename AnyEvent>
48 requires(convertible_to_type_list_member<std::remove_cvref_t<AnyEvent>,
49 EventList> == Inverted)
50 void handle(AnyEvent && /* event */) {}
51
52 void flush() { downstream.flush(); }
53};
54
55} // namespace internal
56
76template <typename EventList, typename Downstream>
77auto select(Downstream downstream) {
78 return internal::select<EventList, false, Downstream>(
79 std::move(downstream));
80}
81
100template <typename Downstream> auto select_none(Downstream downstream) {
101 return internal::select<type_list<>, false, Downstream>(
102 std::move(downstream));
103}
104
124template <typename EventList, typename Downstream>
125auto select_except(Downstream downstream) {
126 return internal::select<EventList, true, Downstream>(
127 std::move(downstream));
128}
129
147template <typename Downstream> auto select_all(Downstream downstream) {
148 return internal::select<type_list<>, true, Downstream>(
149 std::move(downstream));
150}
151
152} // namespace tcspc
auto select_all(Downstream downstream)
Create a processor that passes all events.
Definition select.hpp:147
auto select(Downstream downstream)
Create a processor that passes a given set of events and discards others.
Definition select.hpp:77
auto select_none(Downstream downstream)
Create a processor that passes no events.
Definition select.hpp:100
auto select_except(Downstream downstream)
Create a processor that discards a given set of events and passes others.
Definition select.hpp:125
libtcspc namespace.
Definition acquire.hpp:30