質問

I'm developing a state machine using boost MSM framework. Their tutorial states that boost::any can be used as a "Kleene event", allowing transition on any event being fired, if the current state is the source state. This doesn't work for me, however. I just receive "no_transition". Here is my sample code:

#include <iostream> #include <boost/msm/back/state_machine.hpp> #include <boost/msm/front/state_machine_def.hpp> #include <boost/msm/front/functor_row.hpp> #include <boost/any.hpp> using namespace std; namespace msm = boost::msm; using namespace msm::front; namespace mpl = boost::mpl; namespace { struct event1 {}; struct some_event{}; struct some_sm_ : public msm::front::state_machine_def<some_sm_> { struct State1 : public msm::front::state<> { template <class Event,class FSM> void on_entry(Event const& ,FSM&) {std::cout << "entering: State1" << std::endl;} template <class Event,class FSM> void on_exit(Event const&,FSM& ) {std::cout << "leaving: State1" << std::endl;} }; struct State2 : public msm::front::state<> { template <class Event,class FSM> void on_entry(Event const& ,FSM&) {std::cout << "entering: State2" << std::endl;} template <class Event,class FSM> void on_exit(Event const&,FSM& ) {std::cout << "leaving: State2" << std::endl;} }; typedef State1 initial_state; struct transition_table : mpl::vector< // Start Event Next // +---------+-------------+---------+ Row < State1 , boost::any , State2 >, Row < State1 , event1 , State2 > // +---------+-------------+---------+ > {}; template <class FSM,class Event> void no_transition(Event const& e, FSM&,int state) { std::cout << "no transition from state " << state << " on event " << typeid(e).name() << std::endl; } }; typedef msm::back::state_machine<some_sm_> some_sm; void test() { some_sm p; p.start(); p.process_event(some_event()); p.process_event(event1()); } } int main() { test(); return 0; }

When executed, it produces the following output:

entering: State1

no transition from state 0 on event N12_GLOBAL__N_110some_eventE

leaving: State1

entering: State2

I would expect a transition from "State1" to "State2" to occur upon "some_event", but that, apparently, does not happen.

I must be missing something, but I can't realize what is it.

役に立ちましたか?

解決

I compiled my example with boost version 1.53 and the boost::any worked as explained in the tutorial.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top