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  ;
34 
38 class NodeListPriv : public Object
39 {
40 public:
41  static TypeId GetTypeId (void);
42  NodeListPriv ();
43  ~NodeListPriv ();
44 
45  uint32_t Add (Ptr<Node> node);
46  NodeList::Iterator Begin (void) const;
47  NodeList::Iterator End (void) const;
48  Ptr<Node> GetNode (uint32_t n);
49  uint32_t GetNNodes (void);
50 
51  static Ptr<NodeListPriv> Get (void);
52 
53 private:
54  virtual void DoDispose (void);
55  static Ptr<NodeListPriv> *DoGet (void);
56  static void Delete (void);
57  std::vector<Ptr<Node> > m_nodes;
58 };
59 
61  ;
62 
63 TypeId
65 {
66  static TypeId tid = TypeId ("ns3::NodeListPriv")
67  .SetParent<Object> ()
68  .AddAttribute ("NodeList", "The list of all nodes created during the simulation.",
71  MakeObjectVectorChecker<Node> ())
72  ;
73  return tid;
74 }
75 
78 {
80  return *DoGet ();
81 }
84 {
86  static Ptr<NodeListPriv> ptr = 0;
87  if (ptr == 0)
88  {
89  ptr = CreateObject<NodeListPriv> ();
92  }
93  return &ptr;
94 }
95 void
97 {
100  (*DoGet ()) = 0;
101 }
102 
103 
105 {
106  NS_LOG_FUNCTION (this);
107 }
109 {
110  NS_LOG_FUNCTION (this);
111 }
112 void
114 {
115  NS_LOG_FUNCTION (this);
116  for (std::vector<Ptr<Node> >::iterator i = m_nodes.begin ();
117  i != m_nodes.end (); i++)
118  {
119  Ptr<Node> node = *i;
120  node->Dispose ();
121  *i = 0;
122  }
123  m_nodes.erase (m_nodes.begin (), m_nodes.end ());
125 }
126 
127 
128 uint32_t
130 {
131  NS_LOG_FUNCTION (this << node);
132  uint32_t index = m_nodes.size ();
133  m_nodes.push_back (node);
135  return index;
136 
137 }
140 {
141  NS_LOG_FUNCTION (this);
142  return m_nodes.begin ();
143 }
145 NodeListPriv::End (void) const
146 {
147  NS_LOG_FUNCTION (this);
148  return m_nodes.end ();
149 }
150 uint32_t
152 {
153  NS_LOG_FUNCTION (this);
154  return m_nodes.size ();
155 }
156 
157 Ptr<Node>
159 {
160  NS_LOG_FUNCTION (this << n);
161  NS_ASSERT_MSG (n < m_nodes.size (), "Node index " << n <<
162  " is out of range (only have " << m_nodes.size () << " nodes).");
163  return m_nodes[n];
164 }
165 
166 }
167 
173 namespace ns3 {
174 
175 uint32_t
177 {
178  NS_LOG_FUNCTION (node);
179  return NodeListPriv::Get ()->Add (node);
180 }
183 {
185  return NodeListPriv::Get ()->Begin ();
186 }
189 {
191  return NodeListPriv::Get ()->End ();
192 }
193 Ptr<Node>
194 NodeList::GetNode (uint32_t n)
195 {
196  NS_LOG_FUNCTION (n);
197  return NodeListPriv::Get ()->GetNode (n);
198 }
199 uint32_t
201 {
203  return NodeListPriv::Get ()->GetNNodes ();
204 }
205 
206 } // namespace ns3
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
Definition: object-vector.h:51
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
static uint32_t GetNNodes(void)
Definition: node-list.cc:200
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
static Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:194
Time TimeStep(uint64_t ts)
Definition: nstime.h:950
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
Ptr< Node > GetNode(uint32_t n)
Definition: node-list.cc:158
static void Delete(void)
Definition: node-list.cc:96
static TypeId GetTypeId(void)
Definition: node-list.cc:64
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:336
static Ptr< NodeListPriv > Get(void)
Definition: node-list.cc:77
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:751
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
NodeList::Iterator End(void) const
Definition: node-list.cc:145
static Iterator End(void)
Definition: node-list.cc:188
static uint32_t Add(Ptr< Node > node)
Definition: node-list.cc:176
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:904
std::vector< Ptr< Node > > m_nodes
Definition: node-list.cc:57
std::vector< Ptr< Node > >::const_iterator Iterator
Definition: node-list.h:43
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)
Definition: assert.h:86
NodeList::Iterator Begin(void) const
Definition: node-list.cc:139
static Iterator Begin(void)
Definition: node-list.cc:182
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: node-list.cc:113
void Initialize(void)
This method calls the virtual DoInitialize method on all the objects aggregated to this object...
Definition: object.cc:180
uint32_t GetNNodes(void)
Definition: node-list.cc:151
static EventId ScheduleDestroy(MEM mem_ptr, OBJ obj)
Schedule an event to expire at Destroy time.
Definition: simulator.h:1076
a base class which provides memory management and object aggregation
Definition: object.h:63
static Ptr< NodeListPriv > * DoGet(void)
Definition: node-list.cc:83
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:611
void Dispose(void)
Run the DoDispose methods of this object and all the objects aggregated to it.
Definition: object.cc:205
uint32_t Add(Ptr< Node > node)
Definition: node-list.cc:129