vsdk 11.0.1
Loading...
Searching...
No Matches
Vsdk::Utils::Singleton< T >

Generic CRTP singleton abstraction. More...

#include <Singleton.hpp>

Static Public Member Functions

template<typename... Args>
static T & init (Args &&... args)
static bool hasInstance ()
static T & instance ()
static void destroy ()

Protected Member Functions

 Singleton ()=default

Detailed Description

template<typename T>
class Vsdk::Utils::Singleton< T >

Generic CRTP singleton abstraction.

Note
To correctly disable publicly constructing instances, T's constructors and destroy should not be public. You then need to friend this class and the std::default_delete<T> class to prevent compilation errors.

Constructor & Destructor Documentation

◆ Singleton()

template<typename T>
Vsdk::Utils::Singleton< T >::Singleton ( )
protecteddefault

Member Function Documentation

◆ init()

template<typename T>
template<typename... Args>
T & Vsdk::Utils::Singleton< T >::init ( Args &&... args)
static
Exceptions
Exceptionif called in initialized state to prevent silent destruction of previous instance.

◆ hasInstance()

template<typename T>
bool Vsdk::Utils::Singleton< T >::hasInstance ( )
static
Returns
true if already initialized, else false.

◆ instance()

template<typename T>
T & Vsdk::Utils::Singleton< T >::instance ( )
static
Exceptions
Exceptionwhen called in uninitialized state.

◆ destroy()

template<typename T>
void Vsdk::Utils::Singleton< T >::destroy ( )
static
Note
Can be called even if not initialized.