12#ifndef MAKI_MACHINE_REF_HPP
13#define MAKI_MACHINE_REF_HPP
15#include "machine_ref_conf.hpp"
17#include "detail/tlu/apply.hpp"
18#include "detail/tlu/contains.hpp"
26 template<
class... Events>
27 class machine_ref_event_impl;
29 template<
class Event,
class... Events>
30 class machine_ref_event_impl<Event, Events...>: machine_ref_event_impl<Events...>
33 template<const auto& MachineConf>
34 machine_ref_event_impl(machine<MachineConf>& mach):
35 machine_ref_event_impl<Events...>{mach},
38 [](
void*
const vpsm,
const Event& evt)
40 using machine_t = machine<MachineConf>;
41 const auto psm =
reinterpret_cast<machine_t*
>(vpsm);
42 psm->process_event(evt);
48 using machine_ref_event_impl<Events...>::process_event;
50 void process_event(
const Event& evt)
const
52 (*pprocess_event_)(get_vpsm(), evt);
56 using machine_ref_event_impl<Events...>::get_vpsm;
59 void(*pprocess_event_)(
void*,
const Event&) =
nullptr;
63 class machine_ref_event_impl<>
66 template<const auto& MachineConf>
67 machine_ref_event_impl(machine<MachineConf>& mach):
72 void process_event()
const
77 [[nodiscard]]
void* get_vpsm()
const
83 void* vpsm_ =
nullptr;
92template<const auto& Conf>
96 template<const auto& MachineConf>
102 machine_ref(
const machine_ref&)
noexcept =
default;
103 machine_ref(machine_ref&&)
noexcept =
default;
104 machine_ref& operator=(
const machine_ref&)
noexcept =
default;
105 machine_ref& operator=(machine_ref&&)
noexcept =
default;
106 ~machine_ref() =
default;
108 template<
class Event>
109 void process_event(
const Event& evt)
const
113 detail::tlu::contains_v
118 "Given event type must be part of the type list given to `events()`"
120 impl_.process_event(evt);
124 using event_type_list =
typename std::decay_t<
decltype(Conf)>::event_type_list;
126 using event_impl_type = detail::tlu::apply_t
129 detail::machine_ref_event_impl
132 event_impl_type impl_;
135template<
class... Events>
145template<
class... Events>
machine_ref< machine_ref_e_conf< Events... > > machine_ref_e
A convenient alias for machine_ref that only takes a list of event types.
Definition machine_ref.hpp:146
The state machine implementation template.
Definition machine.hpp:78
The configuration for maki::machine_ref
Definition machine_ref_conf.hpp:29
constexpr auto events() const
Sets the event types that can be passed to maki::machine_ref::process_event().
Definition machine_ref_conf.hpp:47