Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::ActivableObject Class Reference

Stateful helper toggling between activated/deactivated states. More...

#include <spk_activable_object.hpp>

Inheritance diagram for spk::ActivableObject:
Inheritance graph
Collaboration diagram for spk::ActivableObject:
Collaboration graph

Public Types

using Contract = StatefulObject<ActivationStatus>::Contract
 Subscription handle controlling callback lifetime.
using Job = StatefulObject<ActivationStatus>::Job
 Callback signature executed on activation state changes.
Public Types inherited from spk::StatefulObject< ActivationStatus >
using Contract
 Handle allowing subscribers to manage callback lifetimes.
using Job
 Callable invoked when the object transitions to a state.

Public Member Functions

 ActivableObject ()
 Builds a deactivated object.
 ActivableObject (ActivationStatus p_initial)
 Builds with a custom initial activation state.
void activate ()
 Sets the state to Activated.
void deactivate ()
 Sets the state to Deactivated.
void toggle ()
 Toggles between activated and deactivated states.
bool isActive () const
 Checks whether the object is currently activated.
Contract addActivationCallback (const Job &p_callback)
 Registers a callback executed when the object activates.
Contract addDeactivationCallback (const Job &p_callback)
 Registers a callback executed when the object deactivates.
Public Member Functions inherited from spk::StatefulObject< ActivationStatus >
 StatefulObject (const ActivationStatus &p_initialState)
 Builds with an initial state.
StatefulObjectoperator= (const StatefulObject &p_other)=delete
void setState (const ActivationStatus &p_newState)
 Sets a new state and triggers callbacks registered for it.
ActivationStatus state () const
 Returns the current state.
Contract addCallback (const ActivationStatus &p_state, const Job &p_callback)
 Subscribes a callback for a specific state.

Detailed Description

Stateful helper toggling between activated/deactivated states.

See also
StatefulObject
auto contract = obj.addActivationCallback([]{ onActivate(); });
obj.activate();
Stateful helper toggling between activated/deactivated states.
Definition spk_activable_object.hpp:20
Contract addActivationCallback(const Job &p_callback)
Registers a callback executed when the object activates.
Definition spk_activable_object.hpp:87
void activate()
Sets the state to Activated.
Definition spk_activable_object.hpp:54

Constructor & Destructor Documentation

◆ ActivableObject()

spk::ActivableObject::ActivableObject ( ActivationStatus p_initial)
inlineexplicit

Builds with a custom initial activation state.

Parameters
p_initialInitial state.
Here is the call graph for this function:

Member Function Documentation

◆ addActivationCallback()

Contract spk::ActivableObject::addActivationCallback ( const Job & p_callback)
inline

Registers a callback executed when the object activates.

Parameters
p_callbackFunction to run.
Returns
Contract to manage the subscription.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addDeactivationCallback()

Contract spk::ActivableObject::addDeactivationCallback ( const Job & p_callback)
inline

Registers a callback executed when the object deactivates.

Parameters
p_callbackFunction to run.
Returns
Contract to manage the subscription.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isActive()

bool spk::ActivableObject::isActive ( ) const
inline

Checks whether the object is currently activated.

Returns
true when state is Activated.
Here is the call graph for this function:
Here is the caller graph for this function:

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