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
68class null_sink {
69 public:
71 [[nodiscard]] auto introspect_node() const -> processor_info {
72 return processor_info(this, "null_sink");
73 }
74
76 [[nodiscard]] auto introspect_graph() const -> processor_graph {
77 return processor_graph().push_entry_point(this);
78 }
79
81 template <typename Event> void handle(Event const & /* event */) {}
82
84 void flush() {}
85};
86
87namespace internal {
88
89template <typename Downstream> class null_source {
90 bool flushed = false;
91 Downstream downstream;
92
93 public:
94 explicit null_source(Downstream downstream)
95 : downstream(std::move(downstream)) {}
96
97 [[nodiscard]] auto introspect_node() const -> processor_info {
98 return processor_info(this, "null_source");
99 }
100
101 [[nodiscard]] auto introspect_graph() const -> processor_graph {
102 return downstream.introspect_graph().push_entry_point(this);
103 }
104
105 void flush() {
106 if (flushed) {
107 throw std::logic_error(
108 "null_source may not be flushed a second time");
109 }
110 flushed = true;
111 downstream.flush();
112 }
113};
114
115} // namespace internal
116
131template <typename Downstream> auto null_source(Downstream downstream) {
132 return internal::null_source<Downstream>(std::move(downstream));
133}
134
135} // namespace tcspc
Processor that sinks any event and the end-of-stream and does nothing.
Definition core.hpp:68
void handle(Event const &)
Implements processor requirement.
Definition core.hpp:81
void flush()
Implements processor requirement.
Definition core.hpp:84
auto introspect_graph() const -> processor_graph
Implements processor requirement.
Definition core.hpp:76
auto introspect_node() const -> processor_info
Implements processor requirement.
Definition core.hpp:71
Value type representing a directed acyclic graph of processors.
Definition introspect.hpp:198
auto push_entry_point(Processor const *processor) -> processor_graph &
Add a processor node to this graph, upstream of the current entry point (if any), making it the new e...
Definition introspect.hpp:229
Value type representing metadata of a processor.
Definition introspect.hpp:58
auto null_source(Downstream downstream)
Create a processor that sources an empty stream.
Definition core.hpp:131
libtcspc namespace.
Definition acquire.hpp:29
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