12#include "introspect.hpp"
13#include "processor.hpp"
14#include "type_list.hpp"
26template <
typename EventList,
typename Exception,
typename Downstream>
27 requires processor<Downstream>
29 static_assert(type_list_like<EventList>);
31 Downstream downstream;
34 std::string message_prefix;
36 template <
typename Event>
37 [[noreturn]] LIBTCSPC_NOINLINE
void handle_stop(Event
const &event) {
38 if constexpr (std::is_same_v<Exception, end_of_processing>)
40 std::ostringstream stream;
41 if constexpr (internal::ostreamable<Event>) {
42 if (not message_prefix.empty())
43 stream << message_prefix <<
": ";
46 stream << message_prefix;
48 throw Exception(stream.str());
52 explicit stop(std::string prefix, Downstream downstream)
53 : downstream(std::move(downstream)),
54 message_prefix(std::move(prefix)) {}
56 [[nodiscard]]
auto introspect_node() const -> processor_info {
57 return processor_info(
this,
"stop");
60 [[nodiscard]]
auto introspect_graph() const -> processor_graph {
61 return downstream.introspect_graph().push_entry_point(
this);
64 template <
typename Event>
65 requires convertible_to_type_list_member<std::remove_cvref_t<Event>,
67 [[noreturn]]
void handle(Event &&event) {
71 template <
typename Event>
72 requires(not convertible_to_type_list_member<
73 std::remove_cvref_t<Event>, EventList> and
74 handler_for<Downstream, std::remove_cvref_t<Event>>)
75 void handle(Event &&event) {
76 downstream.handle(std::forward<Event>(event));
79 void flush() { downstream.flush(); }
114template <
typename EventList,
typename Exception = std::runtime_error,
117 static_assert(not std::is_same_v<Exception, end_of_processing>);
118 return internal::stop<EventList, Exception, Downstream>(
119 std::move(message_prefix), std::move(downstream));
150template <
typename EventList,
typename Downstream>
151auto stop(std::string message_prefix, Downstream downstream) {
152 return internal::stop<EventList, end_of_processing, Downstream>(
153 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:151
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:116
libtcspc namespace.
Definition acquire.hpp:30