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
node-list.cc
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
* Authors:
19
* Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
20
*/
21
22
#include "ns3/simulator.h"
23
#include "ns3/object-vector.h"
24
#include "ns3/config.h"
25
#include "ns3/log.h"
26
#include "ns3/assert.h"
27
#include "
node-list.h
"
28
#include "
node.h
"
29
30
namespace
ns3 {
31
32
NS_LOG_COMPONENT_DEFINE
(
"NodeList"
);
33
37
class
NodeListPriv
:
public
Object
38
{
39
public
:
40
static
TypeId
GetTypeId
(
void
);
41
NodeListPriv
();
42
~NodeListPriv
();
43
44
uint32_t
Add
(
Ptr<Node>
node);
45
NodeList::Iterator
Begin
(
void
)
const
;
46
NodeList::Iterator
End
(
void
)
const
;
47
Ptr<Node>
GetNode
(uint32_t n);
48
uint32_t
GetNNodes
(
void
);
49
50
static
Ptr<NodeListPriv>
Get
(
void
);
51
52
private
:
53
virtual
void
DoDispose
(
void
);
54
static
Ptr<NodeListPriv>
*
DoGet
(
void
);
55
static
void
Delete
(
void
);
56
std::vector<Ptr<Node> >
m_nodes
;
57
};
58
59
NS_OBJECT_ENSURE_REGISTERED
(
NodeListPriv
);
60
61
TypeId
62
NodeListPriv::GetTypeId
(
void
)
63
{
64
static
TypeId
tid =
TypeId
(
"ns3::NodeListPriv"
)
65
.
SetParent
<
Object
> ()
66
.AddAttribute (
"NodeList"
,
"The list of all nodes created during the simulation."
,
67
ObjectVectorValue
(),
68
MakeObjectVectorAccessor
(&
NodeListPriv::m_nodes
),
69
MakeObjectVectorChecker<Node> ())
70
;
71
return
tid;
72
}
73
74
Ptr<NodeListPriv>
75
NodeListPriv::Get
(
void
)
76
{
77
return
*
DoGet
();
78
}
79
Ptr<NodeListPriv>
*
80
NodeListPriv::DoGet
(
void
)
81
{
82
static
Ptr<NodeListPriv>
ptr = 0;
83
if
(ptr == 0)
84
{
85
ptr = CreateObject<NodeListPriv> ();
86
Config::RegisterRootNamespaceObject
(ptr);
87
Simulator::ScheduleDestroy
(&
NodeListPriv::Delete
);
88
}
89
return
&ptr;
90
}
91
void
92
NodeListPriv::Delete
(
void
)
93
{
94
NS_LOG_FUNCTION_NOARGS
();
95
Config::UnregisterRootNamespaceObject
(
Get
());
96
(*
DoGet
()) = 0;
97
}
98
99
100
NodeListPriv::NodeListPriv
()
101
{
102
NS_LOG_FUNCTION_NOARGS
();
103
}
104
NodeListPriv::~NodeListPriv
()
105
{
106
}
107
void
108
NodeListPriv::DoDispose
(
void
)
109
{
110
NS_LOG_FUNCTION_NOARGS
();
111
for
(std::vector<
Ptr<Node>
>::iterator i =
m_nodes
.begin ();
112
i !=
m_nodes
.end (); i++)
113
{
114
Ptr<Node>
node = *i;
115
node->
Dispose
();
116
*i = 0;
117
}
118
m_nodes
.erase (
m_nodes
.begin (),
m_nodes
.end ());
119
Object::DoDispose
();
120
}
121
122
123
uint32_t
124
NodeListPriv::Add
(
Ptr<Node>
node)
125
{
126
uint32_t index =
m_nodes
.size ();
127
m_nodes
.push_back (node);
128
Simulator::ScheduleWithContext
(index,
TimeStep
(0), &
Node::Start
, node);
129
return
index;
130
131
}
132
NodeList::Iterator
133
NodeListPriv::Begin
(
void
)
const
134
{
135
return
m_nodes
.begin ();
136
}
137
NodeList::Iterator
138
NodeListPriv::End
(
void
)
const
139
{
140
return
m_nodes
.end ();
141
}
142
uint32_t
143
NodeListPriv::GetNNodes
(
void
)
144
{
145
return
m_nodes
.size ();
146
}
147
148
Ptr<Node>
149
NodeListPriv::GetNode
(uint32_t n)
150
{
151
NS_ASSERT_MSG
(n <
m_nodes
.size (),
"Node index "
<< n <<
152
" is out of range (only have "
<<
m_nodes
.size () <<
" nodes)."
);
153
return
m_nodes
[n];
154
}
155
156
}
157
163
namespace
ns3 {
164
165
uint32_t
166
NodeList::Add
(
Ptr<Node>
node)
167
{
168
return
NodeListPriv::Get
()->Add (node);
169
}
170
NodeList::Iterator
171
NodeList::Begin
(
void
)
172
{
173
return
NodeListPriv::Get
()->Begin ();
174
}
175
NodeList::Iterator
176
NodeList::End
(
void
)
177
{
178
return
NodeListPriv::Get
()->End ();
179
}
180
Ptr<Node>
181
NodeList::GetNode
(uint32_t n)
182
{
183
return
NodeListPriv::Get
()->GetNode (n);
184
}
185
uint32_t
186
NodeList::GetNNodes
(
void
)
187
{
188
return
NodeListPriv::Get
()->GetNNodes ();
189
}
190
191
}
// namespace ns3
src
network
model
node-list.cc
Generated on Tue Nov 13 2012 10:32:20 for ns-3 by
1.8.1.2