Class KPStateMachine¶
- Defined in File KPStateMachine.hpp
Inheritance Relationships¶
Base Types¶
public KPComponent(Class KPComponent)public KPSubject< KPStateMachineObserver >(Template Class KPSubject)
Class Documentation¶
-
class
KPStateMachine: public KPComponent, public KPSubject<KPStateMachineObserver>¶ Public Functions
-
template<typename
T>
voidregisterState(T &&state, StateName name, Middleware middleware = nullptr)¶ Register a state with a given unique name. “Optionally” accepts a functor as the third parameter. The functor should take care of calling transitionTo() method of this state machine to move on to the next state.
The middleware should define how the state would transition to another state according a passed-in integer value.
- Template Parameters
T: Deduced subtype of the state
- Parameters
state: State instancename: Name of the state being registeredmiddleware: Any callable with signature: void(int)
-
template<typename
T>
voidregisterState(T &&state, StateName name, StateName next)¶ Convenient method for registering a state with one direct transition to the next one
- Template Parameters
T: Deduced subtype of the state
- Parameters
state: State instancename: Name of the state being registerednext: Name of the next state to transition to
-
template<typename
T= KPState>
T &getState(StateName name)¶ Get the State object with optional static casting to the given state subclasss. The function doesn’t return if the name doesn’t exist.
- Return
- T& Reference to state in storage
- Template Parameters
KPState: Type to cast to
- Parameters
name: Name of the state registered in registerState()
-
KPState *
getCurrentState() const¶ Get the Current State object
- Return
- KPState* Ptr to the internal state object
-
void
next(int code = 0) const¶ This method is to be called in subclassese of KPState
- Parameters
code: exitcode StateController/StateMachine should decide how to deal with this code
-
void
restart()¶ Restart the state by passing the currentState name to transitionTo(name)
-
void
transitionTo(StateName name)¶ Transition to the state registered using the given name
- Parameters
name: Name of a state that was registered by calling registerState()
-
template<typename