12#ifndef MAKI_MACHINE_CONF_HPP
13#define MAKI_MACHINE_CONF_HPP
15#include "event_set.hpp"
18#include "detail/machine_conf_fwd.hpp"
19#include "detail/type.hpp"
20#include "detail/event_action.hpp"
21#include "detail/signature_macros.hpp"
22#include "detail/impl.hpp"
23#include "detail/tuple.hpp"
30#ifdef MAKI_DETAIL_DOXYGEN
31#define MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE machine_conf<IMPLEMENTATION_DETAIL>
33#define MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE auto
44 using context_type =
typename Impl::context_type;
46 constexpr machine_conf() =
default;
48 machine_conf(
const machine_conf&) =
delete;
50 machine_conf(machine_conf&&) =
delete;
52 ~machine_conf() =
default;
54 machine_conf& operator=(
const machine_conf&) =
delete;
56 machine_conf& operator=(machine_conf&&) =
delete;
58#define MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN \
59 [[maybe_unused]] const auto MAKI_DETAIL_ARG_auto_start = impl_.auto_start; \
60 [[maybe_unused]] const auto MAKI_DETAIL_ARG_context_type = detail::type<typename Impl::context_type>; \
61 [[maybe_unused]] const auto MAKI_DETAIL_ARG_context_sig = impl_.context_sig; \
62 [[maybe_unused]] const auto MAKI_DETAIL_ARG_pre_processing_hooks = impl_.pre_processing_hooks; \
63 [[maybe_unused]] const auto MAKI_DETAIL_ARG_post_external_transition_hook = impl_.post_external_transition_hook; \
64 [[maybe_unused]] const auto MAKI_DETAIL_ARG_pre_external_transition_hook = impl_.pre_external_transition_hook; \
65 [[maybe_unused]] const auto MAKI_DETAIL_ARG_exception_handler = impl_.exception_handler; \
66 [[maybe_unused]] const auto MAKI_DETAIL_ARG_post_processing_hooks = impl_.post_processing_hooks; \
67 [[maybe_unused]] const auto MAKI_DETAIL_ARG_process_event_now_enabled = impl_.process_event_now_enabled; \
68 [[maybe_unused]] const auto MAKI_DETAIL_ARG_run_to_completion = impl_.run_to_completion; \
69 [[maybe_unused]] const auto MAKI_DETAIL_ARG_small_event_max_align = impl_.small_event_max_align; \
70 [[maybe_unused]] const auto MAKI_DETAIL_ARG_small_event_max_size = impl_.small_event_max_size; \
71 [[maybe_unused]] const auto MAKI_DETAIL_ARG_transition_tables = impl_.transition_tables;
73#define MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END \
76 detail::machine_conf_option_set \
78 typename std::decay_t<decltype(MAKI_DETAIL_ARG_context_type)>::type, \
79 std::decay_t<decltype(MAKI_DETAIL_ARG_pre_processing_hooks)>, \
80 std::decay_t<decltype(MAKI_DETAIL_ARG_exception_handler)>, \
81 std::decay_t<decltype(MAKI_DETAIL_ARG_pre_external_transition_hook)>, \
82 std::decay_t<decltype(MAKI_DETAIL_ARG_post_external_transition_hook)>, \
83 std::decay_t<decltype(MAKI_DETAIL_ARG_post_processing_hooks)>, \
84 std::decay_t<decltype(MAKI_DETAIL_ARG_transition_tables)> \
88 MAKI_DETAIL_ARG_auto_start, \
89 MAKI_DETAIL_ARG_context_sig, \
90 MAKI_DETAIL_ARG_pre_processing_hooks, \
91 MAKI_DETAIL_ARG_post_external_transition_hook, \
92 MAKI_DETAIL_ARG_pre_external_transition_hook, \
93 MAKI_DETAIL_ARG_exception_handler, \
94 MAKI_DETAIL_ARG_post_processing_hooks, \
95 MAKI_DETAIL_ARG_process_event_now_enabled, \
96 MAKI_DETAIL_ARG_run_to_completion, \
97 MAKI_DETAIL_ARG_small_event_max_align, \
98 MAKI_DETAIL_ARG_small_event_max_size, \
99 MAKI_DETAIL_ARG_transition_tables \
102#define MAKI_DETAIL_X(signature) \
106 template<class Context> \
107 [[nodiscard]] constexpr MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE context_##signature() const \
109 return context<Context, machine_context_signature::signature>(); \
111 MAKI_DETAIL_MACHINE_CONTEXT_CONSTRUCTOR_SIGNATURES
114#define MAKI_DETAIL_X(signature) \
120 template<class EventSetPredicate, class Action> \
121 [[nodiscard]] constexpr MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE pre_processing_hook_##signature(const event_set<EventSetPredicate>& evt_set, const Action& action) const \
123 return pre_processing_hook<action_signature::signature>(evt_set, action); \
131 template<class Event, class Action> \
132 [[nodiscard]] constexpr MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE pre_processing_hook_##signature(const Action& action) const \
134 return pre_processing_hook_##signature(event_set{event<Event>}, action); \
136 MAKI_DETAIL_ACTION_SIGNATURES
153 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
154#define MAKI_DETAIL_ARG_post_external_transition_hook hook
155 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
156#undef MAKI_DETAIL_ARG_post_external_transition_hook
163 [[nodiscard]]
constexpr MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE
auto_start(
const bool value)
const
165 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
166#define MAKI_DETAIL_ARG_auto_start value
167 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
168#undef MAKI_DETAIL_ARG_auto_start
185 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
186#define MAKI_DETAIL_ARG_pre_external_transition_hook hook
187 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
188#undef MAKI_DETAIL_ARG_pre_external_transition_hook
200 [[nodiscard]]
constexpr MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE
run_to_completion(
const bool value)
const
202 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
203#define MAKI_DETAIL_ARG_run_to_completion value
204 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
205#undef MAKI_DETAIL_ARG_run_to_completion
214 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
215#define MAKI_DETAIL_ARG_process_event_now_enabled value
216 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
217#undef MAKI_DETAIL_ARG_process_event_now_enabled
240 template<
class Callable>
241 [[nodiscard]]
constexpr MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE
catch_mx(
const Callable& callable)
const
243 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
244#define MAKI_DETAIL_ARG_exception_handler callable
245 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
246#undef MAKI_DETAIL_ARG_exception_handler
281 template<
class EventSetPredicate,
class Action>
284 const auto new_post_processing_hooks = tuple_append
286 impl_.post_processing_hooks,
287 detail::make_event_action<action_signature::me>(evt_set,
action)
290 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
291#define MAKI_DETAIL_ARG_post_processing_hooks new_post_processing_hooks
292 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
293#undef MAKI_DETAIL_ARG_post_processing_hooks
328 template<
class Event,
class Action>
339 [[nodiscard]]
constexpr MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE
small_event_max_align(
const std::size_t value)
const
341 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
342#define MAKI_DETAIL_ARG_small_event_max_align value
343 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
344#undef MAKI_DETAIL_ARG_small_event_max_align
352 [[nodiscard]]
constexpr MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE
small_event_max_size(
const std::size_t value)
const
354 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
355#define MAKI_DETAIL_ARG_small_event_max_size value
356 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
357#undef MAKI_DETAIL_ARG_small_event_max_size
366 [[nodiscard]]
constexpr MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE
thread_safe(
const bool )
const
375 template<
class... TransitionTables>
376 [[nodiscard]]
constexpr MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE
transition_tables(
const TransitionTables&... tables)
const
378 const auto tpl = detail::tuple<TransitionTables...>{detail::distributed_construct, tables...};
379 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
380#define MAKI_DETAIL_ARG_transition_tables tpl
381 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
382#undef MAKI_DETAIL_ARG_transition_tables
386 using impl_type = Impl;
388 template<
class Impl2>
389 friend class machine_conf;
391 template<
class... Args>
392 constexpr machine_conf(Args&&... args):
393 impl_{std::forward<Args>(args)...}
397 template<
class Context2, auto ContextSig>
398 [[nodiscard]]
constexpr auto context()
const
400 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
401#define MAKI_DETAIL_ARG_context_type detail::type<Context2>
402#define MAKI_DETAIL_ARG_context_sig ContextSig
403 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
404#undef MAKI_DETAIL_ARG_context_type
405#undef MAKI_DETAIL_ARG_context_sig
408 template<action_signature Sig,
class EventSetPredicate,
class Hook>
411 const auto new_pre_processing_hooks = tuple_append
413 impl_.pre_processing_hooks,
414 detail::make_event_action<Sig>(evt_set, hook)
417 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
418#define MAKI_DETAIL_ARG_pre_processing_hooks new_pre_processing_hooks
419 MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
420#undef MAKI_DETAIL_ARG_pre_processing_hooks
423#undef MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_END
424#undef MAKI_DETAIL_MAKE_MACHINE_CONF_COPY_BEGIN
426 MAKI_DETAIL_FRIENDLY_IMPL
429#undef MAKI_DETAIL_MACHINE_CONF_RETURN_TYPE
434 struct is_machine_conf
436 static constexpr auto value =
false;
439 template<
class... Options>
440 struct is_machine_conf<machine_conf<Options...>>
442 static constexpr auto value =
true;
446 constexpr auto is_machine_conf_v = is_machine_conf<T>::value;
Represents an event type set.
Definition event_set.hpp:37
event_set(event_t< Event >) -> event_set< IMPLEMENTATION_DETAIL >
Class template argument deduction guide for maki::event_set.
constexpr machine_conf< IMPLEMENTATION_DETAIL > process_event_now_enabled(const bool value) const
Specifies whether the unsafe function maki::machine::process_event_now() can be called.
Definition machine_conf.hpp:202
constexpr machine_conf< IMPLEMENTATION_DETAIL > transition_tables(const TransitionTables &... tables) const
Specifies the list of transition tables. One region per transition table is created.
Definition machine_conf.hpp:366
constexpr machine_conf< IMPLEMENTATION_DETAIL > run_to_completion(const bool value) const
Specifies whether run-to-completion is enabled.
Definition machine_conf.hpp:190
constexpr machine_conf< IMPLEMENTATION_DETAIL > catch_mx(const Callable &callable) const
Sets up a try/catch(...) block at the top-level of every non-const member function of maki::machine a...
Definition machine_conf.hpp:231
constexpr machine_conf< IMPLEMENTATION_DETAIL > auto_start(const bool value) const
Specifies whether the constructor of maki::machine must call maki::machine::start().
Definition machine_conf.hpp:153
constexpr machine_conf< IMPLEMENTATION_DETAIL > post_external_transition_hook_crset(const Hook &hook) const
Specifies a hook to be called after any external transition.
Definition machine_conf.hpp:141
constexpr machine_conf< IMPLEMENTATION_DETAIL > small_event_max_size(const std::size_t value) const
Specifies the maximum object size for the run-to-completion event queue to enable small object optimi...
Definition machine_conf.hpp:342
constexpr machine_conf< IMPLEMENTATION_DETAIL > small_event_max_align(const std::size_t value) const
Specifies the maximum object alignment requirement for the run-to-completion event queue to enable sm...
Definition machine_conf.hpp:329
constexpr machine_conf< IMPLEMENTATION_DETAIL > post_processing_hook_mep(const event_set< EventSetPredicate > &evt_set, const Action &action) const
Adds a hook to be called whenever maki::machine is done processing an event whose type is part of evt...
Definition machine_conf.hpp:272
constexpr machine_conf< IMPLEMENTATION_DETAIL > pre_external_transition_hook_crset(const Hook &hook) const
Specifies a hook to be called before any external transition.
Definition machine_conf.hpp:173
constexpr machine_conf< IMPLEMENTATION_DETAIL > thread_safe(const bool) const
Currently doesn't do anything. Once thread safety is implemented, will specify whether thread safety ...
Definition machine_conf.hpp:356
Represents an action to be given to maki::transition_table.
Definition action.hpp:60