CppCommon  1.0.4.1
C++ Common Library
Public Member Functions | Static Public Member Functions | List of all members
CppCommon::Singleton< T > Class Template Reference

Singleton template base class. More...

#include <singleton.h>

Public Member Functions

 Singleton (const Singleton &)=delete
 
 Singleton (Singleton &&)=delete
 
Singletonoperator= (const Singleton &)=delete
 
Singletonoperator= (Singleton &&)=delete
 

Static Public Member Functions

static T & GetInstance ()
 Get singleton instance. More...
 

Detailed Description

template<typename T>
class CppCommon::Singleton< T >

Singleton template base class.

Singleton base class is used to protect child class from being created multiple times and provide a static GetInstance() method to access the single instance.

Thread-safe.

Example:

class MySingleton : public CppCommon::Singleton<MySingleton>
{
public:
void Test() { ... }
private:
MySingleton() = default;
~MySingleton() = default;
};
int main(int argc, char** argv)
{
MySingleton::GetInstance().Test();
return 0;
}
Singleton template base class.
Definition: singleton.h:47

https://en.wikipedia.org/wiki/Singleton_pattern

Examples
utility_singleton.cpp.

Definition at line 46 of file singleton.h.

Constructor & Destructor Documentation

◆ Singleton() [1/2]

template<typename T >
CppCommon::Singleton< T >::Singleton ( const Singleton< T > &  )
delete

◆ Singleton() [2/2]

template<typename T >
CppCommon::Singleton< T >::Singleton ( Singleton< T > &&  )
delete

Member Function Documentation

◆ GetInstance()

template<typename T >
static T& CppCommon::Singleton< T >::GetInstance ( )
inlinestatic

Get singleton instance.

Returns
Singleton instance

Definition at line 61 of file singleton.h.

◆ operator=() [1/2]

template<typename T >
Singleton& CppCommon::Singleton< T >::operator= ( const Singleton< T > &  )
delete

◆ operator=() [2/2]

template<typename T >
Singleton& CppCommon::Singleton< T >::operator= ( Singleton< T > &&  )
delete

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