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
ns3::MakeObjectVectorAccessor
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
Definition:
object-vector.h:51
ns3::Ptr< Node >
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:311
ns3::NodeList::GetNNodes
static uint32_t GetNNodes(void)
Definition:
node-list.cc:198
node.h
ns3::NodeList::GetNode
static Ptr< Node > GetNode(uint32_t n)
Definition:
node-list.cc:192
ns3::TimeStep
Time TimeStep(uint64_t ts)
Definition:
nstime.h:817
ns3::NodeListPriv::GetNode
Ptr< Node > GetNode(uint32_t n)
Definition:
node-list.cc:156
ns3::NodeListPriv::Delete
static void Delete(void)
Definition:
node-list.cc:94
ns3::NodeListPriv::GetTypeId
static TypeId GetTypeId(void)
Definition:
node-list.cc:62
ns3::Object::DoDispose
virtual void DoDispose(void)
Definition:
object.cc:335
ns3::NodeListPriv::Get
static Ptr< NodeListPriv > Get(void)
Definition:
node-list.cc:75
ns3::Config::UnregisterRootNamespaceObject
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition:
config.cc:751
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Definition:
log.h:275
node-list.h
ns3::NodeListPriv::End
NodeList::Iterator End(void) const
Definition:
node-list.cc:143
ns3::NodeList::End
static Iterator End(void)
Definition:
node-list.cc:186
ns3::NodeList::Add
static uint32_t Add(Ptr< Node > node)
Definition:
node-list.cc:174
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
ns3::Simulator::ScheduleWithContext
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Definition:
simulator.h:904
ns3::NodeListPriv::m_nodes
std::vector< Ptr< Node > > m_nodes
Definition:
node-list.cc:56
ns3::NodeList::Iterator
std::vector< Ptr< Node > >::const_iterator Iterator
Definition:
node-list.h:43
ns3::NodeListPriv::~NodeListPriv
~NodeListPriv()
Definition:
node-list.cc:106
ns3::NodeListPriv
private implementation detail of the NodeList API.
Definition:
node-list.cc:37
ns3::NodeListPriv::NodeListPriv
NodeListPriv()
Definition:
node-list.cc:102
ns3::Config::RegisterRootNamespaceObject
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition:
config.cc:745
NS_ASSERT_MSG
#define NS_ASSERT_MSG(condition, message)
Definition:
assert.h:86
ns3::NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
ns3::NodeListPriv::Begin
NodeList::Iterator Begin(void) const
Definition:
node-list.cc:137
ns3::NodeList::Begin
static Iterator Begin(void)
Definition:
node-list.cc:180
ns3::NodeListPriv::DoDispose
virtual void DoDispose(void)
Definition:
node-list.cc:111
ns3::Object::Initialize
void Initialize(void)
Definition:
object.cc:179
ns3::NodeListPriv::GetNNodes
uint32_t GetNNodes(void)
Definition:
node-list.cc:149
ns3::Simulator::ScheduleDestroy
static EventId ScheduleDestroy(MEM mem_ptr, OBJ obj)
Definition:
simulator.h:1076
ns3::Object
a base class which provides memory management and object aggregation
Definition:
object.h:63
ns3::NodeListPriv::DoGet
static Ptr< NodeListPriv > * DoGet(void)
Definition:
node-list.cc:81
ns3::ObjectPtrContainerValue
contain a set of ns3::Object pointers.
Definition:
object-ptr-container.h:38
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:610
ns3::Object::Dispose
void Dispose(void)
Definition:
object.cc:204
ns3::NodeListPriv::Add
uint32_t Add(Ptr< Node > node)
Definition:
node-list.cc:127
src
network
model
node-list.cc
Generated on Sat Nov 16 2013 12:55:35 for ns-3 by
1.8.5