libzypp 17.37.17
|
This defines the actual StateMachine. More...
#include <zypp-core/zyppng/base/statemachine.h>
Classes | |
struct | _InitialState |
Public Types | |
using | AllStates = typename detail::make_state_set< Transitions... >::Type |
using | StateSetHelper = typename detail::make_statewithtransition_set< _InitialState, AllStates, Transitions... > |
using | FState = typename StateSetHelper::FirstState |
using | StateSet = typename StateSetHelper::Type |
using | StatemachineType = Statemachine< Derived, StateId, Transitions...> |
Public Member Functions | |
Statemachine () | |
virtual | ~Statemachine () |
void | start () |
template<typename Func> | |
auto | visitState (Func &&f) |
std::optional< StateId > | currentState () const |
std::optional< StateId > | previousState () const |
template<typename T> | |
std::shared_ptr< T > | state () |
template<typename T> | |
const std::shared_ptr< T > | state () const |
template<typename NewState> | |
void | forceState (std::unique_ptr< NewState > &&nS) |
SignalProxy< void()> | sigFinished () |
SignalProxy< void(StateId)> | sigStateChanged () |
Protected Member Functions | |
template<typename OldState, typename NewState> | |
void | enterState (OldState &os, NewState &&nS) |
template<typename NewState> | |
void | enterState (NewState &&nS) |
template<typename State, typename Transition> | |
auto | makeEventCallback (Transition &transition) |
template<std::size_t I = 0, typename State, typename ... StateTrans> | |
void | connectAllTransitions (State &&nS, std::tuple< StateTrans... > &transitions) |
void | clearConnections () |
Private Attributes | |
bool | _isInFinalState = false |
bool | _emittedFinalSig = false |
Signal< void(StateId)> | _sigStateChanged |
Signal< void()> | _sigFinished |
StateSet | _state = _InitialState() |
std::optional< StateId > | _previousState |
std::vector< sigc::connection > | _currentStateConnections |
This defines the actual StateMachine.
Derived | is the Statemachine subclass type, this is used to pass a reference to the actual implementation into the State functions. |
StateId | should be a enum with a ID for each state the SM can be in. |
Transitions | variadic template argument taking a list of all Transition types the statemachine should support. The First Source State in the Transitions List is always the initial state. |
Implementation of a simple signal based statemachine, each state is a user defined state type that has to implement a specific API in order to be compatible. No inheritance is required to use the statemachine and everything will be resolved at compile time.
This is how a basic statemachine implementation would look like
In order to advance the statemachine, each state will have at least one signal ( event ) that tells the statemachine to transition to the next state, optionally a condition can be used to block the transition in certain cases. When transitioning from one state to the other a transition operation will be called that creates the instance of the target state and do other initializations or can move data from the old to the new state. The default version of the operation just returns a new instance of the target state. If a signal or event is used multiple times to trigger transitions, only the first transition whose condition evaluates to true will be triggered. All other transitions with the same trigger signal will not be even evaluated.
After instantiating the statemachine will be in a internal intial state, in order to move to the first user defined state Statemachine::start must be called.
Definition at line 364 of file statemachine.h.
using zyppng::Statemachine< Derived, StateId, Transitions >::AllStates = typename detail::make_state_set< Transitions... >::Type |
Definition at line 370 of file statemachine.h.
using zyppng::Statemachine< Derived, StateId, Transitions >::StateSetHelper = typename detail::make_statewithtransition_set< _InitialState, AllStates, Transitions... > |
Definition at line 371 of file statemachine.h.
using zyppng::Statemachine< Derived, StateId, Transitions >::FState = typename StateSetHelper::FirstState |
Definition at line 372 of file statemachine.h.
using zyppng::Statemachine< Derived, StateId, Transitions >::StateSet = typename StateSetHelper::Type |
Definition at line 373 of file statemachine.h.
using zyppng::Statemachine< Derived, StateId, Transitions >::StatemachineType = Statemachine< Derived, StateId, Transitions...> |
Definition at line 375 of file statemachine.h.
|
inline |
Definition at line 378 of file statemachine.h.
|
inlinevirtual |
Definition at line 379 of file statemachine.h.
|
inline |
Advances the state machine into the initial state.
Definition at line 384 of file statemachine.h.
|
inline |
Definition at line 394 of file statemachine.h.
|
inline |
Returns the current stateId of the state the SM is currently in. If called before start() was called the std::optional will be empty
Definition at line 410 of file statemachine.h.
|
inline |
Returns the ID of the previous state, or a invalid optional if there was no previous state.
Definition at line 425 of file statemachine.h.
|
inline |
Returns a reference to the current state object, will throw a exception if the passed state type does not match the current states type.
Definition at line 434 of file statemachine.h.
|
inline |
Returns a reference to the current state object, will throw a exception if the passed state type does not match the current states type.
Definition at line 444 of file statemachine.h.
|
inline |
Forces the statemachine to enter a specific state, a transition operation will not be executed, but the exit() function of the current state will be called.
Definition at line 454 of file statemachine.h.
|
inline |
Emitted when the statemachine enters a type that has final set to true.
Definition at line 471 of file statemachine.h.
|
inline |
Emitted everytime the statemachine advanced to a new state, carrying the new state's ID.
Definition at line 481 of file statemachine.h.
|
inlineprotected |
Definition at line 488 of file statemachine.h.
|
inlineprotected |
Definition at line 497 of file statemachine.h.
|
inlineprotected |
Definition at line 526 of file statemachine.h.
|
inlineprotected |
Definition at line 538 of file statemachine.h.
|
inlineprotected |
Definition at line 549 of file statemachine.h.
|
private |
Definition at line 556 of file statemachine.h.
|
private |
Definition at line 557 of file statemachine.h.
|
private |
Definition at line 558 of file statemachine.h.
|
private |
Definition at line 559 of file statemachine.h.
|
private |
Definition at line 560 of file statemachine.h.
|
private |
Definition at line 561 of file statemachine.h.
|
private |
Definition at line 562 of file statemachine.h.