Cbeam
Loading...
Searching...
No Matches
cbeam::lifecycle::singleton_control Class Referenceabstract

Base class for controlling the lifecycle of all singleton instances across different types. More...

#include <singleton.hpp>

Inheritance diagram for cbeam::lifecycle::singleton_control:

Public Member Functions

virtual ~singleton_control ()=default
 

Static Public Member Functions

static void reset ()
 Resets (shuts down) all stored singleton instances.
 
static void set_operational ()
 Ends the shut-down state and allows singletons to be created again.
 

Protected Member Functions

virtual void release_instance ()=0
 Releases the internal resource of the derived singleton. Called during a global reset.
 

Static Protected Attributes

static std::map< std::string, std::unique_ptr< singleton_control > > _instances
 
static std::mutex _mutex
 
static bool _shutdown {false}
 

Detailed Description

Base class for controlling the lifecycle of all singleton instances across different types.

singleton_control allows a coordinated reset or shutdown of multiple resources that are each managed by singleton<T, ...>. This is achieved by storing all instances in a static map and providing methods to reset or to set the operational state.

Constructor & Destructor Documentation

◆ ~singleton_control()

virtual cbeam::lifecycle::singleton_control::~singleton_control ( )
virtualdefault

Member Function Documentation

◆ release_instance()

virtual void cbeam::lifecycle::singleton_control::release_instance ( )
protectedpure virtual

Releases the internal resource of the derived singleton. Called during a global reset.

Implemented in cbeam::lifecycle::singleton< T, Args >.

◆ reset()

static void cbeam::lifecycle::singleton_control::reset ( )
inlinestatic

Resets (shuts down) all stored singleton instances.

After calling reset(), new calls to singleton<T>::get(...) will return nullptr until set_operational() is called. This is a global, collective approach for explicitly destroying all singletons and freeing their resources in a controlled manner.

◆ set_operational()

static void cbeam::lifecycle::singleton_control::set_operational ( )
inlinestatic

Ends the shut-down state and allows singletons to be created again.

Particularly useful in test scenarios where you want to re-initialize singletons after a global teardown.

Member Data Documentation

◆ _instances

std::map<std::string, std::unique_ptr<singleton_control> > cbeam::lifecycle::singleton_control::_instances
inlinestaticprotected

◆ _mutex

std::mutex cbeam::lifecycle::singleton_control::_mutex
inlinestaticprotected

◆ _shutdown

bool cbeam::lifecycle::singleton_control::_shutdown {false}
inlinestaticprotected

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