A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
node-container.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#include "node-container.h"
20
21#include "ns3/names.h"
22#include "ns3/node-list.h"
23
24namespace ns3
25{
26
27NodeContainer
29{
31 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
32 {
33 c.Add(*i);
34 }
35 return c;
36}
37
39{
40}
41
43{
44 m_nodes.push_back(node);
45}
46
47NodeContainer::NodeContainer(std::string nodeName)
48{
49 Ptr<Node> node = Names::Find<Node>(nodeName);
50 m_nodes.push_back(node);
51}
52
54{
55 m_nodes.reserve(n);
56 Create(n, systemId);
57}
58
61{
62 return m_nodes.begin();
63}
64
67{
68 return m_nodes.end();
69}
70
73{
74 return m_nodes.size();
75}
76
79{
80 return m_nodes[i];
81}
82
83void
85{
86 for (uint32_t i = 0; i < n; i++)
87 {
88 m_nodes.push_back(CreateObject<Node>());
89 }
90}
91
92void
94{
95 for (uint32_t i = 0; i < n; i++)
96 {
97 m_nodes.push_back(CreateObject<Node>(systemId));
98 }
99}
100
101void
103{
104 for (auto i = nc.Begin(); i != nc.End(); i++)
105 {
106 m_nodes.push_back(*i);
107 }
108}
109
110void
112{
113 m_nodes.push_back(node);
114}
115
116void
117NodeContainer::Add(std::string nodeName)
118{
119 Ptr<Node> node = Names::Find<Node>(nodeName);
120 m_nodes.push_back(node);
121}
122
123bool
125{
126 for (uint32_t i = 0; i < m_nodes.size(); i++)
127 {
128 if (m_nodes[i]->GetId() == id)
129 {
130 return true;
131 }
132 }
133 return false;
134}
135
136} // namespace ns3
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
std::vector< Ptr< Node > > m_nodes
Nodes smart pointers.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
bool Contains(uint32_t id) const
Return true if container contains a Node with index id.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
NodeContainer()
Create an empty NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
static Iterator Begin()
Definition: node-list.cc:237
static Iterator End()
Definition: node-list.cc:244
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Every class exported by the ns3 library is enclosed in the ns3 namespace.