> I'd like to be able to communicate the data from an event to the state(s)
> that get constructed as a result of a transition.
That's a pretty common request, see item 3 on the to-do list:
http://www.boost.org/libs/statechart/doc/future_and_history.html#ToDoList
As stated in the todo-item, passing event data to the state constructor is
not as straight-forward as it might seem. You are bound to lose event
type-safety. However, if you have a compelling use-case, I'm willing to
finally implement this feature.
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 mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Ok. How do you determine whether you'll query the data source? Do you need
to wait for more events or can this be determined with the token only?
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,
Ok, since this has been requested a couple of times now, I'll add this
feature to the next release.
Regards,