libtcspc C++ API
Streaming TCSPC and time tag data processing
Loading...
Searching...
No Matches
core.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 "introspect.hpp"
10
11#include <ostream>
12#include <stdexcept>
13#include <string>
14#include <utility>
15
16namespace tcspc {
17
33 std::string message;
34
36 friend auto operator==(warning_event const &lhs,
37 warning_event const &rhs) noexcept
38 -> bool = default;
39
41 friend auto operator<<(std::ostream &stream, warning_event const &event)
42 -> std::ostream & {
43 return stream << event.message;
44 }
45};
46
54struct never_event {
55 never_event() = delete;
56};
57
58namespace internal {
59
60class sink_all {
61 public:
62 [[nodiscard]] auto introspect_node() const -> processor_info {
63 return processor_info(this, "sink_all");
64 }
65
66 [[nodiscard]] auto introspect_graph() const -> processor_graph {
67 return processor_graph().push_entry_point(this);
68 }
69
70 template <typename Event> void handle(Event const & /* event */) {}
71
72 void flush() {}
73};
74
75template <typename Downstream> class source_nothing {
76 bool flushed = false;
77 Downstream downstream;
78
79 public:
80 explicit source_nothing(Downstream downstream)
81 : downstream(std::move(downstream)) {}
82
83 [[nodiscard]] auto introspect_node() const -> processor_info {
84 return processor_info(this, "source_nothing");
85 }
86
87 [[nodiscard]] auto introspect_graph() const -> processor_graph {
88 return downstream.introspect_graph().push_entry_point(this);
89 }
90
91 void flush() {
92 if (flushed) {
93 throw std::logic_error(
94 "source_nothing may not be flushed a second time");
95 }
96 flushed = true;
97 downstream.flush();
98 }
99};
100
101} // namespace internal
102
115inline auto sink_all() { return internal::sink_all(); }
116
131template <typename Downstream> auto source_nothing(Downstream downstream) {
132 return internal::source_nothing<Downstream>(std::move(downstream));
133}
134
135} // namespace tcspc
Value type representing metadata of a processor.
Definition introspect.hpp:59
auto sink_all()
Create a processor that sinks any event and the end-of-stream and does nothing.
Definition core.hpp:115
auto source_nothing(Downstream downstream)
Create a processor that sources an empty stream.
Definition core.hpp:131
libtcspc namespace.
Definition acquire.hpp:30
An event type indicating a warning.
Definition core.hpp:31
friend auto operator==(warning_event const &lhs, warning_event const &rhs) noexcept -> bool=default
Equality comparison operator.
friend auto operator<<(std::ostream &stream, warning_event const &event) -> std::ostream &
Stream insertion operator.
Definition core.hpp:41
std::string message
A human-readable message describing the warning.
Definition core.hpp:33