Boost logo

Boost Users :

Subject: Re: [Boost-users] [statechart] Pass event data to state constructor?
From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2009-09-03 04:56:34


> This can be determined with the token, perhaps supplemented with queries
> to
> other objects.

Ok, in this case one easy option would be to make the query within the
transition action. Contrary to the entry and exit actions, a transition
action does have type-safe access to the triggering event. If other objects
need to be queried then these could be accessed from the transition action
as well. The data that is gathered in the query could be put into a new
event which is passed to simple_state::post_event. The destination state
would then define an in_state_reaction triggered by the new event.

Or, if you want to make the query after entering the destination state:
Repost the event carrying the token in the transition action and define an
in-state reaction triggered by the same event. The in-state reaction would
then execute the query and store the data in the destination state.

> I should have mentioned that in our system this is a general pattern, with
> different token and data types that need to be responded to differently in
> different states - this is why it seems that the most reliable and general
> solution would be to pass the event data into the new state. It's true
> that
> this removes type safety, since I now have to dynamic_cast or equivalent
> in
> order to get to the actual data, but I'm not terribly worried about this
> (or, maybe more accurately, I don't see a better alternative).

See above, an alternative is the "transition action posts event that
triggers an in-state reaction"-pattern (what a name :-)). With this pattern
type-safety is upheld, at the cost of needing to process an additional
event, which is probably negligible is your case. Another (IMO minor)
problem is that you might need move some of the things that you planned to
to in the destination state entry action to the in-state reaction.

HTH,

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