11#include "introspect.hpp"
12#include "processor.hpp"
13#include "type_list.hpp"
24template <
typename EventList>
class abstract_processor;
26template <>
class abstract_processor<type_list<>> {
28 abstract_processor() =
default;
29 abstract_processor(abstract_processor
const &) =
delete;
30 auto operator=(abstract_processor
const &) =
delete;
31 abstract_processor(abstract_processor &&) =
delete;
32 auto operator=(abstract_processor &&) =
delete;
33 virtual ~abstract_processor() =
default;
34 [[nodiscard]]
virtual auto introspect_node() const -> processor_info = 0;
35 [[nodiscard]] virtual auto introspect_graph() const -> processor_graph = 0;
36 virtual
void flush() = 0;
39template <typename Event0>
40class abstract_processor<type_list<Event0>>
41 : public abstract_processor<type_list<>> {
43 virtual void handle(Event0
const &) = 0;
44 virtual void handle(Event0 &&) = 0;
47template <
typename Event0,
typename... Events>
48class abstract_processor<type_list<Event0, Events...>>
49 :
public abstract_processor<type_list<Events...>> {
50 using base_type = abstract_processor<type_list<Events...>>;
53 using base_type::handle;
54 virtual void handle(Event0
const &) = 0;
55 virtual void handle(Event0 &&) = 0;
58template <
typename Interface,
typename Proc,
typename EventList>
59class virtual_processor_impl;
61template <
typename Interface,
typename Proc>
62class virtual_processor_impl<Interface, Proc, type_list<>> :
public Interface {
68 explicit virtual_processor_impl(Proc proc) : proc(std::move(proc)) {}
70 template <
typename... Args>
71 explicit virtual_processor_impl(Args &&...args)
72 : proc(std::forward<Args>(args)...) {}
74 [[nodiscard]]
auto introspect_node() const -> processor_info final {
75 return processor_info(
this,
"virtual_processor_impl");
78 [[nodiscard]]
auto introspect_graph() const -> processor_graph final {
79 if constexpr (introspectable<Proc>)
80 return proc.introspect_graph().push_entry_point(
this);
82 return processor_graph().push_entry_point(
this);
85 void flush() final { proc.flush(); }
88template <
typename Interface,
typename Proc,
typename Event0,
90class virtual_processor_impl<Interface, Proc, type_list<Event0, Events...>>
91 :
public virtual_processor_impl<Interface, Proc, type_list<Events...>> {
93 virtual_processor_impl<Interface, Proc, type_list<Events...>>;
96 using base_type::proc;
99 using base_type::base_type;
101 using base_type::handle;
102 void handle(Event0
const &event)
final { proc.handle(event); }
103 void handle(Event0 &&event)
final { proc.handle(std::move(event)); }
106template <
typename Proc,
typename EventList>
107using virtual_processor =
108 virtual_processor_impl<abstract_processor<EventList>, Proc, EventList>;
128 using abstract_processor = internal::abstract_processor<event_list>;
130 template <
typename Proc>
131 using virtual_processor = internal::virtual_processor<Proc, event_list>;
133 std::unique_ptr<abstract_processor> proc;
142 : proc(std::make_unique<virtual_processor<internal::
sink_all>>()) {}
151 template <
typename Downstream>
152 requires(not std::same_as<std::remove_cvref_t<Downstream>,
157 : proc(std::make_unique<virtual_processor<Downstream>>(
158 std::move(downstream))) {}
171 template <
typename Event>
175 proc->handle(std::forward<Event>(event));
Value type representing a directed acyclic graph of processors.
Definition introspect.hpp:220
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:252
Value type representing metadata of a processor.
Definition introspect.hpp:59
Processor that type-erases the downstream processor.
Definition type_erased_processor.hpp:126
auto introspect_graph() const -> processor_graph
Implements processor requirement.
Definition type_erased_processor.hpp:166
void handle(Event &&event)
Implements processor requirement.
Definition type_erased_processor.hpp:174
auto introspect_node() const -> processor_info
Implements processor requirement.
Definition type_erased_processor.hpp:161
void flush()
Implements processor requirement.
Definition type_erased_processor.hpp:179
type_erased_processor(Downstream downstream)
Construct with the given downstream processor.
Definition type_erased_processor.hpp:156
type_erased_processor()
Construct with a stub downstream processor.
Definition type_erased_processor.hpp:141
Concept that is satisfied when a type is convertible to at least one of the members of a type list.
Definition type_list.hpp:222
constexpr bool is_processor_of_list_v
Trait variable to check whether a processor handles a list of event types and flush.
Definition processor.hpp:223
auto sink_all()
Create a processor that sinks any event and the end-of-stream and does nothing.
Definition core.hpp:115
unique_type_list< TypeList >::type unique_type_list_t
Helper type for tcspc::unique_type_list.
Definition type_list.hpp:335
libtcspc namespace.
Definition acquire.hpp:30