A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
node-container.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008 INRIA
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7
*/
8
#include "
node-container.h
"
9
10
#include "ns3/names.h"
11
#include "ns3/node-list.h"
12
13
namespace
ns3
14
{
15
16
NodeContainer
17
NodeContainer::GetGlobal
()
18
{
19
NodeContainer
c
;
20
for
(
auto
i
=
NodeList::Begin
();
i
!=
NodeList::End
(); ++
i
)
21
{
22
c
.
Add
(*
i
);
23
}
24
return
c
;
25
}
26
27
NodeContainer::NodeContainer
()
28
{
29
}
30
31
NodeContainer::NodeContainer
(
Ptr<Node>
node)
32
{
33
m_nodes
.push_back(node);
34
}
35
36
NodeContainer::NodeContainer
(std::string
nodeName
)
37
{
38
Ptr<Node>
node = Names::Find<Node>(
nodeName
);
39
m_nodes
.push_back(node);
40
}
41
42
NodeContainer::NodeContainer
(
uint32_t
n,
uint32_t
systemId
/* = 0 */
)
43
{
44
m_nodes
.reserve(n);
45
Create
(n,
systemId
);
46
}
47
48
NodeContainer::Iterator
49
NodeContainer::Begin
()
const
50
{
51
return
m_nodes
.begin();
52
}
53
54
NodeContainer::Iterator
55
NodeContainer::End
()
const
56
{
57
return
m_nodes
.end();
58
}
59
60
uint32_t
61
NodeContainer::GetN
()
const
62
{
63
return
m_nodes
.size();
64
}
65
66
Ptr<Node>
67
NodeContainer::Get
(
uint32_t
i
)
const
68
{
69
return
m_nodes
[
i
];
70
}
71
72
void
73
NodeContainer::Create
(
uint32_t
n)
74
{
75
for
(
uint32_t
i
= 0;
i
< n;
i
++)
76
{
77
m_nodes
.push_back(
CreateObject<Node>
());
78
}
79
}
80
81
void
82
NodeContainer::Create
(
uint32_t
n,
uint32_t
systemId
)
83
{
84
for
(
uint32_t
i
= 0;
i
< n;
i
++)
85
{
86
m_nodes
.push_back(
CreateObject<Node>
(
systemId
));
87
}
88
}
89
90
void
91
NodeContainer::Add
(
const
NodeContainer
&
nc
)
92
{
93
for
(
auto
i
=
nc
.Begin();
i
!=
nc
.End();
i
++)
94
{
95
m_nodes
.push_back(*
i
);
96
}
97
}
98
99
void
100
NodeContainer::Add
(
Ptr<Node>
node)
101
{
102
m_nodes
.push_back(node);
103
}
104
105
void
106
NodeContainer::Add
(std::string
nodeName
)
107
{
108
Ptr<Node>
node = Names::Find<Node>(
nodeName
);
109
m_nodes
.push_back(node);
110
}
111
112
bool
113
NodeContainer::Contains
(
uint32_t
id
)
const
114
{
115
for
(
uint32_t
i
= 0;
i
<
m_nodes
.size();
i
++)
116
{
117
if
(
m_nodes
[
i
]->GetId() ==
id
)
118
{
119
return
true
;
120
}
121
}
122
return
false
;
123
}
124
125
}
// namespace ns3
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
ns3::NodeContainer::Iterator
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition
node-container.h:32
ns3::NodeContainer::End
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Definition
node-container.cc:55
ns3::NodeContainer::m_nodes
std::vector< Ptr< Node > > m_nodes
Nodes smart pointers.
Definition
node-container.h:262
ns3::NodeContainer::GetN
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
Definition
node-container.cc:61
ns3::NodeContainer::GetGlobal
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Definition
node-container.cc:17
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition
node-container.cc:73
ns3::NodeContainer::Contains
bool Contains(uint32_t id) const
Return true if container contains a Node with index id.
Definition
node-container.cc:113
ns3::NodeContainer::Add
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Definition
node-container.cc:91
ns3::NodeContainer::Begin
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Definition
node-container.cc:49
ns3::NodeContainer::NodeContainer
NodeContainer()
Create an empty NodeContainer.
Definition
node-container.cc:27
ns3::NodeContainer::Get
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Definition
node-container.cc:67
ns3::NodeList::Begin
static Iterator Begin()
Definition
node-list.cc:226
ns3::NodeList::End
static Iterator End()
Definition
node-list.cc:233
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
uint32_t
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
node-container.h
src
network
helper
node-container.cc
Generated on Mon Dec 15 2025 15:22:01 for ns-3 by
1.9.8