Skip to content

Commit

Permalink
Generate mappings with mapped and generic events in one go
Browse files Browse the repository at this point in the history
Generate mappings with mapped and generic events for on_entry, on_exit
and unexpected events.
Remove the dual pass processing done in state_machine.hpp since the
improved get_event_mapping_impl_helper directly generate the good mapping.
  • Loading branch information
Guilhem Codron committed Aug 3, 2020
1 parent ca3b05d commit 4cfc667
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 40 deletions.
45 changes: 25 additions & 20 deletions include/boost/sml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,30 +1011,35 @@ struct get_state_mapping<sm<T>, TMappings, TUnexpected> {
};
template <class T, class TMappings, class TUnexpected>
using get_state_mapping_t = typename get_state_mapping<T, TMappings, TUnexpected>::type;
template <class>
template <class...>
transitions<aux::true_type> get_event_mapping_impl(...);
template <class T, class TMappings>
TMappings get_event_mapping_impl(event_mappings<T, TMappings> *);
template <class T, class... T1Mappings, class... T2Mappings>
unique_mappings_t<T1Mappings..., T2Mappings...> get_event_mapping_impl(event_mappings<T, aux::inherit<T1Mappings...>> *,
event_mappings<_, aux::inherit<T2Mappings...>> *);
template <class T1, class T2, class... T1Mappings, class... T2Mappings>
unique_mappings_t<T1Mappings..., T2Mappings...> get_event_mapping_impl(event_mappings<T1, aux::inherit<T1Mappings...>> *,
event_mappings<T2, aux::inherit<T2Mappings...>> *);
template <class E, class _, class TMappings>
using with_default_event_mapping_t = typename aux::conditional<
aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<_>((TMappings *)0))>::value,
decltype(get_event_mapping_impl<E>((TMappings *)0)),
typename aux::conditional<
aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<E>((TMappings *)0))>::value,
decltype(get_event_mapping_impl<_>((TMappings *)0)),
decltype(get_event_mapping_impl<E, _>((TMappings *)0, (TMappings *)0))>::type>::type;
template <class T, class TMappings>
struct get_event_mapping_impl_helper
: aux::conditional<aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<_>((TMappings *)0))>::value,
decltype(get_event_mapping_impl<T>((TMappings *)0)),
decltype(get_event_mapping_impl<T>((TMappings *)0, (TMappings *)0))>::type {};
struct get_event_mapping_impl_helper : with_default_event_mapping_t<T, _, TMappings> {};
template <class T, class TMappings>
struct get_event_mapping_impl_helper<exception<T>, TMappings> : decltype(get_event_mapping_impl<exception<T>>((TMappings *)0)) {
};
template <class T1, class T2, class TMappings>
struct get_event_mapping_impl_helper<unexpected_event<T1, T2>, TMappings>
: decltype(get_event_mapping_impl<unexpected_event<T1, T2>>((TMappings *)0)) {};
template <class T1, class T2, class TMappings>
struct get_event_mapping_impl_helper<on_entry<T1, T2>, TMappings>
: decltype(get_event_mapping_impl<on_entry<T1, T2>>((TMappings *)0)) {};
template <class T1, class T2, class TMappings>
struct get_event_mapping_impl_helper<on_exit<T1, T2>, TMappings>
: decltype(get_event_mapping_impl<on_exit<T1, T2>>((TMappings *)0)) {};
template <class E, class _, class TMappings>
struct get_event_mapping_impl_helper<unexpected_event<_, E>, TMappings>
: with_default_event_mapping_t<unexpected_event<_, E>, unexpected_event<_, _>, TMappings> {};
template <class E, class _, class TMappings>
struct get_event_mapping_impl_helper<on_entry<_, E>, TMappings>
: with_default_event_mapping_t<on_entry<_, E>, on_entry<_, _>, TMappings> {};
template <class E, class _, class TMappings>
struct get_event_mapping_impl_helper<on_exit<_, E>, TMappings>
: with_default_event_mapping_t<on_exit<_, E>, on_exit<_, _>, TMappings> {};
template <class T, class TMappings>
using get_event_mapping_t = get_event_mapping_impl_helper<T, TMappings>;
}
Expand Down Expand Up @@ -1427,12 +1432,12 @@ struct sm_impl : aux::conditional_t<aux::is_empty<typename TSM::sm>::value, aux:
bool process_internal_event(const TEvent &event, TDeps &deps, TSubs &subs, state_t &current_state) {
policies::log_process_event<sm_t>(aux::type<logger_t>{}, deps, event);
#if BOOST_SML_DISABLE_EXCEPTIONS
return process_event_impl<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, states_t{}, current_state)
return process_event_impl<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, states_t{},
current_state);
#else
return process_event_noexcept<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, current_state,
has_exceptions{})
has_exceptions{});
#endif
|| process_internal_generic_event(event, deps, subs, current_state);
}
template <class TMappings, class TEvent, class TDeps, class TSubs, class... TStates>
bool process_event_impl(const TEvent &event, TDeps &deps, TSubs &subs, const aux::type_list<TStates...> &states,
Expand Down
40 changes: 23 additions & 17 deletions include/boost/sml/back/mappings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,37 +135,43 @@ struct get_state_mapping<sm<T>, TMappings, TUnexpected> {
template <class T, class TMappings, class TUnexpected>
using get_state_mapping_t = typename get_state_mapping<T, TMappings, TUnexpected>::type;

template <class>
template <class...>
transitions<aux::true_type> get_event_mapping_impl(...);

template <class T, class TMappings>
TMappings get_event_mapping_impl(event_mappings<T, TMappings> *);

template <class T, class... T1Mappings, class... T2Mappings>
unique_mappings_t<T1Mappings..., T2Mappings...> get_event_mapping_impl(event_mappings<T, aux::inherit<T1Mappings...>> *,
event_mappings<_, aux::inherit<T2Mappings...>> *);
template <class T1, class T2, class... T1Mappings, class... T2Mappings>
unique_mappings_t<T1Mappings..., T2Mappings...> get_event_mapping_impl(event_mappings<T1, aux::inherit<T1Mappings...>> *,
event_mappings<T2, aux::inherit<T2Mappings...>> *);

template <class E, class _, class TMappings>
using with_default_event_mapping_t = typename aux::conditional<
aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<_>((TMappings *)0))>::value,
decltype(get_event_mapping_impl<E>((TMappings *)0)),
typename aux::conditional<
aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<E>((TMappings *)0))>::value,
decltype(get_event_mapping_impl<_>((TMappings *)0)),
decltype(get_event_mapping_impl<E, _>((TMappings *)0, (TMappings *)0))>::type>::type;

