【问题标题】:Boost MSM, transition won't happen despite boost::any being used as an eventBoost MSM,尽管 boost::any 被用作事件,但不会发生转换
【发布时间】:2013-07-03 14:03:44
【问题描述】:

我正在使用 boost MSM 框架开发状态机。他们的教程states 认为 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”的转换,但显然不会发生。

我一定错过了什么,但我不知道是什么。

【问题讨论】:

  • 我想我找到了答案:我正在使用 2012 年 2 月 24 日发布的 boost 版本 1.49。现在,根据这个变更集:link,对 boost::any 的支持为2012 年 5 月 31 日添加了一个通用事件。我会用更新的版本检查一下...

标签: boost state-machine boost-any boost-msm


【解决方案1】:

我使用 boost 版本 1.53 编译了我的示例,并且 boost::any 按照教程中的说明工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-16
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多