Boost logo

Boost Users :

Subject: Re: [Boost-users] [StateChart] Inheriting state
From: Tarcisio Fedrizzi (tarcisio.fedrizzi_at_[hidden])
Date: 2010-02-04 11:17:56


Hi,
I had almost the same problem you have. I solved it in this way:

#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/event.hpp>
#include <boost/statechart/custom_reaction.hpp>
#include <boost/mpl/list.hpp>

namespace sc = boost::statechart;
namespace mpl = boost::mpl;

struct Event1 : sc::event<Event1>
{};

template<class Derived, class Outer>
struct ActiveBase : sc::simple_state<Derived, Outer>
{

   typedef sc::simple_state<Derived, Outer> base;

   sc::result react(const Event1& event)
   {
     return discard_event();
   }

   using base::discard_event;

};

struct Active;

struct FSM : sc::state_machine<FSM, Active>
{

};

struct Active : ActiveBase<Active, FSM>
{
   typedef sc::custom_reaction<Event1> reactions;
};

int main()
{
   FSM fsm;
   fsm.initiate();
}

notice the custom_reaction instead on in_state reaction.
If you see in the documentation the function to specify for
the in state reaction must be:

"...|| Either the state defining the in-state reaction itself or one of
it direct or indirect contexts..."

since the base state (ActiveBase) is not known to the library the library
is not able to use the function specified in the in_state_reaction template.
Indeed if you specify Active instead of BaseActive in the in_state_reaction
template (like in_state_reaction<Event1, Active, &Active::f>) things work
a bit better. However this failes to compile anyway because the third
parameters is seen to be of type "void (ActiveBase<Active,
FSM>::*)(const Event1&)"
and this doesn't match the required type.
Anyway this is only an hypothesis I would wait for the author response
in order to have a correct response.

Hope this is helpful.
Bye,
Tarcisio.



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