JD wrote:
Thanks for your quick answer. It works for this particular problem, but still I have a more general problem with Boost.Statechart that bother me. In the faq I read:
Q. Does Boost.Statechart support polymorphic events? A. No. Although events can be derived from each other to write common code only once
Ok but polymorphism is more than just factorizing code.
In my experience with events you rarely need true polymorphism. If you do, you can often use the trick demonstrated in the FAQ item you refer to. True, from a purely functional perspective this is a limitation I'd rather not have in the library. However, this limitation makes the implementation of the internally used RTTI mechanism much easier and much faster.
The way an event has still to define a "MostDerived" template prevent from using an event as a generic object.
It depends. It is true that there is currently no way to use a common custom base class for events and states as long as you restrict yourself to single inheritance. That is, if event_base does not offer what you look for then you need to multi-inherit your events from your custom base and statechart::event<> and use cross casts to gain access to the custom base. This is demonstrated with events here: http://www.boost-consulting.com/boost/libs/statechart/doc/tutorial.html#Gett... (see the call to state_cast<>, which uses dynamic_cast under the hood) [snip]
//snippet on getline(is, line); theGenericEvent = the_function_in_question(line); MyMachine.post_event(theGenericEvent); //snippet off
I simply can't do that. Or I'm missing something. What is the rational for events not supporting polymorphism?
Have a look at the signature of post_event: http://www.boost-consulting.com/boost/libs/statechart/doc/reference.html#pos... What is stopping you to declare theGenericEvent variable above as event_base type? HTH, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.