-
Notifications
You must be signed in to change notification settings - Fork 201
Open
Description
How can I use a simple way to say: transition always to a specific state with a specific event, without having to specify this event for each state of the state machine ?
In my example, I am trying to transition to the "aborted"_s state from everywhere, if an event onAbort is sent.
I could rearrange the state machine to be hierarchic, but I want to avoid that.
So I have tried the following:
#include <boost/sml.hpp>
#include <cassert>
#include <iostream>
namespace sml = boost::sml;
namespace {
struct e1 {};
struct e2 {};
struct onAbort {};
struct states {
auto operator()() const noexcept {
using namespace sml;
return make_transition_table(
state<_> + event<onAbort> = "aborted"_s
, "aborted"_s + sml::on_entry<_> / [] { std::cout << "aborted on entry" << std::endl; }
, *"s1"_s + event<e1> = "s2"_s
, "s1"_s + sml::on_exit<_> / [] { std::cout << "s1 on exit" << std::endl; }
, "s2"_s + sml::on_entry<_> / [] { std::cout << "s2 on entry" << std::endl; }
, "s2"_s + sml::on_exit<_> / [] { std::cout << "s2 on exit" << std::endl; }
, "s2"_s + event<e2> = X
);
}
};
} // namespace
int main() {
sml::sm<states> sm;
sm.process_event(e1{});
sm.process_event(onAbort{});
sm.process_event(e2{});
}My expectation:
s1 on exit
s2 on entry
s2 on exit
aborted on entry
But the outcome is:
s1 on exit
s2 on entry
s2 on exit
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels