|
Boost Users : |
Subject: Re: [Boost-users] boost::statechart "custom::reaction"
From: rahul baruah (rahul03baruah_at_[hidden])
Date: 2013-11-05 06:16:45
ok..Let me give you better snippet
*SM.hpp:*
struct TopState;
struct PairingStateMachine : sc::state_machine< StateMachine, TopState >
{
unsigned int max; /**< Total number of devices
which can be paired */
};
struct NotReady;
struct TopState : sc::state< TopState, StateMachine, NotReady >
{
TopState(my_context ctx) : my_base( ctx )
{
}
~TopState() { std::cout << "Leave and desctruct TopState state!\n"; }
typedef TopstateList reactions;
template< class MostDerived >
sc::result react( const PairingBaseEvents< MostDerived > & );
};
template< class MostDerived, class Context >
struct StateBase : sc::state< MostDerived, Context>
{
typedef sc::state< MostDerived, Context> base_type;
typedef typename base_type::my_context my_context;
typedef StateBase my_base;
StateBase( my_context ctx ) : base_type( ctx )
{
std::cout << "StateBase cst" << std::endl;
}
};
struct NotReady : StateBase< NotReady, TopState >
{
typedef NotReadystateList reactions;
NotReady (my_context ctx) : my_base( ctx ){
}
template< class MostDerived >
sc::result react( const PairingBaseEvents< MostDerived > & );
};
*SM.cpp:*
template< class MostDerived >
sc::result NotReady::react( const PairingBaseEvents< MostDerived > &
PAEvent){
if (typeid(EntryEvent).name() == typeid(PAEvent).name())
{
outermost_context().maxPairedDevices++;
return discard_event();
}
}
regards
Rahul
On Tue, Nov 5, 2013 at 4:18 PM, Igor R <boost.lists_at_[hidden]> wrote:
> >>
> >> Where do you define the above "react" member function template?
>
> > *.cpp file
> >
> > template< class MostDerived >
> > sc::result NotReady::react( const PairingBaseEvents< MostDerived > &
> > PAEvent){
> > if (typeid(EntryEvent).name() == typeid(PAEvent).name())
> > {
> > outermost_context().maxPairedDevices++;
> > return discard_event();
> > }
> > }
> >
> > i Have a mpl:list defined in another header file.
>
>
> If you define a function template in cpp (not in the header), you have
> to instantiate this definition manually for all the types that the
> declaration gets instantiated for.
> If you want to rely on automatic template instantiation, define the
> function in the header file.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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