I want to share something among states, for example, a mode variable. I save it to the state machine. However, I can not even access its value.
struct InitState;
struct MyFsm : boost::statechart::state_machine<MyFsm, InitState> {
uint8_t mode;
MyFsm() : mode(0) {
std::cout << "mode = " << mode << std::endl;
}
};
The above ctor never prints the value.
struct InitState : boost::statechart::simple_state<InitState, MyFsm > {
typedef boost::mpl::list<
boost::statechart::custom_reaction<Event1>
> reactions;
boost::statechart::result react(const Event1& e) {
context< MyFsm >().mode = 2; // This does NOT work!
}
};
The assignment also fails above. Does anyone know how to get it working?
Or maybe what is the best way to share variables among states?
Or if boost::statechart is too bad to use? Boost's doc is so useless on explaining its APIs.