Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
Singleton.h
Go to the documentation of this file.
1
//
2
//C++ Template: Singleton<T>
3
//
4
#ifndef __SINGLETON_H__INCLUDED__
5
#define __SINGLETON_H__INCLUDED__
6
7
namespace
InitializationFunctors
8
{
9
template
<
typename
T >
10
class
DefaultConstructor
11
{
12
public
:
13
T*
operator()
()
const
14
{
15
return
new
T();
16
}
17
};
18
};
19
32
template
<
typename
T,
typename
INIT = InitializationFunctors::DefaultConstructor< T > >
33
class
Singleton
34
{
35
protected
:
36
static
T *
_singletonInstance
;
37
38
static
void
initializeSingleton
()
39
{
40
if
(
_singletonInstance
!= 0)
41
delete
_singletonInstance
;
42
//GCC 3.3 errors out if you do '(INIT())()'
43
INIT singletonConstructor;
44
_singletonInstance
= singletonConstructor();
45
}
46
47
static
void
deinitializeSingleton
()
48
{
49
_singletonInstance
= 0;
50
}
51
52
~Singleton
()
53
{
54
if
(
_singletonInstance
==
this
)
55
deinitializeSingleton
();
56
}
57
58
public
:
59
static
T *
getSingleton
()
60
{
61
if
(
_singletonInstance
== 0)
62
initializeSingleton
();
63
return
_singletonInstance
;
64
}
65
};
66
67
#endif //__SINGLETON_H__INCLUDED__
68
src
Singleton.h
Generated on Fri May 29 2015 23:07:38 for Vegastrike 0.5.1 rc1 by
1.8.4