Boost logo

Boost Users :

Subject: Re: [Boost-users] [StateChart] How to pass arguments to a state constructor when doing state transition?
From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2011-03-22 14:21:07


Hi

> I have a state like this, which has two parameters in it's constructor
> except the ctx.
> I want to know how to pass these two arguments to the constructor, when
> do
> state transition?
> I have tried this:
> transit< RepeatedPlayingState , 1, 2>();
>
> But it cause compiling error? How to do this? I want to pass something to
> a
> new entered state.

Short answer: By design you can't. The reasons are as follows:

- In general, a transition must be able to enter multiple states at once
(for the case when there are nested and/or orthogonal states). If you were
able to pass arguments to transit like you ask then to what state
constructors are the arguments forwarded? To just the first entered, all of
them, or just a few select ones?
- Moreover, the same state can be the target of multiple different
transitions. If just one of those transitions wanted to pass arguments, then
all other incoming transitions would be forced to pass the same arguments
too.

So, for the general case passing arguments to transit would become
unworkable very quickly. However, you can use
simple_state::triggering_event() to get the triggering event inside the
state constructor. Note: The states that do so must derive from state
instead of simple_state.

HTH & Regards,

-- 
Andreas Huber
When replying by private email, please remove the words spam and trap
from the address shown in the header. 

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