11#include "introspect.hpp"
12#include "processor.hpp"
13#include "type_list.hpp"
25template <
typename EventList,
typename Exception,
typename Downstream>
27 static_assert(type_list_like<EventList>);
28 static_assert(processor<Downstream>);
30 Downstream downstream;
33 std::string message_prefix;
35 template <
typename Event>
36 [[noreturn]] LIBTCSPC_NOINLINE
void handle_stop(Event
const &event) {
37 if constexpr (std::is_same_v<Exception, end_of_processing>)
39 std::ostringstream stream;
40 if (not message_prefix.empty())
41 stream << message_prefix <<
": ";
43 throw Exception(stream.str());
47 explicit stop(std::string prefix, Downstream downstream)
48 : downstream(std::move(downstream)),
49 message_prefix(std::move(prefix)) {}
51 [[nodiscard]]
auto introspect_node() const -> processor_info {
52 return processor_info(
this,
"stop");
55 [[nodiscard]]
auto introspect_graph() const -> processor_graph {
56 return downstream.introspect_graph().push_entry_point(
this);
59 template <
typename Event>
60 requires convertible_to_type_list_member<std::remove_cvref_t<Event>,
62 [[noreturn]]
void handle(Event &&event) {
66 template <
typename Event>
67 requires(not convertible_to_type_list_member<
68 std::remove_cvref_t<Event>, EventList> and
69 handler_for<Downstream, std::remove_cvref_t<Event>>)
70 void handle(Event &&event) {
71 downstream.handle(std::forward<Event>(event));
74 void flush() { downstream.flush(); }
105template <
typename EventList,
typename Exception = std::runtime_error,
108 static_assert(not std::is_same_v<Exception, end_of_processing>);
109 return internal::stop<EventList, Exception, Downstream>(
110 std::move(message_prefix), std::move(downstream));
137template <
typename EventList,
typename Downstream>
138auto stop(std::string message_prefix, Downstream downstream) {
139 return internal::stop<EventList, end_of_processing, Downstream>(
140 std::move(message_prefix), std::move(downstream));
auto stop(std::string message_prefix, Downstream downstream)
Create a processor that ends the stream when a given event type is received.
Definition stop.hpp:138
auto stop_with_error(std::string message_prefix, Downstream downstream)
Create a processor that ends the stream with an error when a given event type is received.
Definition stop.hpp:107
libtcspc namespace.
Definition acquire.hpp:29