Boost logo

Boost Users :

From: Tony Turner (acturner01_at_[hidden])
Date: 2008-07-20 16:25:38


Greetings;

PROBLEM:
I have a need to call a 'post_event' from the ctor of a templated state that
belongs to a templated machine.

BEST SHOT AT SOLUTION SO FAR: ( items #1,#2 & #3 below work fine... item #4, my
goal, fails)

Request for specific assistance is in item #5 below.

Thank you for your time and effort, I know you are very busy and appreciate the
help.

Regards,

Tony Turner
acturner01_at_[hidden]

//************************************************************************
(1) I started with the following non-templated version, which works just fine:

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

// fwd decl
struct Start;
struct Inst : public sc::state_machine< Inst, Start > {};

struct Start : public sc::state< Start, Inst > {
    Start(my_context ctx ) : my_base( ctx ) {// do some stuff ...}
};

// 'main' routine is....

    BOOST_AUTO_TEST_CASE(testMyMachine) {
        Inst myMachine;
        myMachine.initiate();
    }
//************************************************************************
(2) I then templated the machine, with no problems, which is half way to my
solution:

// fwd decl
struct NDIREV_17 {};
struct Start;

template< typename I >
struct Inst : public sc::state_machine< Inst<I>, Start > {};

struct Start : public sc::state< Start, Inst1<NDIREV_17> > {
    Start(my_context ctx ) : my_base( ctx ) {}
};

// 'main' routine is....

    BOOST_AUTO_TEST_CASE(testMyMachine) {
        Inst<NDIREV_17> myMachine;
        myMachine.initiate();
    }

//************************************************************************
(3) I then templated the simple_state<> version, which works just fine.
struct NDIREV_17 {};

template< typename I >
struct Start;

template< typename I >
struct Inst : public sc::state_machine< Inst<I>, Start<I> > {};

template< typename I >
struct Start : public sc::simple_state< Start<I>, Inst<I> > {
};

// same 'main'

//************************************************************************
(4) finally, I templated the state<> version, , which has problems.

