[MSM] Compile-time error using SubMachines and events that carries some data

Hi, I have a Main State Machine (state_machine_) and two SubMachines. I want to start the first SubMachine and when it finished I want to start the second SubMachine. Here is the code. http://pastebin.com/sBdS1wvJ I have a compile-time error on some States of the second SubMachine. error: no member named 'element' in 'exit_introduction' std::cout << "event.element(): " << event.element() << std::endl; ~~~~~ ^ This is on state "StaringGame" and according the Transition Table of GameSM, only the event "character_selected" is used. I don't know why is trying to use the event "exit_introduction". Is this a bug of MSM? Am I doing something wrong? Thanks and regards, Fernando Pelliccioni.

Hi Fernando, Boost.Msm instansiates on_entry member function with various events even if your transition never happen. Hence you can't assume that event handler's template palameta "Event" is always the event you set on your transition table. IIUC, this is a MSM spacification. To solve this problem, you can use SFINAE as follows: struct StaringGame : public msm::front::state<> { template <typename Event, typename FSM> void on_entry(Event const& event, FSM& fsm, typename boost:: enable_if<boost::is_same<Event, character_selected> >::type* = 0 ) { std::cout << "entering: StaringGame" << std::endl; std::cout << "event.element(): " << event.element() << std::endl; std::cout << "event typeid: " << typeid(event).name() << std::endl; } template <typename Event, typename FSM> void on_entry(Event const& event, FSM& fsm, typename boost:: disable_if<boost::is_same<Event, character_selected> >::type* = 0 ) { } }; struct StartTurn: public msm::front::state<> { template <typename Event, typename FSM> void on_entry(Event const& event, FSM& fsm, typename boost:: enable_if<boost::is_same<Event, character_selected> >::type* = 0 ) { std::cout << "entering: StartTurn" << std::endl; std::cout << "event.element(): " << event.element() << std::endl; std::cout << "event typeid: " << typeid(event).name() << std::endl; } template <typename Event, typename FSM> void on_entry(Event const& event, FSM& fsm, typename boost:: disable_if<boost::is_same<Event, character_selected> >::type* = 0 ) { } }; Could you try it? Takatoshi Kondo On Thu, May 23, 2013 at 11:05 AM, Fernando Pelliccioni < fpelliccioni@gmail.com> wrote:
Hi,
I have a Main State Machine (state_machine_) and two SubMachines. I want to start the first SubMachine and when it finished I want to start the second SubMachine.
Here is the code.
I have a compile-time error on some States of the second SubMachine.
error: no member named 'element' in 'exit_introduction' std::cout << "event.element(): " << event.element() << std::endl; ~~~~~ ^
This is on state "StaringGame" and according the Transition Table of GameSM, only the event "character_selected" is used. I don't know why is trying to use the event "exit_introduction".
Is this a bug of MSM? Am I doing something wrong?
Thanks and regards, Fernando Pelliccioni.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Thanks Takatoshi, Seemed odd to me that MSM instantiate a State using a "wrong" Event. I thought I was doing something wrong. The enable_if solution works perfect. :) Thanks and regards, Fernando Pelliccioni On Thu, May 23, 2013 at 3:53 PM, Takatoshi Kondo <redboltz@gmail.com> wrote:
Hi Fernando,
Boost.Msm instansiates on_entry member function with various events even if your transition never happen. Hence you can't assume that event handler's template palameta "Event" is always the event you set on your transition table. IIUC, this is a MSM spacification.
To solve this problem, you can use SFINAE as follows:
struct StaringGame : public msm::front::state<> { template <typename Event, typename FSM> void on_entry(Event const& event, FSM& fsm, typename boost:: enable_if<boost::is_same<Event, character_selected> >::type* = 0 ) { std::cout << "entering: StaringGame" << std::endl; std::cout << "event.element(): " << event.element() << std::endl; std::cout << "event typeid: " << typeid(event).name() << std::endl; } template <typename Event, typename FSM> void on_entry(Event const& event, FSM& fsm, typename boost:: disable_if<boost::is_same<Event, character_selected> >::type* = 0 ) { } };
struct StartTurn: public msm::front::state<> { template <typename Event, typename FSM> void on_entry(Event const& event, FSM& fsm, typename boost:: enable_if<boost::is_same<Event, character_selected> >::type* = 0 ) { std::cout << "entering: StartTurn" << std::endl; std::cout << "event.element(): " << event.element() << std::endl; std::cout << "event typeid: " << typeid(event).name() << std::endl; } template <typename Event, typename FSM> void on_entry(Event const& event, FSM& fsm, typename boost:: disable_if<boost::is_same<Event, character_selected> >::type* = 0 ) { } };
Could you try it?
Takatoshi Kondo
On Thu, May 23, 2013 at 11:05 AM, Fernando Pelliccioni < fpelliccioni@gmail.com> wrote:
Hi,
I have a Main State Machine (state_machine_) and two SubMachines. I want to start the first SubMachine and when it finished I want to start the second SubMachine.
Here is the code.
I have a compile-time error on some States of the second SubMachine.
error: no member named 'element' in 'exit_introduction' std::cout << "event.element(): " << event.element() << std::endl; ~~~~~ ^
This is on state "StaringGame" and according the Transition Table of GameSM, only the event "character_selected" is used. I don't know why is trying to use the event "exit_introduction".
Is this a bug of MSM? Am I doing something wrong?
Thanks and regards, Fernando Pelliccioni.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

----- Original Message ----- From: "Fernando Pelliccioni" <fpelliccioni@gmail.com> Newsgroups: gmane.comp.lib.boost.devel To: <boost@lists.boost.org> Sent: Thursday, May 23, 2013 11:24 PM Subject: Re: [MSM] Compile-time error using SubMachines and events that carries some data
Thanks Takatoshi,
Seemed odd to me that MSM instantiate a State using a "wrong" Event. I thought I was doing something wrong.
The enable_if solution works perfect. :)
Thanks and regards, Fernando Pelliccioni
As Takatoshi (thanks a lot!) correctly explains, MSM does not know with which event a state will be entered as it's a run-time decision, while templates are instantiated at compile-time. I understand the confusion but I'm afraid there is not much to do about it :( Regards, Christophe

On Sun, May 26, 2013 at 5:25 PM, Christophe Henry < christophe.j.henry@googlemail.com> wrote:
----- Original Message ----- From: "Fernando Pelliccioni" < fpelliccioni@gmail.com> Newsgroups: gmane.comp.lib.boost.devel To: <boost@lists.boost.org> Sent: Thursday, May 23, 2013 11:24 PM Subject: Re: [MSM] Compile-time error using SubMachines and events that carries some data
Thanks Takatoshi,
Seemed odd to me that MSM instantiate a State using a "wrong" Event. I thought I was doing something wrong.
The enable_if solution works perfect. :)
Thanks and regards, Fernando Pelliccioni
As Takatoshi (thanks a lot!) correctly explains, MSM does not know with which event a state will be entered as it's a run-time decision, while templates are instantiated at compile-time. I understand the confusion but I'm afraid there is not much to do about it :(
Regards, Christophe
Thanks Christophe, As the Transition-Table is a compile-time structure, I thought that States could only be instantiated using the associated Events in the Transition-Table. However, don't worry, the "Concept Overloading Simulation" ( enable_if ) solution of works perfect :) Thanks and regards, Fernando.
participants (3)
-
Christophe Henry
-
Fernando Pelliccioni
-
Takatoshi Kondo