DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Util::StateMachineContext< StateMachineStateT > Class Template Reference

State machine context as used by class StateMachine. A state machine context holds a map with keys and values of unique state identifiers of type StateEnumType (refer to class StateMachineState). Each map entry indicates a state (key) to be replaced by another state (value). StateMachine::Invoke checks the state identifiers returned by StateMachineState::Invoke and possibly replaces them according to the current context before setting the new state machine state. Contexts can be derived from base contexts unifying and including their replacement lists. More...

Public Types

using StateType = StateMachineStateT
 
using StateEnumType = typename StateType::StateEnumType
 Refer to class StateMachineState. More...
 
using ReplacementListType = std::unordered_map< StateEnumType, StateEnumType >
 

Public Member Functions

 StateMachineContext ()=default
 Default constructor constructs an empty context not performing any state replacement. More...
 
 StateMachineContext (ReplacementListType &&ReplacementList, const char *Description="", std::initializer_list< const StateMachineContext * > BaseContexts={})
 Constructs a StateMachineContext from a replacement list appending the replacement lists of each context in BaseContexts. More...
 
constexpr auto GetDescription () const noexcept
 Returns the context's description. More...
 
StateEnumType AdaptState (StateEnumType State) const
 Checks whether the context contains a replacement entry for the state identified by State and returns the identifier of the state to replace State with. More...
 

Private Attributes

ReplacementListType ReplacementList
 Within this context, the map's key states are replaced by the corresponding value states. The list must not be modified after the StateMachineContext's constructor has run. More...
 
const char * Description
 

Detailed Description

template<typename StateMachineStateT>
class Util::StateMachineContext< StateMachineStateT >

State machine context as used by class StateMachine. A state machine context holds a map with keys and values of unique state identifiers of type StateEnumType (refer to class StateMachineState). Each map entry indicates a state (key) to be replaced by another state (value). StateMachine::Invoke checks the state identifiers returned by StateMachineState::Invoke and possibly replaces them according to the current context before setting the new state machine state. Contexts can be derived from base contexts unifying and including their replacement lists.

Template Parameters
StateMachineStateTState type of type StateMachineState the state machine operates on

Definition at line 1361 of file Util.h.

Member Typedef Documentation

◆ ReplacementListType

template<typename StateMachineStateT >
using Util::StateMachineContext< StateMachineStateT >::ReplacementListType = std::unordered_map<StateEnumType, StateEnumType>

Definition at line 1366 of file Util.h.

◆ StateEnumType

template<typename StateMachineStateT >
using Util::StateMachineContext< StateMachineStateT >::StateEnumType = typename StateType::StateEnumType

Refer to class StateMachineState.

Definition at line 1365 of file Util.h.

◆ StateType

template<typename StateMachineStateT >
using Util::StateMachineContext< StateMachineStateT >::StateType = StateMachineStateT

Definition at line 1364 of file Util.h.

Constructor & Destructor Documentation

◆ StateMachineContext() [1/2]

template<typename StateMachineStateT >
Util::StateMachineContext< StateMachineStateT >::StateMachineContext ( )
default

Default constructor constructs an empty context not performing any state replacement.

◆ StateMachineContext() [2/2]

template<typename StateMachineStateT >
Util::StateMachineContext< StateMachineStateT >::StateMachineContext ( ReplacementListType &&  ReplacementList,
const char *  Description = "",
std::initializer_list< const StateMachineContext< StateMachineStateT > * >  BaseContexts = {} 
)
inline

Constructs a StateMachineContext from a replacement list appending the replacement lists of each context in BaseContexts.

Parameters
ReplacementListMap containing the StateType to replace (keys) with other state types (values)
DescriptionHuman-readable description of what the context does
BaseContextsList of pointers to other state machine contexts this context should be derived from. If this context's replacement list already contains a specific key to replace, further tuples with the same key are ignored and not inserted. Thus, base contexts should be passed as a list ordered in descending priority.

Definition at line 1383 of file Util.h.

Member Function Documentation

◆ AdaptState()

template<typename StateMachineStateT >
StateEnumType Util::StateMachineContext< StateMachineStateT >::AdaptState ( StateEnumType  State) const
inline

Checks whether the context contains a replacement entry for the state identified by State and returns the identifier of the state to replace State with.

Parameters
StateState identifier to check for replacement
Returns
Returns a replacement of State or State itself if there is no replacement registered.

Definition at line 1404 of file Util.h.

◆ GetDescription()

template<typename StateMachineStateT >
constexpr auto Util::StateMachineContext< StateMachineStateT >::GetDescription ( ) const
inlineconstexprnoexcept

Returns the context's description.

Returns
Context's description

Definition at line 1396 of file Util.h.

Member Data Documentation

◆ Description

template<typename StateMachineStateT >
const char* Util::StateMachineContext< StateMachineStateT >::Description
private

Definition at line 1418 of file Util.h.

◆ ReplacementList

template<typename StateMachineStateT >
ReplacementListType Util::StateMachineContext< StateMachineStateT >::ReplacementList
private

Within this context, the map's key states are replaced by the corresponding value states. The list must not be modified after the StateMachineContext's constructor has run.

Definition at line 1416 of file Util.h.


The documentation for this class was generated from the following file: