[StateChart] pass objectpointer to FSM?

Hello,
first; thank you for an excellent library collection. I recently discovered
it, and I'm impressed!
My question:
How can I pass a pointer to an object into the state machine?
I want to use my state machine to control a real-life elevator. All the
functions for controlling this elevator is inside class Elevator;
I.e: myElevator->startEngine(UP);
I've tried different approaches as you might see in my attached code, but I
keep getting this error:
statemachine: ../boost/boost/cast.hpp:97: Target
boost::polymorphic_downcast(Source*) [with Target = ElevatorSM*, Source =
boost::statechart::state_machine

My question: How can I pass a pointer to an object into the state machine?
I want to use my state machine to control a real-life elevator. All the functions for controlling this elevator is inside class Elevator; I.e: myElevator->startEngine(UP);
I've tried different approaches as you might see in my attached code, but I keep getting this error: statemachine: ../boost/boost/cast.hpp:97: Target boost::polymorphic_downcast(Source*) [with Target = ElevatorSM*, Source = boost::statechart::state_machine
]: Assertion `dynamic_cast<Target>(x) == x' failed. Aborted h-file: http://codepad.org/i3rAjT1p cpp-file: http://codepad.org/TpaWluCz
Your code compiles well (after a few cosmetic changes, like fixing test123() name, adding "e" member to your fsm, etc.). boost 1.45, MSVC10.

Thank you for your quick respond.
I'm sorry for the small errors in my code, below is a code that compiles,
but as I try to run ./statemachine I get the following error:
Starting Elevator
Entering Elevator Idle At Floor state
Exiting Elevator Idle At Floor state
statemachine: ../boost/boost/cast.hpp:97: Target
boost::polymorphic_downcast(Source*) [with Target = ElevatorSM*, Source =
boost::statechart::state_machine
My question: How can I pass a pointer to an object into the state machine?
I want to use my state machine to control a real-life elevator. All the functions for controlling this elevator is inside class Elevator; I.e: myElevator->startEngine(UP);
I've tried different approaches as you might see in my attached code, but I keep getting this error: statemachine: ../boost/boost/cast.hpp:97: Target boost::polymorphic_downcast(Source*) [with Target = ElevatorSM*, Source = boost::statechart::state_machine
]: Assertion `dynamic_cast<Target>(x) == x' failed. Aborted h-file: http://codepad.org/i3rAjT1p cpp-file: http://codepad.org/TpaWluCz
Your code compiles well (after a few cosmetic changes, like fixing test123() name, adding "e" member to your fsm, etc.). boost 1.45, MSVC10. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Thank you for your quick respond. I'm sorry for the small errors in my code, below is a code that compiles, but as I try to run ./statemachine I get the following error:
Probably this crash is related to the fact that you're already in FSM destructor, so dynamic_cast fails to cast to the FSM. It's worth seeing what standard says about dynamic_cast applicability in such a case...

Thank you again.
Now I got it working, but I'm a bit confused regarding the error.
I can not see that I was in the destructor of the FSM, just the active
state.
But it is working. If anybody is interested, here is the working code:
http://codepad.org/2LLfnFBT
http://codepad.org/ALZmBUjJ
Thank you very much for the help,
Bernt-Johan
2011/3/15 Igor R
Thank you for your quick respond. I'm sorry for the small errors in my code, below is a code that compiles, but as I try to run ./statemachine I get the following error:
Probably this crash is related to the fact that you're already in FSM destructor, so dynamic_cast fails to cast to the FSM. It's worth seeing what standard says about dynamic_cast applicability in such a case... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Now I got it working, but I'm a bit confused regarding the error. I can not see that I was in the destructor of the FSM, just the active state.
You were getting that crash while exiting from main(), i.e. the state destructor were called as a part of FSM destruction (in the call stack you could see the FSM destructor).
participants (2)
-
Bernt-Johan Bergshaven
-
Igor R