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
24 namespace ns3 {
25
NodeContainer()26 NodeContainer::NodeContainer ()
27 {
28 }
29
NodeContainer(Ptr<Node> node)30 NodeContainer::NodeContainer (Ptr<Node> node)
31 {
32 m_nodes.push_back (node);
33 }
NodeContainer(std::string nodeName)34 NodeContainer::NodeContainer (std::string nodeName)
35 {
36 Ptr<Node> node = Names::Find<Node> (nodeName);
37 m_nodes.push_back (node);
38 }
NodeContainer(uint32_t n,uint32_t systemId)39 NodeContainer::NodeContainer (uint32_t n, uint32_t systemId /* = 0 */)
40 {
41 m_nodes.reserve (n);
42 Create (n, systemId);
43 }
NodeContainer(const NodeContainer & a,const NodeContainer & b)44 NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b)
45 {
46 Add (a);
47 Add (b);
48 }
NodeContainer(const NodeContainer & a,const NodeContainer & b,const NodeContainer & c)49 NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b,
50 const NodeContainer &c)
51 {
52 Add (a);
53 Add (b);
54 Add (c);
55 }
NodeContainer(const NodeContainer & a,const NodeContainer & b,const NodeContainer & c,const NodeContainer & d)56 NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b,
57 const NodeContainer &c, const NodeContainer &d)
58 {
59 Add (a);
60 Add (b);
61 Add (c);
62 Add (d);
63 }
64
NodeContainer(const NodeContainer & a,const NodeContainer & b,const NodeContainer & c,const NodeContainer & d,const NodeContainer & e)65 NodeContainer::NodeContainer (const NodeContainer &a, const NodeContainer &b,
66 const NodeContainer &c, const NodeContainer &d,
67 const NodeContainer &e)
68 {
69 Add (a);
70 Add (b);
71 Add (c);
72 Add (d);
73 Add (e);
74 }
75
76 NodeContainer::Iterator
Begin(void) const77 NodeContainer::Begin (void) const
78 {
79 return m_nodes.begin ();
80 }
81 NodeContainer::Iterator
End(void) const82 NodeContainer::End (void) const
83 {
84 return m_nodes.end ();
85 }
86
87 uint32_t
GetN(void) const88 NodeContainer::GetN (void) const
89 {
90 return m_nodes.size ();
91 }
92 Ptr<Node>
Get(uint32_t i) const93 NodeContainer::Get (uint32_t i) const
94 {
95 return m_nodes[i];
96 }
97 void
Create(uint32_t n)98 NodeContainer::Create (uint32_t n)
99 {
100 for (uint32_t i = 0; i < n; i++)
101 {
102 m_nodes.push_back (CreateObject<Node> ());
103 }
104 }
105 void
Create(uint32_t n,uint32_t systemId)106 NodeContainer::Create (uint32_t n, uint32_t systemId)
107 {
108 for (uint32_t i = 0; i < n; i++)
109 {
110 m_nodes.push_back (CreateObject<Node> (systemId));
111 }
112 }
113 void
Add(NodeContainer other)114 NodeContainer::Add (NodeContainer other)
115 {
116 for (Iterator i = other.Begin (); i != other.End (); i++)
117 {
118 m_nodes.push_back (*i);
119 }
120 }
121 void
Add(Ptr<Node> node)122 NodeContainer::Add (Ptr<Node> node)
123 {
124 m_nodes.push_back (node);
125 }
126 void
Add(std::string nodeName)127 NodeContainer::Add (std::string nodeName)
128 {
129 Ptr<Node> node = Names::Find<Node> (nodeName);
130 m_nodes.push_back (node);
131 }
132
133 NodeContainer
GetGlobal(void)134 NodeContainer::GetGlobal (void)
135 {
136 NodeContainer c;
137 for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
138 {
139 c.Add (*i);
140 }
141 return c;
142 }
143
144 bool
Contains(uint32_t id) const145 NodeContainer::Contains (uint32_t id) const
146 {
147 for (uint32_t i = 0; i < m_nodes.size (); i++)
148 {
149 if (m_nodes[i]->GetId () == id)
150 {
151 return true;
152 }
153 }
154 return false;
155 }
156
157 } // namespace ns3
158