Boost logo

Boost Users :

From: Andreas Huber (ahd6974-spamgroupstrap_at_[hidden])
Date: 2005-05-03 08:11:19


Hi Marcin

> Is there a way that an event triggered on entry to a state can
> access the event that caused that state to be entered?

No, not currently. I was thinking about providing something like that but
postponed it because I've never had the need. Neither have I revceived any
other requests in that direction.

> I'm thinking of adding a line to the process_event method in a
> wrapper class derived from state_machine that stores the event object
> received as a way of doing this.

That works only as long as you don't post any events. I order to catch those
events as well you'd need to do the same for state_machine::post_event, which
is not part of the documented interface. I don't currently see a proper way
how users can implement this themselves (save of changing the library code),
if they want to be able to post events.
I think the best way is to add the following member function to the
simple_state interface:

const event_base * current_event() const

If the state entry was triggered by an event, current_event() returns a
pointer to the event that triggered the transition. Otherwise, it returns 0
(e.g. the state was entered as a result of calling state_machine::initiate().
We could also name this triggering_event()...

Thoughts?

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