A Discrete-Event Network Simulator
API
node-container.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2008 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 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 */
20#include "node-container.h"
21#include "ns3/node-list.h"
22#include "ns3/names.h"
23
24namespace ns3 {
25
26NodeContainer
28{
30 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
31 {
32 c.Add (*i);
33 }
34 return c;
35}
36
38{
39}
40
42{
43 m_nodes.push_back (node);
44}
45
46NodeContainer::NodeContainer (std::string nodeName)
47{
48 Ptr<Node> node = Names::Find<Node> (nodeName);
49 m_nodes.push_back (node);
50}
51
53{
54 m_nodes.reserve (n);
55 Create (n, systemId);
56}
57
60{
61 return m_nodes.begin ();
62}
63
66{
67 return m_nodes.end ();
68}
69
72{
73 return m_nodes.size ();
74}
75
78{
79 return m_nodes[i];
80}
81
82void
84{
85 for (uint32_t i = 0; i < n; i++)
86 {
87 m_nodes.push_back (CreateObject<Node> ());
88 }
89}
90
91void
93{
94 for (uint32_t i = 0; i < n; i++)
95 {
96 m_nodes.push_back (CreateObject<Node> (systemId));
97 }
98}
99
100void
102{
103 for (Iterator i = nc.Begin (); i != nc.End (); i++)
104 {
105 m_nodes.push_back (*i);
106 }
107}
108
109void
111{
112 m_nodes.push_back (node);
113}
114
115void
116NodeContainer::Add (std::string nodeName)
117{
118 Ptr<Node> node = Names::Find<Node> (nodeName);
119 m_nodes.push_back (node);
120}
121
122bool
124{
125 for (uint32_t i = 0; i < m_nodes.size (); i++)
126 {
127 if (m_nodes[i]->GetId () == id)
128 {
129 return true;
130 }
131 }
132 return false;
133}
134
135} // namespace ns3
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
std::vector< Ptr< Node > > m_nodes
Nodes smart pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the 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.
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 End(void)
Definition: node-list.cc:235
static Iterator Begin(void)
Definition: node-list.cc:229
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition: node-list.h:44
Every class exported by the ns3 library is enclosed in the ns3 namespace.