Hi,
I want no_transition() to be called whenever no row matches, even if there
is a row that does not match only because the guard returns false. How can
I achieve this? I want to be strict about the input events. I can probably
workaround this by putting guardless rows at the top whose action is to
call no_transition(), but I'm hoping to find a cleaner solution.
If I get this behavior in msm, then the following code should output "no
transition..." as its last line. Right now, with boost 1.51, it doesn't. It
just prints "entering State1".
Josh
#include <iostream>
#include
#include
#include
using namespace std;
namespace mpl = boost::mpl;
namespace msm = boost::msm;
using namespace msm::front;
struct Event {
Event(bool data) : data(data) { }
bool data;
};
struct state_ : public msm::front::state_machine_def {
struct MyGuard {
template
bool operator()(EVT const& e, FSM&, SourceState&, TargetState&) {
return e.data;
}
};
struct State1 : public msm::front::state<> {
// optional entry/exit methods
template
void on_entry(Event const&, FSM& f) { std::cout << "entering:
State1" << std::endl; }
template
void on_exit(Event const&,FSM& ) { std::cout << "leaving: State1"
<< std::endl; }
};
struct State2 : public msm::front::state<> {
// optional entry/exit methods
template
void on_entry(Event const&, FSM& f) { std::cout << "entering:
State2" << std::endl; }
template
void on_exit(Event const&,FSM& ) { std::cout << "leaving: State2"
<< std::endl; }
};
typedef State1 initial_state;
struct transition_table : mpl::vector<
Row< State1, Event , State2, none, MyGuard >
> {};
template
void no_transition(Event const& e, FSM&, int state) {
std::cout << "no transition from state " << state
<< " on event " << typeid(e).name() << std::endl;
}
};
typedef msm::back::state_machine State;
int main() {
State state;
state.start();
state.process_event(Event(false));
return 0;
}