Boost logo

Boost Users :

Subject: Re: [Boost-users] [MSM] Is there an elegant way to get the outermostFSM?
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2011-08-30 17:17:26


> Hi,
>
> I am having a statemachine with a submachine. In the internal submachine I
> need to check if there is a flag active in the outer statemachine.
> Currently I solve this with a const pointer to the outermost FSM passed to
> the submachine's constructor:
> backEnd.set_states(msm::back::states_ <<
> StOk(msm::back::states_ <<
> StSlave(&backEnd)));
> StSlave is the internal submachine in which I need to check whether a flag
> in StOk is active or not.
>
> Then I check the flag activity status e.g in a guard of StSlave like this:
> struct GrdBladeUp {
> template<class EVT, class FSM, class SourceState, class TargetState>
> bool operator()(EVT const& event, FSM& fsm, SourceState&, TargetState&) {
> if(fsm.getOutermostFSM()->template is_flag_active<FlagBladeUp>()) {
> return true;
> }
> return false;
> }
> };
>
> Is there an easier way to get somehow the parent fsm or the outermost fsm
> of a submachine?
>
> Thanks,
> Gabor

Hi Gabor,

this feature has been requested a few times and I have it on my list, but I
didn't implement it (yet).
Your solution is ok, though it creates a cyclic dependency, which is not so
nice.
Alternatively you could pass the submachine a boost::function, which breaks
the cycle but gets not fun if you start having too many.

This is clearly something which msm will have at some point.

Regards,
Christophe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net