Radium Engine
1.5.20
Toggle main menu visibility
Main Page
Related Pages
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
f
g
i
l
m
n
o
p
q
r
s
t
v
z
Functions
a
c
d
f
g
i
l
m
n
o
p
q
r
s
t
v
Variables
Typedefs
Enumerations
Enumerator
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
~
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
~
Variables
b
d
f
i
m
s
v
w
Typedefs
a
b
c
f
g
i
k
o
r
s
t
v
Enumerations
Enumerator
Related Symbols
Files
File List
File Members
All
Macros
▼
Radium Engine
►
Radium Basics
►
Radium Concepts
►
Developer manual
►
Licenses
Todo List
Deprecated List
►
Namespaces
►
Classes
▼
Files
▼
File List
▼
src
▼
Core
►
Animation
►
Asset
►
Containers
►
Geometry
►
Math
►
Resources
►
Tasks
▼
Utils
Attribs.cpp
Attribs.hpp
BijectiveAssociation.hpp
Chronometer.hpp
CircularIndex.cpp
CircularIndex.hpp
Color.cpp
Color.hpp
ContainerIntrospectionInterface.hpp
EnumConverter.hpp
Index.hpp
IndexedObject.hpp
IndexMap.hpp
Log.hpp
ObjectWithSemantic.hpp
Observable.hpp
Singleton.hpp
StackTrace.cpp
StackTrace.hpp
StdExperimentalTypeTraits.hpp
StdFilesystem.hpp
►
StdMapIterators.hpp
StdOptional.hpp
StdUtils.hpp
StringUtils.cpp
StringUtils.hpp
Timer.hpp
TypesUtils.cpp
TypesUtils.hpp
Version.hpp
CoreMacros.hpp
pch.hpp
RaCore.hpp
Types.hpp
►
Engine
►
Gui
►
Headless
►
IO
►
PluginBase
►
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Loading...
Searching...
No Matches
Singleton.hpp
1
#pragma once
2
3
#include <Core/RaCore.hpp>
4
5
#include <memory>
6
7
// Singleton utility.
8
// This file give you two macros to automatically implement a class
9
// as a singleton.
10
// I used to be a template like you, then I took a DLL to the knee...
11
12
// Usage : The singleton instance is initially set to null.
13
// To create the instance, call `createInstance( )` with the
14
// class constructor arguments.
15
// To access the singleton instance, call getInstance().
16
// The singleton instance can also be destroyed (reset to null).
17
21
#define RA_SINGLETON_INTERFACE( TYPE ) \
22
protected: \
23
TYPE( const TYPE& ) = delete; \
24
void operator=( const TYPE& ) = delete; \
25
struct Deleter { \
26
void operator()( TYPE* p ) const { \
27
delete p; \
28
} \
29
}; \
30
static std::unique_ptr<TYPE, Deleter> s_instance; \
31
\
32
public: \
33
template <typename... Args> \
34
inline static TYPE* createInstance( const Args&... args ) { \
35
s_instance = std::unique_ptr<TYPE, Deleter>( new TYPE( args... ), Deleter() ); \
36
return getInstance(); \
37
} \
38
inline static TYPE* getInstance() { \
39
return s_instance.get(); \
40
} \
41
inline static void destroyInstance() { \
42
s_instance.reset( nullptr ); \
43
}
44
46
// Limitations : TYPE cannot be a nested type
47
// RA_SINGLETON_IMPLEMENTATION(A::MySingleton); will *not* work.
48
#define RA_SINGLETON_IMPLEMENTATION( TYPE ) \
49
std::unique_ptr<TYPE, TYPE::Deleter> TYPE::s_instance = nullptr; \
50
class TYPE
51
// The line above is just there to make the macro end with a ;
src
Core
Utils
Singleton.hpp
Generated by
1.12.0