12#ifndef MAKI_TRANSITION_TABLE_HPP
13#define MAKI_TRANSITION_TABLE_HPP
17#include "event_set.hpp"
19#include "state_set.hpp"
20#include "state_mold.hpp"
25#include "detail/tlu/left_fold.hpp"
26#include "detail/type_set.hpp"
27#include "detail/friendly_impl.hpp"
28#include "detail/tuple.hpp"
33#ifdef MAKI_DETAIL_DOXYGEN
53template<
class Impl = IMPLEMENTATION_DETAIL>
56template<
class Impl = detail::tuple<>>
64 class SourceStateMold,
65 class TargetStateMold,
74 using event_type = Event;
76 SourceStateMold source_state_mold;
77 TargetStateMold target_state_mold;
79 action<ActionSignature, ActionCallable> act;
80 guard<GuardSignature, GuardCallable> grd;
83 static constexpr bool can_process_completion_event()
85 return is_null_v<Event>;
91 class SourceStateMold,
92 class TargetStateMold,
104 action<ActionSignature, ActionCallable>,
105 guard<GuardSignature, GuardCallable>
117 template<
class TransitionEvent>
118 struct transition_event_event_type_set;
120 template<
class Event>
121 struct transition_event_event_type_set<event_t<Event>>
123 using type = type_set_item<Event>;
126 template<
class EventSetImpl>
127 struct transition_event_event_type_set<
event_set<EventSetImpl>>
129 using type = EventSetImpl;
133 struct transition_event_event_type_set<
null_t>
135 using type = empty_type_set_t;
138 template<
class TransitionEvent>
139 using transition_event_event_type_set_t =
typename transition_event_event_type_set<TransitionEvent>::type;
141 template<
class Transition>
142 using transition_event_type_set_t = transition_event_event_type_set_t<typename Transition::event_type>;
144 template<
class... Transitions>
145 constexpr auto make_transition_table(
const tuple<Transitions...>& transitions)
147 return transition_table<tuple<Transitions...>>{transitions};
151 constexpr decltype(
auto) store_state_mold(T&& obj)
153 return std::forward<T>(obj);
157 constexpr auto store_state_mold(
ini_t )
159 return &detail::state_molds::null;
163 constexpr auto store_state_mold(
fin_t )
165 return &detail::state_molds::fin;
169 template<
class OptionSet>
170 constexpr auto store_state_mold(
const state_mold<OptionSet>& mold)
221 class ActionOrNull =
null_t,
222 class GuardOrNull =
null_t
224 constexpr auto operator()
226 const Source& source_state_mold,
227 const Target& target_state_mold,
228 const Event& evt = null,
229 const ActionOrNull&
action = null,
230 const GuardOrNull&
guard = null
234 if constexpr(Impl::size == 0)
238 detail::is_ini_v<Source>,
239 "Source (1st argument) of first transition must be `maki::ini`. (Note: Composite state regions without initial pseudostate are not implemented yet.)"
246 detail::is_state_mold_v<Source> || detail::is_state_set_v<Source>,
247 "Source (1st argument) must be an instance of `maki::state_mold` or an instance of `maki::state_set`"
252 if constexpr(detail::is_ini_v<Source>)
256 detail::is_state_mold_v<Target>,
257 "Target (2nd argument) of transition from initial pseudostate must be an instance of `maki::state_mold`."
264 detail::is_state_mold_v<Target> || detail::is_null_v<Target> || detail::is_fin_v<Target>,
265 "Target (2nd argument) must be an instance of `maki::state_mold`, `maki::null` or `maki::fin`."
270 if constexpr(detail::is_ini_v<Source>)
274 detail::is_null_v<Event>,
275 "Event (3rd argument) of transition from initial pseudostate must be `maki::null`"
282 detail::is_event_v<Event> || detail::is_event_set_v<Event> || detail::is_null_v<Event>,
283 "Event (3rd argument) must be an instance of `maki::event_t`, an instance of `maki::event_set`, or `maki::null`"
290 detail::is_action_v<ActionOrNull> || detail::is_null_v<ActionOrNull>,
291 "Action (4th argument) must be an instance of `maki::action` or `maki::null`."
295 if constexpr(detail::is_ini_v<Source>)
299 detail::is_null_v<GuardOrNull>,
300 "Guard (5th argument) of transition from initial pseudostate must be `maki::null`."
307 detail::is_guard_v<GuardOrNull> || detail::is_null_v<GuardOrNull>,
308 "Guard (5th argument) must be an instance of `maki::guard` or `maki::null`."
312 return detail::make_transition_table
318 detail::store_state_mold(source_state_mold),
319 detail::store_state_mold(target_state_mold),
321 detail::to_action(action),
322 detail::to_guard(guard)
329 MAKI_DETAIL_FRIENDLY_IMPL
331 using impl_type = Impl;
333#ifndef MAKI_DETAIL_DOXYGEN
334 template<
class... Transitions>
335 friend constexpr auto detail::make_transition_table(
const detail::tuple<Transitions...>&);
348 template<
class EventTypeSet,
class Transition>
349 using transition_table_event_type_set_fold_operation_t = type_set_union_t
352 transition_event_type_set_t<Transition>
355 template<
class TransitionTable>
356 using transition_table_event_type_set_t = tlu::left_fold_t
358 impl_of_t<TransitionTable>,
359 transition_table_event_type_set_fold_operation_t,
event_set(event_t< Event >) -> event_set< IMPLEMENTATION_DETAIL >
Class template argument deduction guide for maki::event_set.
Represents a transition table.
Definition transition_table.hpp:178
constexpr transition_table(const transition_table &)=default
Copy constructor.
transition_table & operator=(transition_table &&)=delete
Deleted move operator.
transition_table(transition_table &&)=delete
Deleted move constructor.
transition_table & operator=(const transition_table &)=delete
Deleted assignment operator.
constexpr transition_table()=default
Default constructor.
IMPLEMENTATION_DETAIL null_t
The type of maki::null.
Definition null.hpp:26
IMPLEMENTATION_DETAIL ini_t
The type of maki::ini.
Definition ini.hpp:19
guard_signature
The set of arguments taken by a guard callable.
Definition guard.hpp:26
action_signature
The set of arguments taken by an action callable.
Definition action.hpp:26
IMPLEMENTATION_DETAIL fin_t
The type of maki::fin.
Definition fin.hpp:19
Represents an action to be given to maki::transition_table.
Definition action.hpp:60
Represents a guard to be given to maki::transition_table. Use the builder functions (maki::guard_v() ...
Definition guard.hpp:86