ECSM v0.7.0
Entity Component System Manager
Loading...
Searching...
No Matches

Base singleton class. More...

#include <singleton.hpp>

Public Types

typedef T ItemType

Static Public Member Functions

static bool hasInstance ()
 Returns true if class singleton or manager instance is exist.
static T * getInstance ()
 Returns class singleton or manager instance.
static T * tryGetInstance ()
 Returns class singleton or manager instance if exists.

Protected Member Functions

 Singleton (bool set=true)
 Creates a new singleton class instance.
virtual ~Singleton ()
 Destroys singleton class instance.
void setSingleton ()
 Sets a new class singleton instance.
void unsetSingleton () noexcept
 Unsets this class singleton instance.

Static Protected Attributes

static T * singletonInstance = nullptr

Detailed Description

template<class T, bool UseManager = true>
class ecsm::Singleton< T, UseManager >

Base singleton class.

Singleton class is a class designed in such a way that only one instance of it can exist during the runtime of the game or application. This pattern is often used to manage systems or resources that need to be globally accessible, without having multiple copies floating around, which could lead to resource inefficiency or bugs.

Template Parameters
Ttype of the singleton class
UseManageruse manager system instance if singleton is not set

Member Typedef Documentation

◆ ItemType

template<class T, bool UseManager = true>
typedef T ItemType

Type of the singleton class.

Constructor & Destructor Documentation

◆ Singleton()

template<class T, bool UseManager = true>
Singleton ( bool set = true)
inlineprotected

Creates a new singleton class instance.

Parameters
setis singleton instance should be set

◆ ~Singleton()

template<class T, bool UseManager = true>
virtual ~Singleton ( )
inlineprotectedvirtual

Destroys singleton class instance.

Note
It also unsets singleton if it's the same as this system.

Member Data Documentation

◆ singletonInstance

template<class T, bool UseManager = true>
T* singletonInstance = nullptr
inlinestaticprotected

Singleton class instance.