[statechart] Passing parameters from event to State Local Storage

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

Christophe Bourez
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
{ 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
{ public: StTarget(std::size_t val) : val(value) {} private: std::size_t value; };
I have a patch using boost.fusion to allow this. It works this way:
class StSource : public sc::simple_state
Thanks, Christophe
Regards, -- Felipe Magno de Almeida

Hi Felipe
I have a patch using boost.fusion to allow this. It works this way:
class StSource : public sc::simple_state
{ public: typedef sc::custom_reaction<EvTest> reactions; sc::result react(const EvTest &event) { // How to pass event.getValue() to the target state ? transit<StTarget>(event.value); // pass arguments to target // state constructor } }; Does Boost have interest in this?
Yes, definitely! Thanks, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.

Hi Christophe
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.
The "problem" with passing event data to a constructor of a destination state is hinted at here (item 3): http://www.boost.org/doc/libs/1_42_0/libs/statechart/doc/future_and_history.... Nevertheless, the triggering_event() function is available in >=1.42 (but only documented in >=1.43). Also, I'll definitely look at Felipe's patch. HTH, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.

Hello,
The "problem" with passing event data to a constructor of a destination state is hinted at here (item 3): http://www.boost.org/doc/libs/1_42_0/libs/statechart/doc/future_and_history.... Nevertheless, the triggering_event() function is available in >=1.42 (but only documented in >=1.43). Also, I'll definitely look at Felipe's patch.
Was there any progress with this patch, i.e. is it possible in the current version to pass arbitrary arguments to a state constructor? If not, what's the recommended workaround? To share data through the outermost state? Thanks! -- View this message in context: http://old.nabble.com/-statechart--Passing-parameters-from-event-to-State-Lo... Sent from the Boost - Users mailing list archive at Nabble.com.

Was there any progress with this patch, i.e. is it possible in the current version to pass arbitrary arguments to a state constructor?
Unfortunately not, I have not heard anything from Felipe. I personally don't see a good way how this can be implemented, so I'm really interested in his approach.
If not, what's the recommended workaround? To share data through the outermost state?
Either that, or: 1) Repost the event in the transition and have an in_state_reaction (triggered by the same event) store whatever you need (typesafe), or 2) use triggering_event() http://www.boost.org/doc/libs/1_43_0/libs/statechart/doc/reference.html#trig... (not typesafe) HTH, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.

Andreas Huber-3 wrote
1) Repost the event in the transition and have an in_state_reaction (triggered by the same event) store whatever you need (typesafe), or
Please can you provide an example. -- View this message in context: http://boost.2283326.n4.nabble.com/statechart-Passing-parameters-from-event-... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (5)
-
Andreas Huber
-
Christophe Bourez
-
Felipe Magno de Almeida
-
Igor R.
-
ksl