I'm trying to use boost::msm library to create a state machine in my code. Does anyone know a way to get a string name (not int id) of a state? I am trying to get this for logging/debugging purpose. For example in no_transition function, I get the state id but I'm trying to get a name so it's easier to read:
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);
}
Here's how I defined an event and a state: State:
struct Idle : front::state<> {
static const char* const getStateName() {
return "Idle";
}
};
Event:
struct SampleEvent {
SampleEvent() {}
static const char* const getEventId() {
return "SampleEvent";
}
};
Any ideas would be great. Thanks!