Boost logo

Boost Users :

Subject: [Boost-users] [statechart] Passing parameters from event to State Local Storage
From: Christophe Bourez (boost_at_[hidden])
Date: 2010-05-06 03:56:00


I need to maintain a parameter into the state local storage. This
parameter is initially contained in the event that causes the transition to
the target state. I give hereafter a small illustrative example.

typename sc = boost::statechart;

class EvTest : public sc::event<EvTest>
{
public:
    EvTest(std::size_t val) : value(val) {}
    std::size_t getValue() const { return this->value; }
private:
    std::size_t value;
};

class MyStateMachine;
class StSource;
class StTarget;

class StSource : public sc::simple_state<StSource, MyStateMachine>
{
public:
    typedef sc::custom_reaction<EvTest> reactions;

    sc::result react(const EvTest &event)
    {
        // How to pass event.getValue() to the target state ?
        transit<StTarget>();
    }
};

class StTarget : public sc::simple_state<StTarget, MyStateMachine>
{
public:
    StTarget(std::size_t val) : val(value) {}
private:
    std::size_t value;
};

Thanks,
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