Boost logo

Boost Users :

Subject: Re: [Boost-users] [MSM] Problem with passing event as a reference to base event class
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2013-07-05 16:07:01


Hi,

>Hi,
>

>I have noticed a strange problem with event processing with msm.
>My events derive publicly from a base events struct like this:
>

>struct BaseEvent { virtual ~BaseEvent() {} };
>struct ConcreteEvent : public BaseEvent {};
>

>

>I my FSM i have a transition defined for ConcreteEvent,
>

>When I do this :
>
>
>void foo(const BuddyEvent& event)

Do you mean BaseEvent?

>
>{
>fsm->process_event(event); // event is of type ConcreteEvent
>}
>

>The fsm fires a no_transition , and I see a message saying no transition for ConcreteEvent in state X (state X has a valid transition for >ConcreteEvent)

 The message is probably using typeid, which uses rtti, msm does not.

>However this succeeds:
>void foo(const BuddyEvent& event)
>{
>fsm->process_event(ConcreteEvent(0);
>}
>

>I am using boost-1.49 and the boost msm library that comes bundled with this.
This should make no difference, but I'm not sure what bugs there were in this version.

>So my question is, why is msm not able to generate a valid transition for a concrete event passed as a reference to its base tyoe.

MSM is a compile-time construct, not run-time. When you call process_event, templatized on the event type, the compile generates code for this type, because it has no way to know which event you will really send at run-time.

Note that the other way around would work, a transition with BaseEvent, and process_event(ConcreteEvent(0)) because this is something the compiler can solve.

What you want is probably possible in C++, but it would be another library based on rtti (no idea if one is doing though).

Cheers,
Christophe



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