Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::StatefulObject< TType > Class Template Reference

Tracks a state value and triggers callbacks per-state. More...

#include <spk_stateful_object.hpp>

Collaboration diagram for spk::StatefulObject< TType >:
Collaboration graph

Public Types

using Contract = ContractProvider::Contract
 Handle allowing subscribers to manage callback lifetimes.
using Job = ContractProvider::Job
 Callable invoked when the object transitions to a state.

Public Member Functions

 StatefulObject (const TType &p_initialState)
 Builds with an initial state.
 StatefulObject (const StatefulObject &p_other)=delete
StatefulObjectoperator= (const StatefulObject &p_other)=delete
 StatefulObject (StatefulObject &&p_other) noexcept
 Move-constructs, transferring state and callbacks.
StatefulObjectoperator= (StatefulObject &&p_other) noexcept
 Move-assigns, transferring state and callbacks.
void setState (const TType &p_newState)
 Sets a new state and triggers callbacks registered for it.
TType state () const
 Returns the current state.
Contract addCallback (const TType &p_state, const Job &p_callback)
 Subscribes a callback for a specific state.

Detailed Description

template<typename TType>
class spk::StatefulObject< TType >

Tracks a state value and triggers callbacks per-state.

Template Parameters
TTypeState type (hashable for map keys).

Constructor & Destructor Documentation

◆ StatefulObject() [1/2]

template<typename TType>
spk::StatefulObject< TType >::StatefulObject ( const TType & p_initialState)
inline

Builds with an initial state.

Parameters
p_initialStateInitial state value.

◆ StatefulObject() [2/2]

template<typename TType>
spk::StatefulObject< TType >::StatefulObject ( StatefulObject< TType > && p_other)
inlinenoexcept

Move-constructs, transferring state and callbacks.

Parameters
p_otherSource object.

Member Function Documentation

◆ addCallback()

template<typename TType>
Contract spk::StatefulObject< TType >::addCallback ( const TType & p_state,
const Job & p_callback )
inline

Subscribes a callback for a specific state.

Parameters
p_stateState for which to run the callback.
p_callbackCallback to execute.
Returns
Contract managing the subscription.
Here is the caller graph for this function:

◆ operator=()

template<typename TType>
StatefulObject & spk::StatefulObject< TType >::operator= ( StatefulObject< TType > && p_other)
inlinenoexcept

Move-assigns, transferring state and callbacks.

Parameters
p_otherSource object.
Returns
*this.

◆ setState()

template<typename TType>
void spk::StatefulObject< TType >::setState ( const TType & p_newState)
inline

Sets a new state and triggers callbacks registered for it.

Parameters
p_newStateNew state value.
Here is the caller graph for this function:

◆ state()

template<typename TType>
TType spk::StatefulObject< TType >::state ( ) const
inline

Returns the current state.

Returns
State value.
Here is the caller graph for this function:

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