Boost logo

Boost Users :

Subject: [Boost-users] [msm] access to root fsm
From: Alexander Mingalev (infest21h_at_[hidden])
Date: 2013-07-12 12:29:36


I have main fsm with two sub-levels.
The problem is, the sub-fsms need data which is held in root fsm, like:

struct SomeAction
{
                 template <typename EVT, typename FSM, typename
SourceState, typename TargetState>
                 void operator()(EVT&, FSM& fsm, SourceState&,
TargetState&) const
                 {
                                 // ...
                 }
};

Instance of fsm here might be root fsm as well as sub-fsm.
I see two possible solutions:

1. use sm_ptr policy and store parent pointer in each sub-fsm
In this case access might look like this:

fsm.parent_->data; (access from 1-level fsm)
fsm.parent_->parent_->data; (access from 2-level fsm)

doesn't look so nice, besides, documentation states that using sm_ptr is
deprecated.

2. recursively traverse all states, detect fsm's and store root pointer

typedef RootFSM::stt stt;
typedef boost::msm::back::generate_state_set<stt>::type all_states;

boost::mpl::for_each<all_states, boost::msm::wrap<mpl::placeholders::_1> >
     (find_sub_fsm<stt>());

     template <typename stt>
     struct find_sub_fsm
     {
         template <class StateType>
         void operator()(boost::msm::wrap<StateType>& state) const
         {
             // ???
             // state.root_ = &g_root;
             // do the recurs
         }
     };

How to detect that StateType is sub-fsm?

3. Maybe, there is a easier way to communicate between sub-fsm's?




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