Subject: [boost] [MSM] constructor arguments for sub state/machines
From: Richard Szabo (sz.richard_at_[hidden])
Date: 2010-12-28 18:07:31
I have tried out the new feature of msm : using constructor arguments
for substate/machines :
player p( back::states_ << Playing(back::states_ << Song1(some_Song1_data)) ,
see doc : http://svn.boost.org/svn/boost/trunk/libs/msm/doc/HTML/ch03s05.html#d0e2320
I have some problem with it :(.
this case state Playing and Song1 will be constructed first with
default constructor in back end constructor than the internally
constructed Playing and Song1 will be assigned to the newly construed
Playing / Song1 copy which got copied by value.
The only reason to use this feature is to able to use reference
members in the substates but for that reference members must be
initialised in the member initialisation list of the constructor of
the substates in order to provide the references constructor arguments
must be used.
Since subsates must provide default constructors it is not possible to
always initialise reference members from outside.
Furthermore substate must be copyable and must implement assignment
which brings more harm than good :(.
Is there a way to resolve these problems ?
Looking to the test:
I think there is a bug : at with line : fsm.context_ = 20;
according my understanding the compiler will create a
SomeExternalContext object on the stack of the context of
on_entry(Event const&,FSM& fsm) function and will replace the
fsm.context_ reference to the reference of the newly constructed
object one the stack
so when the on_entry function exits the SomeExternalContext object
will be removed from the stack so the fsm.context_ reference becomes
invalid so code p.context_.bla == 20 actually should crash because it
uses invalid reference.
I think it is just working by chance ?
p.start(); // after this p.context_ will be invalid
BOOST_CHECK_MESSAGE(p.context_.bla == 20,"error with fsm entry
behavior"); // accessing invalid reference
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk