libassa
3.5.1
assa
Singleton.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// Singleton.h
4
//------------------------------------------------------------------------------
5
// Copyright (C) 1997-2002,2005 Vladislav Grinchenko
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Library General Public
9
// License as published by the Free Software Foundation; either
10
// version 2 of the License, or (at your option) any later version.
11
//------------------------------------------------------------------------------
12
// Created: 02/22/99
13
//------------------------------------------------------------------------------
14
#ifndef _Singleton_h
15
#define _Singleton_h
16
17
#include "
Destroyer.h
"
18
19
namespace
ASSA
{
20
41
template
<
class
T>
42
class
Singleton
43
{
44
public
:
46
47
static
T*
get_instance
() {
48
if
(
m_instance
== 0) {
49
m_instance
=
new
T;
50
m_destroyer
.setGuard (
m_instance
);
51
}
52
return
m_instance
;
53
}
54
55
protected
:
57
Singleton
() {}
58
59
friend
class
Destroyer
<T>;
60
62
virtual
~Singleton
() {}
63
64
private
:
66
static
T*
m_instance
;
67
69
static
Destroyer<T>
m_destroyer
;
70
};
71
72
}
// end namespace ASSA
73
74
82
#define ASSA_DECL_SINGLETON(K) \
83
template <> K* ASSA::Singleton<K>::m_instance = NULL; \
84
template <class T> ASSA::Destroyer<T> ASSA::Singleton<T>::m_destroyer; \
85
template ASSA::Destroyer<K> ASSA::Singleton<K>::m_destroyer;
86
87
#endif
ASSA::Singleton::Singleton
Singleton()
Protected Constructor.
Definition:
Singleton.h:57
ASSA::Singleton::~Singleton
virtual ~Singleton()
Virtual Destructor.
Definition:
Singleton.h:62
ASSA::Singleton::get_instance
static T * get_instance()
Return an instance of templated class T.
Definition:
Singleton.h:47
Destroyer.h
ASSA::Singleton::m_destroyer
static Destroyer< T > m_destroyer
Destroyer that owns object T.
Definition:
Singleton.h:69
ASSA::Singleton
Definition:
Singleton.h:42
ASSA::Destroyer
Definition:
Destroyer.h:24
ASSA
Definition:
Acceptor.h:40
ASSA::Singleton::m_instance
static T * m_instance
Pointer to the object T instance.
Definition:
Singleton.h:66
Generated by
1.8.17