Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::Singleton< Derived > Class Template Reference

#include <Singleton.h>

Public Member Functions

 Singleton (const Singleton &)=delete
 Copy constructor is deleted to prevent duplicating the singleton instance.
 
Singletonoperator= (const Singleton &)=delete
 Assignment operator is deleted to prevent duplicating the singleton instance.
 

Static Public Member Functions

static Derived & getInstance ()
 Gets the singleton instance of the derived class.
 

Protected Member Functions

 Singleton ()=default
 Default constructor is protected to prevent instantiation outside of derived classes.
 
 ~Singleton ()=default
 Default destructor is protected to prevent deletion through base class pointer.
 

Constructor & Destructor Documentation

◆ Singleton() [1/2]

template<typename Derived>
uniot::Singleton< Derived >::Singleton ( const Singleton< Derived > & )
delete

Copy constructor is deleted to prevent duplicating the singleton instance.

◆ Singleton() [2/2]

template<typename Derived>
uniot::Singleton< Derived >::Singleton ( )
protecteddefault

Default constructor is protected to prevent instantiation outside of derived classes.

Derived classes should declare Singleton as a friend class to allow instantiation while keeping their constructors protected or private.

◆ ~Singleton()

template<typename Derived>
uniot::Singleton< Derived >::~Singleton ( )
protecteddefault

Default destructor is protected to prevent deletion through base class pointer.

Member Function Documentation

◆ getInstance()

template<typename Derived>
static Derived & uniot::Singleton< Derived >::getInstance ( )
inlinestatic

Gets the singleton instance of the derived class.

This method creates the instance on first call (lazy initialization) and returns a reference to it on all subsequent calls. The instance is created as a static variable, ensuring thread-safe initialization in C++11 and above.

Return values
Derived&Reference to the singleton instance of the derived class

◆ operator=()

template<typename Derived>
Singleton & uniot::Singleton< Derived >::operator= ( const Singleton< Derived > & )
delete

Assignment operator is deleted to prevent duplicating the singleton instance.


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