Boost logo

Boost Users :

Subject: [Boost-users] [MSM] What's the easiest way to share data between states in a Boost.MSM state machine?
From: B. Tommy Jensen (bjorntommyjensen_at_[hidden])
Date: 2012-04-25 08:56:12


As the subject indicates, I'm trying to find the best way to share data
between states in a MSM state machine.

My first attempt has been to let each sub-machine and state inherit from a
common base class, e.g.:

  struct MyStateMachine_ : public
msm::front::state_machine_def<MyStateMachine_,CommonBaseClass>

My idea is to add a reference to some shared data in the base class, making
it easy to access the shared data from any state. The shared data reference
must be passed to the base class.

Questions:

1. Is it possible to pass constructor parameters to the common base class'
constructor? I have tried different options without success, it seems that
the default constructor with no arguments is the only option.

2. If 1. is not possible, what is the best way to initialize the shared
property correctly? For example an easy method to iterate over all defined
states? (not only the active ones). I have tried to iterate over all states
with get_state_by_id, but this method does not enter sub-machines' states.

3. In general, what is the preferred way of implementing shared data
between state classes in Boost.MSM? It would have been natural to store the
data in the root state, but I can't see that there is an easy way to get
access to the root FSM. (only the "nearest parent" FSM in the hierarchy is
passed to the various event handler methods).

Regards,
Tommy



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