Boost logo

Boost Users :

Subject: [Boost-users] [statechart] history not saved
From: Ilya Orlov (iorlov_at_[hidden])
Date: 2012-11-06 10:34:23


I have following code:

// from A11 and A12 and back
struct Ev1 : sc::event < Ev1 >{};
struct Ev2 : sc::event < Ev2 >{};

// from A to B and back
struct Ev3 : sc::event < Ev3 >{};
struct Ev4 : sc::event < Ev4 >{};

// from A1 to A2 and back
struct Ev5 : sc::event < Ev5 >{};
struct Ev6 : sc::event < Ev6 >{};

struct StateA;
struct StateA1;
struct StateA11;
struct StateA12;
struct StateA2;
struct StateA21;
struct StateA22;

struct StateB;

struct Machine : sc::state_machine < Machine, StateA > {};

struct StateA : sc::simple_state < StateA, Machine, mpl::list <
sc::deep_history < StateA1 > >, sc::has_deep_history >
{
typedef sc::transition < Ev3, StateB > reactions;
};

struct StateA1 : sc::simple_state < StateA1, StateA, mpl::list <
sc::deep_history < StateA11 > >, sc::has_deep_history >
{
typedef sc::transition < Ev5, StateA2 > reactions;
};

struct StateA11 : sc::simple_state < StateA11, StateA1 >
{
typedef sc::transition < Ev1, StateA12 > reactions;
};

struct StateA12 : sc::simple_state < StateA12, StateA1 >
{
typedef sc::transition < Ev2, StateA11 > reactions;
};

struct StateA2 : sc::simple_state < StateA2, StateA, mpl::list <
sc::deep_history < StateA21 > >, sc::has_deep_history >
{
typedef sc::transition < Ev6, StateA1 > reactions;
};

struct StateA21 : sc::simple_state < StateA21, StateA2 > {};

struct StateA22 : sc::simple_state < StateA22, StateA2 > {};

struct StateB : sc::simple_state < StateB, Machine >
{
typedef sc::custom_reaction < Ev4 > reactions;

sc::result react(const Ev4&) { std::cout << "react" << std::endl; return
transit < sc::deep_history < StateA11 > >(); }
};

I am sending events like this:

Machine m;
m.initiate();

std::cout << "Ev5" << std::endl;
m.process_event(Ev5());

std::cout << "Ev3" << std::endl;
m.process_event(Ev3());

std::cout << "Ev4" << std::endl;
m.process_event(Ev4());

After Ev5 machine goes to A2 -> A21 state.
After Ev3 machine leaves state A with history and goes to state B.
After Ev4 machine leaves state B and should go back to A2 -> A21 but
actually goes to A -> A1 -> A11 - default states.
How I can fix it?

Thanks,
Ilya



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