Skip to content

Commit 4cfc667

Browse files
author
Guilhem Codron
committed
Generate mappings with mapped and generic events in one go
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.
1 parent ca3b05d commit 4cfc667

File tree

3 files changed

+50
-40
lines changed

3 files changed

+50
-40
lines changed

include/boost/sml.hpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,30 +1011,35 @@ struct get_state_mapping<sm<T>, TMappings, TUnexpected> {
10111011
};
10121012
template <class T, class TMappings, class TUnexpected>
10131013
using get_state_mapping_t = typename get_state_mapping<T, TMappings, TUnexpected>::type;
1014-
template <class>
1014+
template <class...>
10151015
transitions<aux::true_type> get_event_mapping_impl(...);
10161016
template <class T, class TMappings>
10171017
TMappings get_event_mapping_impl(event_mappings<T, TMappings> *);
1018-
template <class T, class... T1Mappings, class... T2Mappings>
1019-
unique_mappings_t<T1Mappings..., T2Mappings...> get_event_mapping_impl(event_mappings<T, aux::inherit<T1Mappings...>> *,
1020-
event_mappings<_, aux::inherit<T2Mappings...>> *);
1018+
template <class T1, class T2, class... T1Mappings, class... T2Mappings>
1019+
unique_mappings_t<T1Mappings..., T2Mappings...> get_event_mapping_impl(event_mappings<T1, aux::inherit<T1Mappings...>> *,
1020+
event_mappings<T2, aux::inherit<T2Mappings...>> *);
1021+
template <class E, class _, class TMappings>
1022+
using with_default_event_mapping_t = typename aux::conditional<
1023+
aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<_>((TMappings *)0))>::value,
1024+
decltype(get_event_mapping_impl<E>((TMappings *)0)),
1025+
typename aux::conditional<
1026+
aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<E>((TMappings *)0))>::value,
1027+
decltype(get_event_mapping_impl<_>((TMappings *)0)),
1028+
decltype(get_event_mapping_impl<E, _>((TMappings *)0, (TMappings *)0))>::type>::type;
10211029
template <class T, class TMappings>
1022-
struct get_event_mapping_impl_helper
1023-
: aux::conditional<aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<_>((TMappings *)0))>::value,
1024-
decltype(get_event_mapping_impl<T>((TMappings *)0)),
1025-
decltype(get_event_mapping_impl<T>((TMappings *)0, (TMappings *)0))>::type {};
1030+
struct get_event_mapping_impl_helper : with_default_event_mapping_t<T, _, TMappings> {};
10261031
template <class T, class TMappings>
10271032
struct get_event_mapping_impl_helper<exception<T>, TMappings> : decltype(get_event_mapping_impl<exception<T>>((TMappings *)0)) {
10281033
};
1029-
template <class T1, class T2, class TMappings>
1030-
struct get_event_mapping_impl_helper<unexpected_event<T1, T2>, TMappings>
1031-
: decltype(get_event_mapping_impl<unexpected_event<T1, T2>>((TMappings *)0)) {};
1032-
template <class T1, class T2, class TMappings>
1033-
struct get_event_mapping_impl_helper<on_entry<T1, T2>, TMappings>
1034-
: decltype(get_event_mapping_impl<on_entry<T1, T2>>((TMappings *)0)) {};
1035-
template <class T1, class T2, class TMappings>
1036-
struct get_event_mapping_impl_helper<on_exit<T1, T2>, TMappings>
1037-
: decltype(get_event_mapping_impl<on_exit<T1, T2>>((TMappings *)0)) {};
1034+
template <class E, class _, class TMappings>
1035+
struct get_event_mapping_impl_helper<unexpected_event<_, E>, TMappings>
1036+
: with_default_event_mapping_t<unexpected_event<_, E>, unexpected_event<_, _>, TMappings> {};
1037+
template <class E, class _, class TMappings>
1038+
struct get_event_mapping_impl_helper<on_entry<_, E>, TMappings>
1039+
: with_default_event_mapping_t<on_entry<_, E>, on_entry<_, _>, TMappings> {};
1040+
template <class E, class _, class TMappings>
1041+
struct get_event_mapping_impl_helper<on_exit<_, E>, TMappings>
1042+
: with_default_event_mapping_t<on_exit<_, E>, on_exit<_, _>, TMappings> {};
10381043
template <class T, class TMappings>
10391044
using get_event_mapping_t = get_event_mapping_impl_helper<T, TMappings>;
10401045
}
@@ -1427,12 +1432,12 @@ struct sm_impl : aux::conditional_t<aux::is_empty<typename TSM::sm>::value, aux:
14271432
bool process_internal_event(const TEvent &event, TDeps &deps, TSubs &subs, state_t &current_state) {
14281433
policies::log_process_event<sm_t>(aux::type<logger_t>{}, deps, event);
14291434
#if BOOST_SML_DISABLE_EXCEPTIONS
1430-
return process_event_impl<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, states_t{}, current_state)
1435+
return process_event_impl<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, states_t{},
1436+
current_state);
14311437
#else
14321438
return process_event_noexcept<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, current_state,
1433-
has_exceptions{})
1439+
has_exceptions{});
14341440
#endif
1435-
|| process_internal_generic_event(event, deps, subs, current_state);
14361441
}
14371442
template <class TMappings, class TEvent, class TDeps, class TSubs, class... TStates>
14381443
bool process_event_impl(const TEvent &event, TDeps &deps, TSubs &subs, const aux::type_list<TStates...> &states,

include/boost/sml/back/mappings.hpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,37 +135,43 @@ struct get_state_mapping<sm<T>, TMappings, TUnexpected> {
135135
template <class T, class TMappings, class TUnexpected>
136136
using get_state_mapping_t = typename get_state_mapping<T, TMappings, TUnexpected>::type;
137137

138-
template <class>
138+
template <class...>
139139
transitions<aux::true_type> get_event_mapping_impl(...);
140140

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

144-
template <class T, class... T1Mappings, class... T2Mappings>
145-
unique_mappings_t<T1Mappings..., T2Mappings...> get_event_mapping_impl(event_mappings<T, aux::inherit<T1Mappings...>> *,
146-
event_mappings<_, aux::inherit<T2Mappings...>> *);
144+
template <class T1, class T2, class... T1Mappings, class... T2Mappings>
145+
unique_mappings_t<T1Mappings..., T2Mappings...> get_event_mapping_impl(event_mappings<T1, aux::inherit<T1Mappings...>> *,
146+
event_mappings<T2, aux::inherit<T2Mappings...>> *);
147+
148+
template <class E, class _, class TMappings>
149+
using with_default_event_mapping_t = typename aux::conditional<
150+
aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<_>((TMappings *)0))>::value,
151+
decltype(get_event_mapping_impl<E>((TMappings *)0)),
152+
typename aux::conditional<
153+
aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<E>((TMappings *)0))>::value,
154+
decltype(get_event_mapping_impl<_>((TMappings *)0)),
155+
decltype(get_event_mapping_impl<E, _>((TMappings *)0, (TMappings *)0))>::type>::type;
147156

