Reputation: 497
In the tutorial to boost::msm there is an example showing how we can check the current state.
// 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;
}
}
Author uses an array state_names
. But I did not find an explanation how to determine the order of the states. Of course I can guess that it is the order of states in the "Start" column of the transition table. But what about cases when some states are not in the "Start" column?
Upvotes: 3
Views: 1466
Reputation: 725
This is explained in the MSM documentation (Chapter 6. Internals, Generated state ids). The order is what one would expect - respective order of source states in the transition table, followed by respective order of target states.
Upvotes: 0