boost :: msm中的状态ID

时间:2013-05-27 14:42:38

标签: c++ boost state-machine boost-msm

在boost :: msm教程中,有一个示例显示我们如何检查当前状态。

    // Transition table for player
    struct transition_table : mpl::vector<
        //      Start     Event         Next      Action               Guard
        //    +---------+-------------+---------+---------------------+----------------------+
        a_row < Stopped , play        , Playing , &p::start_playback                         >,
        a_row < Stopped , open_close  , Open    , &p::open_drawer                            >,
        a_row < Stopped , stop        , Stopped , &p::stopped_again                          >,
        //    +---------+-------------+---------+---------------------+----------------------+
        a_row < Open    , open_close  , Empty   , &p::close_drawer                           >,
        //    +---------+-------------+---------+---------------------+----------------------+
        a_row < Empty   , open_close  , Open    , &p::open_drawer                            >,
        a_row < Empty   , cd_detected , Stopped , &p::store_cd_info                          >,
        //    +---------+-------------+---------+---------------------+----------------------+
        a_row < Playing , stop        , Stopped , &p::stop_playback                          >,
        a_row < Playing , pause       , Paused  , &p::pause_playback                         >,
        a_row < Playing , open_close  , Open    , &p::stop_and_open                          >,
        //    +---------+-------------+---------+---------------------+----------------------+
        a_row < Paused  , end_pause   , Playing , &p::resume_playback                        >,
        a_row < Paused  , stop        , Stopped , &p::stop_playback                          >,
        a_row < Paused  , open_close  , Open    , &p::stop_and_open                          >,
        //    +---------+-------------+---------+---------------------+----------------------+
        a_row < AllOk   , error_found ,ErrorMode, &p::report_error                           >,
        a_row <ErrorMode,end_error    ,AllOk    , &p::report_end_error                       >
        //    +---------+-------------+---------+---------------------+----------------------+
    > {};

    // Replaces the default no-transition response.
    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;
    }
};
// Pick a back-end
typedef msm::back::state_machine<player_> player;

//
// Testing utilities.
//
static char const* const state_names[] = { "Stopped", "Open", "Empty", "Playing", "Paused","AllOk","ErrorMode" };

void pstate(player const& p)
{
    // we have now several active states, which we show
    for (unsigned int i=0;i<player::nr_regions::value;++i)
    {
        std::cout << " -> " << state_names[p.current_state()[i]] << std::endl;
    }
}

作者使用数组state_names。但我没有找到如何确定州的顺序的解释。当然,我可以猜测它是转换表的“开始”列中的状态顺序。但是,当某些州不在“开始”栏中时会发生什么情况?

1 个答案:

答案 0 :(得分:1)

这在MSM文档(第6章内部,生成的状态ID)中进行了解释。订单是人们所期望的 - 转换表中各自的源状态顺序,然后是各自的目标状态顺序。