#include <icy/singleton.h>Helper template class for managing singleton objects allocated on the heap.
| Return | Name | Description |
|---|---|---|
Singleton | Defaulted constructor. | |
S * | get inline | Returns a pointer to the managed singleton, instantiating it on first call. Thread-safe; protected by an internal mutex. |
S * | swap inline | 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. |
void | destroy inline | Destroys the managed singleton instance and resets the internal pointer to null. Thread-safe; protected by an internal mutex. |
Singleton() = defaultDefaulted constructor.
inline
inline S * get()Returns a pointer to the managed singleton, instantiating it on first call. Thread-safe; protected by an internal mutex.
Pointer to the singleton instance (never null).
inline
inline S * swap(S * newPtr)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.
newPtr Replacement instance (may be nullptr).Previously managed pointer (caller must delete if non-null).
inline
inline void destroy()Destroys the managed singleton instance and resets the internal pointer to null. Thread-safe; protected by an internal mutex.
std::unique_ptr< S, Deleter > _ptrstd::mutex _m