A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  .AddAttribute ("NodeList", "The list of all nodes created during the simulation.",
117  MakeObjectVectorChecker<Node> ())
118  ;
119  return tid;
120 }
121 
124 {
126  return *DoGet ();
127 }
130 {
132  static Ptr<NodeListPriv> ptr = 0;
133  if (ptr == 0)
134  {
135  ptr = CreateObject<NodeListPriv> ();
138  }
139  return &ptr;
140 }
141 void
143 {
146  (*DoGet ()) = 0;
147 }
148 
149 
151 {
152  NS_LOG_FUNCTION (this);
153 }
155 {
156  NS_LOG_FUNCTION (this);
157 }
158 void
160 {
161  NS_LOG_FUNCTION (this);
162  for (std::vector<Ptr<Node> >::iterator i = m_nodes.begin ();
163  i != m_nodes.end (); i++)
164  {
165  Ptr<Node> node = *i;
166  node->Dispose ();
167  *i = 0;
168  }
169  m_nodes.erase (m_nodes.begin (), m_nodes.end ());
171 }
172 
173 
174 uint32_t
176 {
177  NS_LOG_FUNCTION (this << node);
178  uint32_t index = m_nodes.size ();
179  m_nodes.push_back (node);
181  return index;
182 
183 }
186 {
187  NS_LOG_FUNCTION (this);
188  return m_nodes.begin ();
189 }
191 NodeListPriv::End (void) const
192 {
193  NS_LOG_FUNCTION (this);
194  return m_nodes.end ();
195 }
196 uint32_t
198 {
199  NS_LOG_FUNCTION (this);
200  return m_nodes.size ();
201 }
202 
203 Ptr<Node>
205 {
206  NS_LOG_FUNCTION (this << n);
207  NS_ASSERT_MSG (n < m_nodes.size (), "Node index " << n <<
208  " is out of range (only have " << m_nodes.size () << " nodes).");
209  return m_nodes[n];
210 }
211 
212 }
213 
219 namespace ns3 {
220 
221 uint32_t
223 {
224  NS_LOG_FUNCTION (node);
225  return NodeListPriv::Get ()->Add (node);
226 }
229 {
231  return NodeListPriv::Get ()->Begin ();
232 }
235 {
237  return NodeListPriv::Get ()->End ();
238 }
239 Ptr<Node>
240 NodeList::GetNode (uint32_t n)
241 {
242  NS_LOG_FUNCTION (n);
243  return NodeListPriv::Get ()->GetNode (n);
244 }
245 uint32_t
247 {
249  return NodeListPriv::Get ()->GetNNodes ();
250 }
251 
252 } // namespace ns3
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
Definition: object-vector.h:51
#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:246
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:240
Time TimeStep(uint64_t ts)
Definition: nstime.h:997
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:204
static void Delete(void)
Delete the nodes list object.
Definition: node-list.cc:142
static TypeId GetTypeId(void)
Get the type ID.
Definition: node-list.cc:110
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:335
static Ptr< NodeListPriv > Get(void)
Get the node list object.
Definition: node-list.cc:123
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:751
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
NodeList::Iterator End(void) const
Definition: node-list.cc:191
static Iterator End(void)
Definition: node-list.cc:234
static uint32_t Add(Ptr< Node > node)
Definition: node-list.cc:222
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:905
std::vector< Ptr< Node > > m_nodes
node objects container
Definition: node-list.cc:104
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
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:745
#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:84
NodeList::Iterator Begin(void) const
Definition: node-list.cc:185
static Iterator Begin(void)
Definition: node-list.cc:228
virtual void DoDispose(void)
Dispose the nodes in the list.
Definition: node-list.cc:159
void Initialize(void)
This method calls the virtual DoInitialize method on all the objects aggregated to this object...
Definition: object.cc:179
uint32_t GetNNodes(void)
Definition: node-list.cc:197
static EventId ScheduleDestroy(MEM mem_ptr, OBJ obj)
Schedule an event to expire at Destroy time.
Definition: simulator.h:1077
a base class which provides memory management and object aggregation
Definition: object.h:64
static Ptr< NodeListPriv > * DoGet(void)
Get the node list object.
Definition: node-list.cc:129
contain a set of ns3::Object pointers.
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
void Dispose(void)
Run the DoDispose methods of this object and all the objects aggregated to it.
Definition: object.cc:204
uint32_t Add(Ptr< Node > node)
Definition: node-list.cc:175