148157
template <class T, class TMappings>
149-
struct get_event_mapping_impl_helper
150-
: aux::conditional<aux::is_same<transitions<aux::true_type>, decltype(get_event_mapping_impl<_>((TMappings *)0))>::value,
151-
decltype(get_event_mapping_impl<T>((TMappings *)0)),
152-
decltype(get_event_mapping_impl<T>((TMappings *)0, (TMappings *)0))>::type {};
158+
struct get_event_mapping_impl_helper : with_default_event_mapping_t<T, _, TMappings> {};
153159

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

158-
template <class T1, class T2, class TMappings>
159-
struct get_event_mapping_impl_helper<unexpected_event<T1, T2>, TMappings>
160-
: decltype(get_event_mapping_impl<unexpected_event<T1, T2>>((TMappings *)0)) {};
164+
template <class E, class _, class TMappings>
165+
struct get_event_mapping_impl_helper<unexpected_event<_, E>, TMappings>
166+
: with_default_event_mapping_t<unexpected_event<_, E>, unexpected_event<_, _>, TMappings> {};
161167

162-
template <class T1, class T2, class TMappings>
163-
struct get_event_mapping_impl_helper<on_entry<T1, T2>, TMappings>
164-
: decltype(get_event_mapping_impl<on_entry<T1, T2>>((TMappings *)0)) {};
168+
template <class E, class _, class TMappings>
169+
struct get_event_mapping_impl_helper<on_entry<_, E>, TMappings>
170+
: with_default_event_mapping_t<on_entry<_, E>, on_entry<_, _>, TMappings> {};
165171

166-
template <class T1, class T2, class TMappings>
167-
struct get_event_mapping_impl_helper<on_exit<T1, T2>, TMappings>
168-
: decltype(get_event_mapping_impl<on_exit<T1, T2>>((TMappings *)0)) {};
172+
template <class E, class _, class TMappings>
173+
struct get_event_mapping_impl_helper<on_exit<_, E>, TMappings>
174+
: with_default_event_mapping_t<on_exit<_, E>, on_exit<_, _>, TMappings> {};
169175

170176
template <class T, class TMappings>
171177
using get_event_mapping_t = get_event_mapping_impl_helper<T, TMappings>;

include/boost/sml/back/state_machine.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,11 @@ struct sm_impl : aux::conditional_t<aux::is_empty<typename TSM::sm>::value, aux:
182182
bool process_internal_event(const TEvent &event, TDeps &deps, TSubs &subs, state_t &current_state) {
183183
policies::log_process_event<sm_t>(aux::type<logger_t>{}, deps, event);
184184
#if BOOST_SML_DISABLE_EXCEPTIONS // __pph__
185-
return process_event_impl<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, states_t{}, current_state)
185+
return process_event_impl<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, states_t{}, current_state);
186186
#else // __pph__
187187
return process_event_noexcept<get_event_mapping_t<get_mapped_t<TEvent>, mappings>>(event, deps, subs, current_state,
188-
has_exceptions{})
188+
has_exceptions{});
189189
#endif // __pph__
190-
|| process_internal_generic_event(event, deps, subs, current_state);
191190
}
192191

193192
template <class TMappings, class TEvent, class TDeps, class TSubs, class... TStates>

0 commit comments

Comments
 (0)