Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Singleton.hxx
Go to the documentation of this file.
1
36
#ifndef _UTILS_SINGLETON_HXX_
37
#define _UTILS_SINGLETON_HXX_
38
39
#include "
utils/macros.h
"
40
65
template
<
class
T>
class
Singleton
{
66
public
:
67
Singleton
() {
68
HASSERT
(
instance_
==
nullptr
);
69
instance_
=
static_cast<
T*
>
(
this
);
70
}
71
72
~Singleton
() {
73
instance_
=
nullptr
;
74
}
75
77
static
T*
instance
() {
78
HASSERT
(
instance_
!=
nullptr
);
79
return
instance_
;
80
}
81
83
static
bool
exists
() {
84
return
(
instance_
!=
nullptr
);
85
}
86
87
private
:
89
static
T*
instance_
;
90
};
91
92
template
<
class
T> T*
Singleton<T>::instance_
=
nullptr
;
93
98
#define DEFINE_SINGLETON_INSTANCE(T) template<> T* Singleton<T>::instance_ = nullptr
99
100
#endif
// _UTILS_SINGLETON_HXX_
101
Singleton
Singleton class.
Definition
Singleton.hxx:65
Singleton::instance
static T * instance()
Definition
Singleton.hxx:77
Singleton::instance_
static T * instance_
The singleton instance pointer.
Definition
Singleton.hxx:89
Singleton::exists
static bool exists()
Definition
Singleton.hxx:83
macros.h
HASSERT
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition
macros.h:138
src
utils
Singleton.hxx
Generated on Sun Feb 2 2025 21:18:14 for Open Model Railroad Network (OpenMRN) by
1.9.8