        [NOTE: I've referenced line # 3773 below, to sync with output]

struct NDIREV_17 {};

template< typename I >
struct Start;

template< typename I >
struct Inst : public sc::state_machine< Inst<I>, Start<I> > {};[ line# 3773 ]

template< typename I >
struct Start : public sc::state< Start<I>, Inst<I> > {
    Start<I>(my_context ctx ) : my_base( ctx ) {}
};

// same 'main'

//************************************************************************
(5) ATTEMPTS TO FIX:

  a) look @ code in state.hpp ( shown below ) and attempt to replace
"my_context" & "my_base" with direct substitutions of "simple_state" and
this->set_context.... no luck.

REQUEST FOR HELP:
Could someone who has successfully templated both the machine<> and the state<>
classes possibly give me a hint as to what I might be able to do to fix this bug?

Thank you for your time and effort;

Tony Turner
acturner01_at_[hidden]

//************************************************************************
(6) state.hpp fragment

// here is 'state<> fragment from state.hpp

template< class MostDerived,
          class Context,
          class InnerInitial = mpl::list<>,
          history_mode historyMode = has_no_history >
class state : public simple_state<
  MostDerived, Context, InnerInitial, historyMode >
{
  typedef simple_state< MostDerived, Context, InnerInitial, historyMode >
    base_type;

  protected:
    //////////////////////////////////////////////////////////////////////////
    struct my_context
    {
      my_context( typename base_type::context_ptr_type pContext ) :
        pContext_( pContext )
      {
      }

      typename base_type::context_ptr_type pContext_;
    };

    typedef state my_base;

    state( my_context ctx )
    {
      this->set_context( ctx.pContext_ );
    }

    ~state() {}

------------------------------------------------------------
------------------------------------------------------------

Resulting Error msg:

Device.hpp:3774:
error: expected `)' before 'ctx'
In file included from src/bin/UnitTestDevice.cpp:25:
Device.hpp:3774:
error: expected `)' before 'ctx'
/usr/include/boost/statechart/state.hpp: In static member function 'static
typename boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::inner_context_ptr_type boost::statechart::state<MostDerived,
Context, InnerInitial, historyMode>::shallow_construct(const typename
boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::context_ptr_type&, typename
boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::outermost_context_base_type&) [with MostDerived =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Context =
MNavAnts::Inst1<MNavAnts::NDIREV_99>, InnerInitial = boost::mpl::list<mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na>, boost::statechart::history_mode historyMode =
has_no_history]':
/usr/include/boost/statechart/state.hpp:79: instantiated from 'static void
boost::statechart::state<MostDerived, Context, InnerInitial,
historyMode>::deep_construct(const typename
boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::context_ptr_type&, typename
boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::outermost_context_base_type&) [with MostDerived =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Context =
MNavAnts::Inst1<MNavAnts::NDIREV_99>, InnerInitial = boost::mpl::list<mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na>, boost::statechart::history_mode historyMode =
has_no_history]'
/usr/include/boost/statechart/state.hpp:70: instantiated from 'static void
boost::statechart::state<MostDerived, Context, InnerInitial,
historyMode>::initial_deep_construct(typename
boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::outermost_context_base_type&) [with MostDerived =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Context =
MNavAnts::Inst1<MNavAnts::NDIREV_99>, InnerInitial = boost::mpl::list<mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na>, boost::statechart::history_mode historyMode =
has_no_history]'
/usr/include/boost/statechart/state_machine.hpp:701: instantiated from 'void
boost::statechart::state_machine<MostDerived, InitialState, Allocator,
ExceptionTranslator>::initial_construct() [with MostDerived =
MNavAnts::Inst1<MNavAnts::NDIREV_99>, InitialState =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Allocator = std::allocator<void>,
ExceptionTranslator = boost::statechart::null_exception_translator]'
/usr/include/boost/statechart/state_machine.hpp:716: instantiated from
'boost::statechart::result boost::statechart::state_machine<MostDerived,
InitialState, Allocator,
ExceptionTranslator>::initial_construct_function::operator()() [with MostDerived
= MNavAnts::Inst1<MNavAnts::NDIREV_99>, InitialState =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Allocator = std::allocator<void>,
ExceptionTranslator = boost::statechart::null_exception_translator]'
/usr/include/boost/statechart/null_exception_translator.hpp:33: instantiated
from 'boost::statechart::result
boost::statechart::null_exception_translator::operator()(Action,
ExceptionEventHandler) [with Action =
boost::statechart::state_machine<MNavAnts::Inst1<MNavAnts::NDIREV_99>,
MNavAnts::Start1<MNavAnts::NDIREV_99>, std::allocator<void>,
boost::statechart::null_exception_translator>::initial_construct_function,
ExceptionEventHandler =
boost::statechart::state_machine<MNavAnts::Inst1<MNavAnts::NDIREV_99>,
MNavAnts::Start1<MNavAnts::NDIREV_99>, std::allocator<void>,
boost::statechart::null_exception_translator>::exception_event_handler]'
/usr/include/boost/statechart/state_machine.hpp:253: instantiated from 'void
boost::statechart::state_machine<MostDerived, InitialState, Allocator,
ExceptionTranslator>::initiate() [with MostDerived =
MNavAnts::Inst1<MNavAnts::NDIREV_99>, InitialState =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Allocator = std::allocator<void>,
ExceptionTranslator = boost::statechart::null_exception_translator]'
src/bin/UnitTestDevice.cpp:870: instantiated from here
/usr/include/boost/statechart/state.hpp:89: error: no matching function for call
to
'MNavAnts::Start1<MNavAnts::NDIREV_99>::Start1(
boost::statechart::state<MNavAnts::Start1<MNavAnts::NDIREV_99>,
MNavAnts::Inst1<MNavAnts::NDIREV_99>, boost::mpl::list<mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na>, has_no_history>::my_context)'
Device.hpp:3773:
note: candidates are: MNavAnts::Start1<MNavAnts::NDIREV_99>::Start1()
Device.hpp:3773:
note: MNavAnts::Start1<MNavAnts::NDIREV_99>::Start1(const
MNavAnts::Start1<MNavAnts::NDIREV_99>&)
/usr/include/boost/statechart/state.hpp: In static member function 'static
typename boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::inner_context_ptr_type boost::statechart::state<MostDerived,
Context, InnerInitial, historyMode>::shallow_construct(const typename
boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::context_ptr_type&, typename
boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::outermost_context_base_type&) [with MostDerived =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Context =
MNavAnts::Inst1<MNavAnts::NDIREV_99>, InnerInitial = boost::mpl::list<mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na>, boost::statechart::history_mode historyMode =
has_no_history]':
/usr/include/boost/statechart/state.hpp:79: instantiated from 'static void
boost::statechart::state<MostDerived, Context, InnerInitial,
historyMode>::deep_construct(const typename
boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::context_ptr_type&, typename
boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::outermost_context_base_type&) [with MostDerived =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Context =
MNavAnts::Inst1<MNavAnts::NDIREV_99>, InnerInitial = boost::mpl::list<mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na>, boost::statechart::history_mode historyMode =
has_no_history]'
/usr/include/boost/statechart/state.hpp:70: instantiated from 'static void
boost::statechart::state<MostDerived, Context, InnerInitial,
historyMode>::initial_deep_construct(typename
boost::statechart::simple_state<MostDerived, Context, InnerInitial,
historyMode>::outermost_context_base_type&) [with MostDerived =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Context =
MNavAnts::Inst1<MNavAnts::NDIREV_99>, InnerInitial = boost::mpl::list<mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na>, boost::statechart::history_mode historyMode =
has_no_history]'
/usr/include/boost/statechart/state_machine.hpp:701: instantiated from 'void
boost::statechart::state_machine<MostDerived, InitialState, Allocator,
ExceptionTranslator>::initial_construct() [with MostDerived =
MNavAnts::Inst1<MNavAnts::NDIREV_99>, InitialState =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Allocator = std::allocator<void>,
ExceptionTranslator = boost::statechart::null_exception_translator]'
/usr/include/boost/statechart/state_machine.hpp:716: instantiated from
'boost::statechart::result boost::statechart::state_machine<MostDerived,
InitialState, Allocator,
ExceptionTranslator>::initial_construct_function::operator()() [with MostDerived
= MNavAnts::Inst1<MNavAnts::NDIREV_99>, InitialState =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Allocator = std::allocator<void>,
ExceptionTranslator = boost::statechart::null_exception_translator]'
/usr/include/boost/statechart/null_exception_translator.hpp:33: instantiated
from 'boost::statechart::result
boost::statechart::null_exception_translator::operator()(Action,
ExceptionEventHandler) [with Action =
boost::statechart::state_machine<MNavAnts::Inst1<MNavAnts::NDIREV_99>,
MNavAnts::Start1<MNavAnts::NDIREV_99>, std::allocator<void>,
boost::statechart::null_exception_translator>::initial_construct_function,
ExceptionEventHandler =
boost::statechart::state_machine<MNavAnts::Inst1<MNavAnts::NDIREV_99>,
MNavAnts::Start1<MNavAnts::NDIREV_99>, std::allocator<void>,
boost::statechart::null_exception_translator>::exception_event_handler]'
/usr/include/boost/statechart/state_machine.hpp:253: instantiated from 'void
boost::statechart::state_machine<MostDerived, InitialState, Allocator,
ExceptionTranslator>::initiate() [with MostDerived =
MNavAnts::Inst1<MNavAnts::NDIREV_99>, InitialState =
MNavAnts::Start1<MNavAnts::NDIREV_99>, Allocator = std::allocator<void>,
ExceptionTranslator = boost::statechart::null_exception_translator]'
src/bin/UnitTestDevice.cpp:870: instantiated from here
/usr/include/boost/statechart/state.hpp:89: error: no matching function for call
to
'MNavAnts::Start1<MNavAnts::NDIREV_99>::Start1(
boost::statechart::state<MNavAnts::Start1<MNavAnts::NDIREV_99>,
MNavAnts::Inst1<MNavAnts::NDIREV_99>, boost::mpl::list<mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na,
mpl_::na, mpl_::na>, has_no_history>::my_context)'
Device.hpp:3773:
note: candidates are: MNavAnts::Start1<MNavAnts::NDIREV_99>::Start1()
Device.hpp:3773:
note: MNavAnts::Start1<MNavAnts::NDIREV_99>::Start1(const
MNavAnts::Start1<MNavAnts::NDIREV_99>&)


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