A Discrete-Event Network Simulator
API
node-list.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2007 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 * Authors:
19 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
20 */
21
22#include "ns3/simulator.h"
23#include "ns3/object-vector.h"
24#include "ns3/config.h"
25#include "ns3/log.h"
26#include "ns3/assert.h"
27#include "node-list.h"
28#include "node.h"
29
30namespace ns3 {
31
32NS_LOG_COMPONENT_DEFINE ("NodeList");
33
38class NodeListPriv : public Object
39{
40public:
45 static TypeId GetTypeId (void);
46 NodeListPriv ();
48
56 uint32_t Add (Ptr<Node> node);
57
62 NodeList::Iterator Begin (void) const;
63
68 NodeList::Iterator End (void) const;
69
75
79 uint32_t GetNNodes (void);
80
85 static Ptr<NodeListPriv> Get (void);
86
87private:
92 static Ptr<NodeListPriv> *DoGet (void);
93
97 static void Delete (void);
98
102 virtual void DoDispose (void);
103
104 std::vector<Ptr<Node> > m_nodes;
105};
106
108
109TypeId
111{
112 static TypeId tid = TypeId ("ns3::NodeListPriv")
113 .SetParent<Object> ()
114 .SetGroupName("Network")
115 .AddAttribute ("NodeList", "The list of all nodes created during the simulation.",
118 MakeObjectVectorChecker<Node> ())
119 ;
120 return tid;
121}
122
125{
127 return *DoGet ();
128}
131{
133 static Ptr<NodeListPriv> ptr = 0;
134 if (ptr == 0)
135 {
136 ptr = CreateObject<NodeListPriv> ();
139 }
140 return &ptr;
141}
142void
144{
147 (*DoGet ()) = 0;
148}
149
150
152{
153 NS_LOG_FUNCTION (this);
154}
156{
157 NS_LOG_FUNCTION (this);
158}
159void
161{
162 NS_LOG_FUNCTION (this);
163 for (std::vector<Ptr<Node> >::iterator i = m_nodes.begin ();
164 i != m_nodes.end (); i++)
165 {
166 Ptr<Node> node = *i;
167 node->Dispose ();
168 *i = 0;
169 }
170 m_nodes.erase (m_nodes.begin (), m_nodes.end ());
172}
173
174
177{
178 NS_LOG_FUNCTION (this << node);
179 uint32_t index = m_nodes.size ();
180 m_nodes.push_back (node);
181 Simulator::ScheduleWithContext (index, TimeStep (0), &Node::Initialize, node);
182 return index;
183
184}
187{
188 NS_LOG_FUNCTION (this);
189 return m_nodes.begin ();
190}
193{
194 NS_LOG_FUNCTION (this);
195 return m_nodes.end ();
196}
199{
200 NS_LOG_FUNCTION (this);
201 return m_nodes.size ();
202}
203
206{
207 NS_LOG_FUNCTION (this << n);
208 NS_ASSERT_MSG (n < m_nodes.size (), "Node index " << n <<
209 " is out of range (only have " << m_nodes.size () << " nodes).");
210 return m_nodes[n];
211}
212
213}
214
220namespace ns3 {
221
224{
225 NS_LOG_FUNCTION (node);
226 return NodeListPriv::Get ()->Add (node);
227}
230{
232 return NodeListPriv::Get ()->Begin ();
233}
236{
238 return NodeListPriv::Get ()->End ();
239}
242{
243 NS_LOG_FUNCTION (n);
244 return NodeListPriv::Get ()->GetNode (n);
245}
248{
250 return NodeListPriv::Get ()->GetNNodes ();
251}
252
253} // namespace ns3
static Iterator End(void)
Definition: node-list.cc:235
static uint32_t GetNNodes(void)
Definition: node-list.cc:247
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:241
static uint32_t Add(Ptr< Node > node)
Definition: node-list.cc:223
static Iterator Begin(void)
Definition: node-list.cc:229
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition: node-list.h:44
private implementation detail of the NodeList API.
Definition: node-list.cc:39
uint32_t GetNNodes(void)
Definition: node-list.cc:198
virtual void DoDispose(void)
Dispose the nodes in the list.
Definition: node-list.cc:160
Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:205
static Ptr< NodeListPriv > * DoGet(void)
Get the node list object.
Definition: node-list.cc:130
static Ptr< NodeListPriv > Get(void)
Get the node list object.
Definition: node-list.cc:124
static void Delete(void)
Delete the nodes list object.
Definition: node-list.cc:143
static TypeId GetTypeId(void)
Get the type ID.
Definition: node-list.cc:110
NodeList::Iterator End(void) const
Definition: node-list.cc:192
std::vector< Ptr< Node > > m_nodes
node objects container
Definition: node-list.cc:104
NodeList::Iterator Begin(void) const
Definition: node-list.cc:186
uint32_t Add(Ptr< Node > node)
Definition: node-list.cc:176
A base class which provides memory management and object aggregation.
Definition: object.h:88
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
void Initialize(void)
Invoke DoInitialize on all Objects aggregated to this one.
Definition: object.cc:183
void Dispose(void)
Dispose of this Object.
Definition: object.cc:214
Container for a set of ns3::Object pointers.
static void ScheduleWithContext(uint32_t context, Time const &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:571
static EventId ScheduleDestroy(FUNC f, Ts &&... args)
Schedule an event to run at the end of the simulation, when Simulator::Destroy() is called.
Definition: simulator.h:605
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:81
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:952
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:946
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.