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
NS_LOG_FUNCTION_NOARGS
();
78
return
*
DoGet
();
79
}
80
Ptr<NodeListPriv>
*
81
NodeListPriv::DoGet
(
void
)
82
{
83
NS_LOG_FUNCTION_NOARGS
();
84
static
Ptr<NodeListPriv>
ptr = 0;
85
if
(ptr == 0)
86
{
87
ptr = CreateObject<NodeListPriv> ();
88
Config::RegisterRootNamespaceObject
(ptr);
89
Simulator::ScheduleDestroy
(&
NodeListPriv::Delete
);
90
}
91
return
&ptr;
92
}
93
void
94
NodeListPriv::Delete
(
void
)
95
{
96
NS_LOG_FUNCTION_NOARGS
();
97
Config::UnregisterRootNamespaceObject
(
Get
());
98
(*
DoGet
()) = 0;
99
}
100
101
102
NodeListPriv::NodeListPriv
()
103
{
104
NS_LOG_FUNCTION
(
this
);
105
}
106
NodeListPriv::~NodeListPriv
()
107
{
108
NS_LOG_FUNCTION
(
this
);
109
}
110
void
111
NodeListPriv::DoDispose
(
void
)
112
{
113
NS_LOG_FUNCTION
(
this
);
114
for
(std::vector<
Ptr<Node>
>::iterator i =
m_nodes
.begin ();
115
i !=
m_nodes
.end (); i++)
116
{
117
Ptr<Node>
node = *i;
118
node->
Dispose
();
119
*i = 0;
120
}
121
m_nodes
.erase (
m_nodes
.begin (),
m_nodes
.end ());
122
Object::DoDispose
();
123
}
124
125
126
uint32_t
127
NodeListPriv::Add
(
Ptr<Node>
node)
128
{
129
NS_LOG_FUNCTION
(
this
<< node);
130
uint32_t index =
m_nodes
.size ();
131
m_nodes
.push_back (node);
132
Simulator::ScheduleWithContext
(index,
TimeStep
(0), &
Node::Initialize
, node);
133
return
index;
134
135
}
136
NodeList::Iterator
137
NodeListPriv::Begin
(
void
)
const
138
{
139
NS_LOG_FUNCTION
(
this
);
140
return
m_nodes
.begin ();
141
}
142
NodeList::Iterator
143
NodeListPriv::End
(
void
)
const
144
{
145
NS_LOG_FUNCTION
(
this
);
146
return
m_nodes
.end ();
147
}
148
uint32_t
149
NodeListPriv::GetNNodes
(
void
)
150
{
151
NS_LOG_FUNCTION
(
this
);
152
return
m_nodes
.size ();
153
}
154
155
Ptr<Node>
156
NodeListPriv::GetNode
(uint32_t n)
157
{
158
NS_LOG_FUNCTION
(
this
<< n);
159
NS_ASSERT_MSG
(n <
m_nodes
.size (),
"Node index "
<< n <<
160
" is out of range (only have "
<<
m_nodes
.size () <<
" nodes)."
);
161
return
m_nodes
[n];
162
}
163
164
}
165
171
namespace
ns3 {
172
173
uint32_t
174
NodeList::Add
(
Ptr<Node>
node)
175
{
176
NS_LOG_FUNCTION
(node);
177
return
NodeListPriv::Get
()->Add (node);
178
}
179
NodeList::Iterator
180
NodeList::Begin
(
void
)
181
{
182
NS_LOG_FUNCTION_NOARGS
();
183
return
NodeListPriv::Get
()->Begin ();
184
}
185
NodeList::Iterator
186
NodeList::End
(
void
)
187
{
188
NS_LOG_FUNCTION_NOARGS
();
189
return
NodeListPriv::Get
()->End ();
190
}
191
Ptr<Node>
192
NodeList::GetNode
(uint32_t n)
193
{
194
NS_LOG_FUNCTION
(n);
195
return
NodeListPriv::Get
()->GetNode (n);
196
}
197
uint32_t
198
NodeList::GetNNodes
(
void
)
199
{
200
NS_LOG_FUNCTION_NOARGS
();
201
return
NodeListPriv::Get
()->GetNNodes ();
202
}
203
204
}
// namespace ns3
src
network
model
node-list.cc
Generated on Fri Aug 30 2013 01:42:59 for ns-3 by
1.8.1.2