A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
simulation-singleton.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#ifndef SIMULATION_SINGLETON_H
21
#define SIMULATION_SINGLETON_H
22
23
namespace
ns3 {
24
32
template
<
typename
T>
33
class
SimulationSingleton
34
{
35
public
:
42
static
T *
Get
(
void
);
43
private
:
44
static
T **
GetObject
(
void
);
45
static
void
DeleteObject
(
void
);
46
};
47
48
}
// namespace ns3
49
50
51
#include "
simulator.h
"
52
53
namespace
ns3 {
54
55
template
<
typename
T>
56
T *
57
SimulationSingleton<T>::Get
(
void
)
58
{
59
T ** ppobject = GetObject ();
60
return
*ppobject;
61
}
62
63
template
<
typename
T>
64
T **
65
SimulationSingleton<T>::GetObject
(
void
)
66
{
67
static
T *pobject = 0;
68
if
(pobject == 0)
69
{
70
pobject =
new
T ();
71
Simulator::ScheduleDestroy
(&
SimulationSingleton<T>::DeleteObject
);
72
}
73
return
&pobject;
74
}
75
76
template
<
typename
T>
77
void
78
SimulationSingleton<T>::DeleteObject
(
void
)
79
{
80
T **ppobject = GetObject ();
81
delete
(*ppobject);
82
*ppobject = 0;
83
}
84
85
}
// namespace ns3
86
87
88
#endif
/* SIMULATION_SINGLETON_H */
ns3::SimulationSingleton
This singleton class template ensures that the type for which we want a singleton has a lifetime boun...
Definition:
simulation-singleton.h:33
simulator.h
ns3::SimulationSingleton::DeleteObject
static void DeleteObject(void)
Definition:
simulation-singleton.h:78
ns3::SimulationSingleton::Get
static T * Get(void)
Definition:
simulation-singleton.h:57
ns3::SimulationSingleton::GetObject
static T ** GetObject(void)
Definition:
simulation-singleton.h:65
ns3::Simulator::ScheduleDestroy
static EventId ScheduleDestroy(MEM mem_ptr, OBJ obj)
Schedule an event to expire at Destroy time.
Definition:
simulator.h:1076
src
core
model
simulation-singleton.h
Generated on Sat Apr 19 2014 14:06:52 for ns-3 by
1.8.6