A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
singleton.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007 INRIA
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
*/
19
#ifndef SINGLETON_H
20
#define SINGLETON_H
21
28
namespace
ns3
29
{
30
59
template
<
typename
T>
60
class
Singleton
61
{
62
public
:
63
// Delete copy constructor and assignment operator to avoid misuse
64
Singleton
(
const
Singleton<T>
&) =
delete
;
65
Singleton
&
operator=
(
const
Singleton<T>
&) =
delete
;
66
75
static
T*
Get
();
76
77
protected
:
79
Singleton
()
80
{
81
}
82
84
virtual
~Singleton
()
85
{
86
}
87
};
88
89
}
// namespace ns3
90
91
/********************************************************************
92
* Implementation of the templates declared above.
93
********************************************************************/
94
95
namespace
ns3
96
{
97
98
template
<
typename
T>
99
T*
100
Singleton<T>::Get
()
101
{
102
static
T
object
;
103
return
&
object
;
104
}
105
106
}
// namespace ns3
107
108
#endif
/* SINGLETON_H */
ns3::Singleton
A template singleton.
Definition:
singleton.h:61
ns3::Singleton::Singleton
Singleton(const Singleton< T > &)=delete
ns3::Singleton::Get
static T * Get()
Get a pointer to the singleton instance.
Definition:
singleton.h:100
ns3::Singleton::Singleton
Singleton()
Constructor.
Definition:
singleton.h:79
ns3::Singleton::~Singleton
virtual ~Singleton()
Destructor.
Definition:
singleton.h:84
ns3::Singleton::operator=
Singleton & operator=(const Singleton< T > &)=delete
object
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
model
singleton.h
Generated on Sun Mar 3 2024 17:10:55 for ns-3 by
1.9.1