JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
Singleton< T > Class Template Reference

Inherit from this class to create a singleton that will be destroyed when your games exits. More...

#include <jngl/Singleton.hpp>

Public Member Functions

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

Static Public Member Functions

static T & handle ()
 Creates the Singleton if needed.
 
static T * handleIfAlive () noexcept
 Doesn't create the Singleton, may return nullptr.
 
static void destroy () noexcept
 Deletes the Singleton.
 

Detailed Description

template<class T>
class jngl::Singleton< T >

Inherit from this class to create a singleton that will be destroyed when your games exits.

You should use this instead of global / static variables, because some platforms (Android) don't destroy the process on exit and instead re-enter the main function.

class Foo : public jngl::Singleton<Foo>
// ...
}
// somewhere else:
Foo::handle().bar();
Inherit from this class to create a singleton that will be destroyed when your games exits.
Definition Singleton.hpp:23

Definition at line 23 of file Singleton.hpp.

Member Function Documentation

◆ handle()

template<class T >
static T & handle ( )
inlinestatic

Creates the Singleton if needed.

Definition at line 32 of file Singleton.hpp.

◆ handleIfAlive()

template<class T >
static T * handleIfAlive ( )
inlinestaticnoexcept

Doesn't create the Singleton, may return nullptr.

Definition at line 41 of file Singleton.hpp.

◆ destroy()

template<class T >
static void destroy ( )
inlinestaticnoexcept

Deletes the Singleton.

Definition at line 46 of file Singleton.hpp.


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