|
Boost Users : |
Subject: [Boost-users] [StateChart] Inheriting state
From: Igor R (boost.lists_at_[hidden])
Date: 2010-02-03 18:06:13
Hello,
I'd like to share some functionality between states belonging to
different (but similar) FSMs. I try to do this by taking out some part
of a state to a base class template:
template<class Derived, class Outer, class Inner>
struct ActiveBase : state<Derived, Outer, Inner>
{
// this's probably not quite standard, but it should be fine with msvc
ActiveBase(my_context ctx) : my_base(ctx)
{}
void f(const Event1 &)
{}
};
struct Active;
struct FSM : asynchronous_state_machine<FSM, Active>
{
//...
};
struct Active : ActiveBase<Active, FSM, Disconnected>
{
Active(my_context ctx) : ActiveBase(ctx)
{}
typedef mpl::list
<
sc::in_state_reaction<Event1, ActiveBase, &ActiveBase::f>
> reactions;
};
However, this doesn't compile:
1>..\boost/statechart/state_machine.hpp(493) : error C2440: 'return' :
cannot convert from 'FSM' to 'ActiveBase<Derived,Outer,Inner> &'
1> with
1> [
1> Derived=Active,
1> Outer=FSM,
1> Inner=boost::mpl::list<Disconnected>
1> ]
1> ../boost/statechart/simple_state.hpp(684) : see reference to
function template instantiation 'Context
&boost::statechart::state_machine<MostDerived,InitialState,Allocator,ExceptionTranslator>::context<OtherContext>(void)'
being compiled
1> with
1> [
1> Context=ActiveBase<Active,FSM,boost::mpl::list<Disconnected>>,
1> MostDerived=FSM,
1> InitialState=Active,
1> Allocator=std::allocator<void>,
1> ExceptionTranslator=boost::statechart::null_exception_translator,
1> OtherContext=ActiveBase<Active,FSM,boost::mpl::list<Disconnected>>
1> ]
etc........
Of course, the above snippet is not the real code, and maybe I miss
the problem in some other place, but I just would like to know if the
above approach legitimate and *should* compile.
Thanks.
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