I want a sub state-machine to be the "initial_state" of a state-machine. The following should be a broken down version of the code.
struct E {
};
struct A : public boost::msm::front::state<> {
template <class TEvent, class TStateMachine>
void on_entry(TEvent const& event, TStateMachine& stateMachine) {
}
template <class TEvent, class TStateMachine>
void on_exit(TEvent const& event, TStateMachine& stateMachine) {
}
};
struct B: public boost::msm::front::state<> {
template <class TStateMachine>
void on_entry(E const& event, TStateMachine& stateMachine) {
}
template <class TStateMachine>
void on_exit(E const& event, TStateMachine& stateMachine) {
}
};
struct SubMachineDefinition : public boost::msm::front::state_machine_def<SubMachineDefinition> {
typedef boost::msm::front::state_machine_def<SubMachineDefinition> Base;
typedef A initial_state;
struct transition_table : boost::mpl::vector<
typename Base::template _row<A, E, B>
> {};
// Added via suggestion of sehe
template <class IE, class SM> void on_entry(IE const&, SM&) { std::cout << __PRETTY_FUNCTION__ << "\n"; }
// Added via suggestion of sehe
template <class IE, class SM> void on_exit (IE const&, SM&) { std::cout << __PRETTY_FUNCTION__ << "\n"; }
};
struct SuperMachineDefinition : public boost::msm::front::state_machine_def<SuperMachineDefinition > {
typedef SubMachineDefinition initial_state;
struct transition_table : boost::mpl::vector<> {};
};
int main() {
boost::msm::back::state_machine<SuperMachineDefinition> states;
states.start();
states.process_event(E()); // This crashes
}
While this compiles fine, when I call process_event
, it crashes. Is this even possible or is there a way of debugging this?
EDIT 1:
I now set a breakpoint on A::on_entry
. When start
gets called, it does not break, so my obvious question - why is the sub state-machine not used!?
EDIT 2:
Interestingly, when I replace SubMachineDefinition
with boost::msm::back::state_machine<SubMachineDefinition>
(as initial_state
) I get a compilation error, stating it tries to call B::on_entry
with InitEvent
instead of E
. I am by now very confused.
EDIT 3:
Actually I did copy the wrong overloads for A
. I also did apply sehe's SubMachineDefinition::on_entry
and SubMachineDefinition::on_exit
definitions. Still, I get the compilation error, that it tries to call B::on_entry
with InitEvent
.