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 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("NodeList");
33 
38 class NodeListPriv : public Object
39 {
40 public:
45  static TypeId GetTypeId (void);
46  NodeListPriv ();
47  ~NodeListPriv ();
48 
56  uint32_t Add (Ptr<Node> node);
57 
62  NodeList::Iterator Begin (void) const;
63 
68  NodeList::Iterator End (void) const;
69 
74  Ptr<Node> GetNode (uint32_t n);
75 
79  uint32_t GetNNodes (void);
80 
85  static Ptr<NodeListPriv> Get (void);
86 
87 private:
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 
109 TypeId
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 }
142 void
144 {
147  (*DoGet ()) = 0;
148 }
149 
150 
152 {
153  NS_LOG_FUNCTION (this);
154 }
156 {
157  NS_LOG_FUNCTION (this);
158 }
159 void
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 
175 uint32_t
177 {
178  NS_LOG_FUNCTION (this << node);
179  uint32_t index = m_nodes.size ();
180  m_nodes.push_back (node);
182  return index;
183 
184 }
187 {
188  NS_LOG_FUNCTION (this);
189  return m_nodes.begin ();
190 }
192 NodeListPriv::End (void) const
193 {
194  NS_LOG_FUNCTION (this);
195  return m_nodes.end ();
196 }
197 uint32_t
199 {
200  NS_LOG_FUNCTION (this);
201  return m_nodes.size ();
202 }
203 
204 Ptr<Node>
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 
220 namespace ns3 {
221 
222 uint32_t
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 }
240 Ptr<Node>
242 {
243  NS_LOG_FUNCTION (n);
244  return NodeListPriv::Get ()->GetNode (n);
245 }
246 uint32_t
248 {
250  return NodeListPriv::Get ()->GetNNodes ();
251 }
252 
253 } // namespace ns3
void Dispose(void)
Dispose of this Object.
Definition: object.cc:214
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
static uint32_t GetNNodes(void)
Definition: node-list.cc:247
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:241
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:896
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:81
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:205
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
static Ptr< NodeListPriv > Get(void)
Get the node list object.
Definition: node-list.cc:124
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:890
NodeList::Iterator Begin(void) const
Definition: node-list.cc:186
static Iterator End(void)
Definition: node-list.cc:235
static uint32_t Add(Ptr< Node > node)
Definition: node-list.cc:223
NodeList::Iterator End(void) const
Definition: node-list.cc:192
std::vector< Ptr< Node > > m_nodes
node objects container
Definition: node-list.cc:104
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:38
Time TimeStep(uint64_t ts)
Definition: nstime.h:1121
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1484
static Iterator Begin(void)
Definition: node-list.cc:229
virtual void DoDispose(void)
Dispose the nodes in the list.
Definition: node-list.cc:160
uint32_t GetNNodes(void)
Definition: node-list.cc:198
static EventId ScheduleDestroy(MEM mem_ptr, OBJ obj)
Schedule an event to expire when Simulator::Destroy is called.
Definition: simulator.h:1686
A base class which provides memory management and object aggregation.
Definition: object.h:87
static Ptr< NodeListPriv > * DoGet(void)
Get the node list object.
Definition: node-list.cc:130
Container for a set of ns3::Object pointers.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
void Initialize(void)
Invoke DoInitialize on all Objects aggregated to this one.
Definition: object.cc:183
uint32_t Add(Ptr< Node > node)
Definition: node-list.cc:176