Search code examples
c++booststate-machineboost-statechartstatechart

How to get the current most derived state in a boost::statechart state_machine object?


I am using boost::state_chart library. For debug purposes, I would like to know at any given time the state of my state machine. How to get the current (most derived) state in the state_machine object ?


Solution

  • You can get at the current state object(s) with state_machine::state_begin and state_machine::state_end, see "Custom State Queries" here:

    http://www.boost.org/libs/statechart/doc/tutorial.html#StateQueries

    These give you base class pointers, if you want to get at the most-derived type you'd have to employ a visitor of some sort.