[statechart] Events not consumed when using derived states?
Dear statecharters, I would like to request help with a problem building a statemachine from states that I derive from simple_state. Here is minimal code that defines two states StateA and StateB and an event cycling between these two: #include <boost/statechart/state_machine.hpp> #include <boost/statechart/simple_state.hpp> #include <boost/statechart/event.hpp> #include <boost/statechart/transition.hpp> namespace sc = boost::statechart; using namespace std; class StateA; struct StateMachine : sc::state_machine< StateMachine, StateA > { void unconsumed_event( const sc::event_base & evt ) { cout << "unconsumed!" << endl; } }; class Event : public sc::event< Event > {}; struct StateA : sc::simple_state< StateA, StateMachine > { typedef sc::transition< Event, StateB > reactions; }; struct StateB : sc::simple_state< StateB, StateMachine > { typedef sc::transition< Event, StateA > reactions; }; ----------------- This works fine as expected with process_event( Event() ). However, I would like to derive the states of my statechart from a class like this: template<class context> struct State : sc::simple_state< State<context>, context > { // Some application-specific things }; struct StateA : State< StateMachine > { typedef sc::transition< Event, StateB > reactions; }; struct StateB : State< StateMachine > { typedef sc::transition< Event, StateA > reactions; }; ----------------- Now, calling process_event( Event() ) does not do anything, except turning the event up at the StateMachine::unconsumed_event() method. I am aware of this one: http://www.boost.org/doc/libs/1_35_0/libs/statechart/doc/faq.html#TemplatedS... but I'm not sure whether this applies in any way to my case, as I don't have any compiler errors. May I be violating some prerequisites here? Thank you for any help you can provide, Stefan.
Hi Stefan [snip]
struct State : sc::simple_state< State<context>, context >
{ // Some application-specific things
};struct StateA : State< StateMachine > { typedef sc::transition< Event, StateB > reactions; }; struct StateB : State< StateMachine >
{ typedef sc::transition< Event, StateA > reactions; }; [snip]
May I be violating some prerequisites here?Thank you for any help you can provide, Stefan.
Yes, the first template argument passed to simple_state must be the *most-derived* simple_state<> subclass. Please see: <http://www.boost.org/doc/libs/1_36_0/libs/statechart/doc/reference.html#ClassTemplatesimple_state>, Class template simple_state parameters HTH, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
Ha! Got it. That helped. Thank you. For the benefit of other fellow physicists with a reading problem, this will work: template<class MostDerived, class Context> struct State : sc::simple_state< MostDerived, Context > { // Some application-specific things common to all states }; struct StateA : State< StateA, StateMachine > { typedef sc::transition< Event, StateB > reactions; }; [...] Stefan. 2008/9/1 Andreas Huber <ahd6974-spamboostorgtrap@yahoo.com>
[snipsnip]
May I be violating some prerequisites here?Thank you for any help you can
provide, Stefan.
Yes, the first template argument passed to simple_state must be the *most-derived* simple_state<> subclass. Please see:
< http://www.boost.org/doc/libs/1_36_0/libs/statechart/doc/reference.html#ClassTemplatesimple_state>, Class template simple_state parameters
HTH,
-- 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-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Andreas Huber
-
Stefan Steuerwald