A Discrete-Event Network Simulator
API
building-list.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Jaume Nin <jaume.nin@cttc,cat>
19 * Based on BuildingList implementation by Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20 *
21 */
22#include "building-list.h"
23#include "ns3/simulator.h"
24#include "ns3/object-vector.h"
25#include "ns3/config.h"
26#include "ns3/log.h"
27#include "ns3/assert.h"
28#include "building-list.h"
29#include "building.h"
30
31namespace ns3 {
32
33NS_LOG_COMPONENT_DEFINE ("BuildingList");
34
39{
40public:
45 static TypeId GetTypeId (void);
48
55 uint32_t Add (Ptr<Building> building);
61 BuildingList::Iterator Begin (void) const;
67 BuildingList::Iterator End (void) const;
79
84 static Ptr<BuildingListPriv> Get (void);
85
86private:
87 virtual void DoDispose (void);
92 static Ptr<BuildingListPriv> *DoGet (void);
99 static void Delete (void);
100 std::vector<Ptr<Building> > m_buildings;
101};
102
104
105TypeId
107{
108 static TypeId tid = TypeId ("ns3::BuildingListPriv")
109 .SetParent<Object> ()
110 .SetGroupName ("Buildings")
111 .AddAttribute ("BuildingList", "The list of all buildings created during the simulation.",
114 MakeObjectVectorChecker<Building> ())
115 ;
116 return tid;
117}
118
121{
122 return *DoGet ();
123}
126{
127 static Ptr<BuildingListPriv> ptr = 0;
128 if (ptr == 0)
129 {
130 ptr = CreateObject<BuildingListPriv> ();
133 }
134 return &ptr;
135}
136void
138{
141 (*DoGet ()) = 0;
142}
143
144
146{
148}
150{
151}
152void
154{
156 for (std::vector<Ptr<Building> >::iterator i = m_buildings.begin ();
157 i != m_buildings.end (); i++)
158 {
159 Ptr<Building> building = *i;
160 building->Dispose ();
161 *i = 0;
162 }
163 m_buildings.erase (m_buildings.begin (), m_buildings.end ());
165}
166
167
170{
171 uint32_t index = m_buildings.size ();
172 m_buildings.push_back (building);
173 Simulator::ScheduleWithContext (index, TimeStep (0), &Building::Initialize, building);
174 return index;
175
176}
179{
180 return m_buildings.begin ();
181}
184{
185 return m_buildings.end ();
186}
189{
190 return m_buildings.size ();
191}
192
195{
196 NS_ASSERT_MSG (n < m_buildings.size (), "Building index " << n <<
197 " is out of range (only have " << m_buildings.size () << " buildings).");
198 return m_buildings.at (n);
199}
200
201}
202
208namespace ns3 {
209
212{
213 return BuildingListPriv::Get ()->Add (building);
214}
217{
218 return BuildingListPriv::Get ()->Begin ();
219}
222{
223 return BuildingListPriv::Get ()->End ();
224}
227{
228 return BuildingListPriv::Get ()->GetBuilding (n);
229}
232{
233 return BuildingListPriv::Get ()->GetNBuildings ();
234}
235
236} // namespace ns3
static Ptr< Building > GetBuilding(uint32_t n)
std::vector< Ptr< Building > >::const_iterator Iterator
Const Iterator.
Definition: building-list.h:40
static uint32_t Add(Ptr< Building > building)
static uint32_t GetNBuildings(void)
static Iterator End(void)
static Iterator Begin(void)
private implementation detail of the BuildingList API.
std::vector< Ptr< Building > > m_buildings
Container of Building.
BuildingList::Iterator End(void) const
Returns an interator to the end of the list.
Ptr< Building > GetBuilding(uint32_t n)
Gets the n-th Building in the container.
static Ptr< BuildingListPriv > * DoGet(void)
Get the Singleton instance of BuildingListPriv (or create one)
static void Delete(void)
Dispose the Singleton instance of BuildingListPriv.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t Add(Ptr< Building > building)
Add a Building to the list.
virtual void DoDispose(void)
Destructor implementation.
static Ptr< BuildingListPriv > Get(void)
Get the Singleton instance of BuildingListPriv (or create one)
uint32_t GetNBuildings(void)
Gets the number of Building in the container.
BuildingList::Iterator Begin(void) const
Returns an interator to the start of the list.
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
Container for a set of ns3::Object pointers.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
static void ScheduleWithContext(uint32_t context, Time const &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition: simulator.h:570
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:604
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_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.