Base module

Singleton

Helper template class for managing singleton objects allocated on the heap.

#include <icy/singleton.h>

template<class S>
class Singleton

Defined in src/base/include/icy/singleton.h:24

Public Methods

ReturnNameDescription
SingletonDefaulted constructor.
~SingletonDefaulted destructor.
S *get inlineReturns a pointer to the managed singleton, instantiating it on first call. Thread-safe; protected by an internal mutex.
S *swap inlineReplaces the managed singleton with newPtr and returns the previous instance. The caller takes ownership of the returned pointer. Thread-safe; protected by an internal mutex.
voiddestroy inlineDestroys the managed singleton instance and resets the internal pointer to null. Thread-safe; protected by an internal mutex.

Singleton

Singleton() = default

Defined in src/base/include/icy/singleton.h:27

Defaulted constructor.


~Singleton

~Singleton() = default

Defined in src/base/include/icy/singleton.h:29

Defaulted destructor.


get

inline

inline S * get()

Defined in src/base/include/icy/singleton.h:34

Returns a pointer to the managed singleton, instantiating it on first call. Thread-safe; protected by an internal mutex.

Returns

Pointer to the singleton instance (never null).


swap

inline

inline S * swap(S * newPtr)

Defined in src/base/include/icy/singleton.h:47

Replaces the managed singleton with newPtr and returns the previous instance. The caller takes ownership of the returned pointer. Thread-safe; protected by an internal mutex.

Returns

Previously managed pointer (caller must delete if non-null).

Parameters

ParameterTypeDescription
newPtrS *Replacement instance (may be nullptr).

destroy

inline

inline void destroy()

Defined in src/base/include/icy/singleton.h:57

Destroys the managed singleton instance and resets the internal pointer to null. Thread-safe; protected by an internal mutex.

Private Attributes

ReturnNameDescription
std::unique_ptr< S, Deleter >_ptr
std::mutex_m

_ptr

std::unique_ptr< S, Deleter > _ptr

Defined in src/base/include/icy/singleton.h:70


_m

std::mutex _m

Defined in src/base/include/icy/singleton.h:71