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 * 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
13namespace ns3
14{
15
16NodeContainer
18{
20 for (auto i = NodeList::Begin(); i != NodeList::End(); ++i)
21 {
22 c.Add(*i);
23 }
24 return c;
25}
26
30
32{
33 m_nodes.push_back(node);
34}
35
36NodeContainer::NodeContainer(std::string nodeName)
37{
38 Ptr<Node> node = Names::Find<Node>(nodeName);
39 m_nodes.push_back(node);
40}
41
43{
44 m_nodes.reserve(n);
45 Create(n, systemId);
46}
47
50{
51 return m_nodes.begin();
52}
53
56{
57 return m_nodes.end();
58}
59
62{
63 return m_nodes.size();
64}
65
68{
69 return m_nodes[i];
70}
71
72void
74{
75 for (uint32_t i = 0; i < n; i++)
76 {
77 m_nodes.push_back(CreateObject<Node>());
78 }
79}
80
81void
83{
84 for (uint32_t i = 0; i < n; i++)
85 {
86 m_nodes.push_back(CreateObject<Node>(systemId));
87 }
88}
89
90void
92{
93 for (auto i = nc.Begin(); i != nc.End(); i++)
94 {
95 m_nodes.push_back(*i);
96 }
97}
98
99void
101{
102 m_nodes.push_back(node);
103}
104
105void
106NodeContainer::Add(std::string nodeName)
107{
108 Ptr<Node> node = Names::Find<Node>(nodeName);
109 m_nodes.push_back(node);
110}
111
112bool
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
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition names.h:443
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:226
static Iterator End()
Definition node-list.cc:233
Smart pointer class similar to boost::intrusive_ptr.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.