ECSM v0.2.0
Singleton< T, UseManager >

Base singleton class. More...

#include <singleton.hpp>

Public Types

typedef Singleton< T, UseManager > Instance
 Singleton class type.
 

Static Public Member Functions

static bool has ()
 Returns true if class singleton or manager instance is exist.
 
static T * get ()
 Returns class singleton or manager instance.
 
static T * tryGet ()
 Returns class singleton or manager instance if exist.
 

Protected Member Functions

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

Static Protected Attributes

static T * singletonInstance = nullptr
 Singleton class instance.
 

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

Constructor & Destructor Documentation

◆ Singleton()

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

Creates a new singleton class instace.

Parameters
setis singleton instance should be set