carl  24.04
Computer ARithmetic Library
carl::Singleton< T > Class Template Reference

Base class that implements a singleton. More...

#include <Singleton.h>

Inheritance diagram for carl::Singleton< T >:

Public Member Functions

 Singleton (const Singleton &)=delete
 
 Singleton (Singleton &&)=delete
 
Singletonoperator= (const Singleton &)=delete
 
Singletonoperator= (Singleton &&)=delete
 
virtual ~Singleton () noexcept=default
 Virtual destructor. More...
 

Static Public Member Functions

static T & getInstance ()
 Returns the single instance of this class by reference. More...
 

Protected Member Functions

 Singleton ()=default
 Protected default constructor. More...
 

Detailed Description

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

Base class that implements a singleton.

A class that shall be a singleton can inherit from this class (the template argument being the class itself, see CRTP for this). It takes care of

  • deleting the copy constructor and the assignment operator,
  • providing a protected default constructor and a virtual destructor and
  • providing getInstance() that returns the one single object of this type.

Definition at line 23 of file Singleton.h.

Constructor & Destructor Documentation

◆ Singleton() [1/3]

template<typename T >
carl::Singleton< T >::Singleton ( )
protecteddefault

Protected default constructor.

◆ Singleton() [2/3]

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

◆ Singleton() [3/3]

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

◆ ~Singleton()

template<typename T >
virtual carl::Singleton< T >::~Singleton ( )
virtualdefaultnoexcept

Virtual destructor.

Member Function Documentation

◆ getInstance()

template<typename T >
static T& carl::Singleton< T >::getInstance ( )
inlinestatic

Returns the single instance of this class by reference.

If there is no instance yet, a new one is created.

Definition at line 45 of file Singleton.h.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

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