Boost logo

Boost Users :

Subject: [Boost-users] How to get current state from state machine?
From: jusva2010 (justinjose12002_at_[hidden])
Date: 2011-05-03 22:05:37


Hi All,

How can I get the current state of the state machine?

Currently i am getting in this way.. i would like to know if there any
better way

statemachine
---------------
struct StateMachine:sc::state_machine<StateMachine, Initial>
{

   void setState(string s){
     state = s;
   }
   string getState()
   {
     return state;
   }
private:
   string state;
}

//event

struct dummyEvent:sc::event<dummyEvent>
{

}

//state

struct Initial:sc::simple_state&lt;Initial, StateMachine&gt;
{

 typedef mpl::list&lt;sc::custom_reactions&lt;dummyEvent&gt;> reactions;
  sc::result react(const dummyEvent&);
}

In react function of the 'Initial' state

sc::result Initial::react(const dummyEvent&)
{
  context <StateMachine>().setState("Initial");
}

In my main

main()
{
  StateMachine machine;
  machine.initiate()
  cout << "Current State "<< machine.getState() << endl; // return me the
current state
}

Thanks in adavance
justin

-----
justin

--
View this message in context: http://boost.2283326.n4.nabble.com/How-to-get-current-state-from-state-machine-tp3494238p3494238.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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