我正在尝试使用 boost::msm 库在我的代码中创建状态机。有谁知道获取状态的字符串名称(不是 int id)的方法?我正在尝试将此用于日志记录/调试目的。例如在 no_transition 函数中,我得到了状态 id,但我正在尝试获取一个名称,以便于阅读:
template <class Event ,class Fsm>
void no_transition(Event const& e, Fsm& fsm, int stateId)
{
//This is what I'm trying:
auto state = fsm.get_state_by_id(stateId); //This returns a boost::msm::front::default_base_state. Anything I can override in there to set a name?
const char* stateName = state->getStateName(); //I want to do something like this since I can do e.getEventId()
print("FSM rejected the event %s as there is no transition from current state %s (%d)\n", e.getEventId(), stateName, stateId);
}
以下是我定义事件和状态的方式: 状态:
struct Idle : front::state<> {
static const char* const getStateName() {
return "Idle";
}
};
事件:
struct SampleEvent {
SampleEvent() {}
static const char* const getEventId() {
return "SampleEvent";
}
};
任何想法都会很棒。谢谢!