Skip to content

Commit

Permalink
Add special case for initial on_entry events that have no associated …
Browse files Browse the repository at this point in the history
…action. This ensures that composite states have in turn their on_entry actions executed.

See subsequent_anonymous_transitions_composite_without_action (now passes) and subsequent_anonymous_transitions_composite_with_action (always passed).
  • Loading branch information
Rijom authored and krzysztof-jusiak committed Jun 28, 2022
1 parent a4dcc73 commit e051103
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
18 changes: 16 additions & 2 deletions include/boost/sml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,10 +1424,24 @@ struct sm_impl : aux::conditional_t<aux::is_empty<typename TSM::sm>::value, aux:
}
template <class TEvent, class TDeps, class TSubs, class... Ts,
__BOOST_SML_REQUIRES(!aux::is_base_of<get_generic_t<TEvent>, events_ids_t>::value &&
!aux::is_base_of<get_mapped_t<TEvent>, events_ids_t>::value)>
bool process_internal_events(const TEvent &, TDeps &, TSubs &, Ts &&...) {
!aux::is_base_of<get_mapped_t<TEvent>, events_ids_t>::value &&
!aux::is_same<get_event_t<TEvent>, initial>::value)>
bool process_internal_events(const TEvent&, TDeps &, TSubs &, Ts &&...) {
return false;
}
template <class TEvent, class TDeps, class TSubs, class... Ts,
__BOOST_SML_REQUIRES(!aux::is_base_of<get_generic_t<TEvent>, events_ids_t>::value &&
!aux::is_base_of<get_mapped_t<TEvent>, events_ids_t>::value &&
aux::is_same<get_event_t<TEvent>, initial>::value)>
bool process_internal_events(const TEvent &event, TDeps &deps, TSubs &subs) {
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_generic_t<TEvent>, mappings>>(event, deps, subs, states_t{},
aux::make_index_sequence<regions>{});
#else
return process_event_except_imp<get_event_mapping_t<get_generic_t<TEvent>, mappings>>(event, deps, subs, has_exceptions{});
#endif
}
template <class TEvent, class TDeps, class TSubs,
__BOOST_SML_REQUIRES(aux::is_base_of<get_generic_t<TEvent>, events_ids_t>::value &&
!aux::is_base_of<get_mapped_t<TEvent>, events_ids_t>::value)>
Expand Down
22 changes: 20 additions & 2 deletions include/boost/sml/back/state_machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,29 @@ struct sm_impl : aux::conditional_t<aux::is_empty<typename TSM::sm>::value, aux:

template <class TEvent, class TDeps, class TSubs, class... Ts,
__BOOST_SML_REQUIRES(!aux::is_base_of<get_generic_t<TEvent>, events_ids_t>::value &&
!aux::is_base_of<get_mapped_t<TEvent>, events_ids_t>::value)>
bool process_internal_events(const TEvent &, TDeps &, TSubs &, Ts &&...) {
!aux::is_base_of<get_mapped_t<TEvent>, events_ids_t>::value &&
!aux::is_same<get_event_t<TEvent>, initial>::value)>
bool process_internal_events(const TEvent&, TDeps &, TSubs &, Ts &&...) {
return false;
}

// This version is used by initial events that are not associated with any actions.
// Without this, composite classes will their initial events not have executed.
template <class TEvent, class TDeps, class TSubs, class... Ts,
__BOOST_SML_REQUIRES(!aux::is_base_of<get_generic_t<TEvent>, events_ids_t>::value &&
!aux::is_base_of<get_mapped_t<TEvent>, events_ids_t>::value &&
aux::is_same<get_event_t<TEvent>, initial>::value)>
bool process_internal_events(const TEvent &event, TDeps &deps, TSubs &subs) {
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_generic_t<TEvent>, mappings>>(event, deps, subs, states_t{},
aux::make_index_sequence<regions>{});
#else // __pph__
return process_event_except_imp<get_event_mapping_t<get_generic_t<TEvent>, mappings>>(event, deps, subs, has_exceptions{});
#endif // __pph__
}


template <class TEvent, class TDeps, class TSubs,
__BOOST_SML_REQUIRES(aux::is_base_of<get_generic_t<TEvent>, events_ids_t>::value &&
!aux::is_base_of<get_mapped_t<TEvent>, events_ids_t>::value)>
Expand Down
28 changes: 14 additions & 14 deletions test/ft/transitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ test subsequent_anonymous_transitions_composite_with_action = []{
V calls{};
//
// sub_sm
// +--------------------------------+
// | |
// | +---+ +---+ evExit |
// *+---> *+---> A +-------> B +----> X +----> X
// | +---+ +---+ |
// | |
// +--------------------------------+
// +----------------------------------+
// | |
// | +----+ +----+ evExit |
// *+---> *+---> s1 +-------> s2 +----> X +----> X
// | +----+ +----+ |
// | |
// +----------------------------------+
//

struct sub_sm {
Expand Down Expand Up @@ -219,13 +219,13 @@ test subsequent_anonymous_transitions_composite_without_action = []{

//
// sub_sm
// +--------------------------------+
// | |
// | +---+ +---+ evExit |
// *+---> *+---> A +-------> B +----> X +----> X
// | +---+ +---+ |
// | |
// +--------------------------------+
// +----------------------------------+
// | |
// | +----+ +----+ evExit |
// *+---> *+---> s1 +-------> s2 +----> X +----> X
// | +----+ +----+ |
// | |
// +----------------------------------+
//

struct sub_sm {
Expand Down

0 comments on commit e051103

Please sign in to comment.