|
Boost Users : |
From: JD (jean.daniel.michaud_at_[hidden])
Date: 2007-04-10 15:31:51
Andreas Huber wrote:
>
> There are two options to do this:
> 1) Use C++ RTTI, i.e. type_info::name(). This is the easiest option as
> it necessitates the least amount of work but of course requires that you
> compile your program with C++ RTTI enabled.
> 2) Use event_base::custom_static_type_ptr
>
Andreas,
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. The way an
event has still to define a "MostDerived" template prevent from using an
event as a generic object.
Consider the same example given above:
//snippet on
template< class MostDerived >
struct EventA : sc::event< MostDerived >
{
virtual std::string name() { return "unnamed event"; }
};
struct EventB : public EventA< EventB >
{
std::string name() { return "EventB"; }
};
struct EventC : public EventA< EventC >
{
std::string name() { return "EventC"; }
};
//snippet off
Now, how can I have a function that create events following an
argument. For example I read patterns in file, and following the pattern
I found, I have to create different event:
//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?
Thanks in advance for your time.
JD
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