template <class T, class TMappings>
struct get_event_mapping_impl_helper
: aux::conditional<aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<_>((TMappings *)0))>::value,
decltype(get_event_mapping_impl<T>((TMappings *)0)),
decltype(get_event_mapping_impl<T>((TMappings *)0, (TMappings *)0))>::type {};
struct get_event_mapping_impl_helper : with_default_event_mapping_t<T, _, TMappings> {};

template <class T, class TMappings>
struct get_event_mapping_impl_helper<exception<T>, TMappings> : decltype(get_event_mapping_impl<exception<T>>((TMappings *)0)) {
};

template <class T1, class T2, class TMappings>
struct get_event_mapping_impl_helper<unexpected_event<T1, T2>, TMappings>
: decltype(get_event_mapping_impl<unexpected_event<T1, T2>>((TMappings *)0)) {};
template <class E, class _, class TMappings>
struct get_event_mapping_impl_helper<unexpected_event<_, E>, TMappings>
: with_default_event_mapping_t<unexpected_event<_, E>, unexpected_event<_, _>, TMappings> {};

template <class T1, class T2, class TMappings>
struct get_event_mapping_impl_helper<on_entry<T1, T2>, TMappings>
: decltype(get_event_mapping_impl<on_entry<T1, T2>>((TMappings *)0)) {};
template <class E, class _, class TMappings>
struct get_event_mapping_impl_helper<on_entry<_, E>, TMappings>
: with_default_event_mapping_t<on_entry<_, E>, on_entry<_, _>, TMappings> {};

template <class T1, class T2, class TMappings>
struct get_event_mapping_impl_helper<on_exit<T1, T2>, TMappings>
: decltype(get_event_mapping_impl<on_exit<T1, T2>>((TMappings *)0)) {};
template <class E, class _, class TMappings>
struct get_event_mapping_impl_helper<on_exit<_, E>, TMappings>
: with_default_event_mapping_t<on_exit<_, E>, on_exit<_, _>, TMappings> {};

template <class T, class TMappings>
using get_event_mapping_t = get_event_mapping_impl_helper<T, TMappings>;
Expand Down
5 changes: 2 additions & 3 deletions include/boost/sml/back/state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,11 @@ struct sm_impl : aux::conditional_t<aux::is_empty<typename TSM::sm>::value, aux:
bool process_internal_event(const TEvent &event, TDeps &deps, TSubs &subs, state_t &current_state) {
policies::log_process_event<sm_t>(aux::type<logger_t>{}, deps, event);
#if BOOST_SML_DISABLE_EXCEPTIONS // __pph__
return process_event_impl<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, states_t{}, current_state)
return process_event_impl<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, states_t{}, current_state);
#else // __pph__
return process_event_noexcept<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, current_state,
has_exceptions{})
has_exceptions{});
#endif // __pph__
|| process_internal_generic_event(event, deps, subs, current_state);
}

template <class TMappings, class TEvent, class TDeps, class TSubs, class... TStates>
Expand Down

0 comments on commit 4cfc667

Please sign in to comment.