我正在使用 boost MSM 框架开发状态机。他们的教程指出boost::any可以用作“Kleene 事件”,如果当前状态是源状态,则允许在任何被触发的事件上进行转换。然而,这对我不起作用。我刚刚收到“no_transition”。这是我的示例代码:
#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;
}
执行时,它会产生以下输出:
进入:State1
在事件 N12_GLOBAL__N_110some_eventE 上没有从状态 0 转换
离开:State1
进入:State2
我希望在“some_event”上发生从“State1”到“State2”的转换,但这显然不会发生。
我一定错过了什么,但我无法意识到它是什么。