[MSM] test if state machine is in a given state / const get_state
Hello all, i am working with the Boost 1.45 Meta State Machine, using both orthogonal regions and submachines. Overall, i am very happy with this library. But i am looking for a nice way to check if a state machine (e.g. instance mAvail of class AvailFSM) is in a given state, for example i would like to write something like this: assert(isInState(mAvail, AvailFSM::UpstreamAvailable())); I didn't find something like "isInState" provided by the MSM library, so i came up with the following implementation: template <class FSM, class StateType> bool isInState(const FSM& p, const StateType& s) { int stateId = boost::msm::back::get_state_id<typename FSM::stt,StateType>::value; for (int i=0; i < FSM::nr_regions::value; ++i) { if(p.current_state()[i] == stateId) { return true; } } return false; } This works well for simple state machines and orthogonal regions, but not for submachines. Does any one knows a way to extend the above code to work with submachines? Lets say the state "AvailFSM::UpstreamAvailable" from above is in fact a submachine, having the state "Primary" amongst others. It would be nice to have the following working: assert(isInState(mAvail, AvailFSM::UpstreamAvailable::Primary())); Currently i am using the following workaround: assert(isInState(mAvail, AvailFSM::UpstreamAvailable())); assert(isInState(mAvail.get_state<AvailFSM::UpstreamAvailable&>(), AvailFSM::UpstreamAvailable::Primary())); I consider this solution ugly not only because of its lengthiness, but also because "get_state" isn't a const function. Unfortunately i'am not deep enough into the template magic to tell if a const implementation of "get_state" is possible. Can anyone help me out ? So, to sum up, i have two questions: 1) How to implement something like "isInState" that even works on submachines, if possible ? 2) Is a const version of "get_state" possible ? And how? best regards, jan
participants (1)
-
Jan Vogelgesang