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 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("BuildingList");
34 
38 class BuildingListPriv : public Object
39 {
40 public:
41  static TypeId GetTypeId (void);
44 
45  uint32_t Add (Ptr<Building> building);
46  BuildingList::Iterator Begin (void) const;
47  BuildingList::Iterator End (void) const;
48  Ptr<Building> GetBuilding (uint32_t n);
49  uint32_t GetNBuildings (void);
50 
51  static Ptr<BuildingListPriv> Get (void);
52 
53 private:
54  virtual void DoDispose (void);
55  static Ptr<BuildingListPriv> *DoGet (void);
56  static void Delete (void);
57  std::vector<Ptr<Building> > m_buildings;
58 };
59 
61 
62 TypeId
64 {
65  static TypeId tid = TypeId ("ns3::BuildingListPriv")
66  .SetParent<Object> ()
67  .SetGroupName ("Buildings")
68  .AddAttribute ("BuildingList", "The list of all buildings created during the simulation.",
71  MakeObjectVectorChecker<Building> ())
72  ;
73  return tid;
74 }
75 
78 {
79  return *DoGet ();
80 }
83 {
84  static Ptr<BuildingListPriv> ptr = 0;
85  if (ptr == 0)
86  {
87  ptr = CreateObject<BuildingListPriv> ();
90  }
91  return &ptr;
92 }
93 void
95 {
98  (*DoGet ()) = 0;
99 }
100 
101 
103 {
105 }
107 {
108 }
109 void
111 {
113  for (std::vector<Ptr<Building> >::iterator i = m_buildings.begin ();
114  i != m_buildings.end (); i++)
115  {
116  Ptr<Building> building = *i;
117  building->Dispose ();
118  *i = 0;
119  }
120  m_buildings.erase (m_buildings.begin (), m_buildings.end ());
122 }
123 
124 
125 uint32_t
127 {
128  uint32_t index = m_buildings.size ();
129  m_buildings.push_back (building);
131  return index;
132 
133 }
136 {
137  return m_buildings.begin ();
138 }
141 {
142  return m_buildings.end ();
143 }
144 uint32_t
146 {
147  return m_buildings.size ();
148 }
149 
152 {
153  NS_ASSERT_MSG (n < m_buildings.size (), "Building index " << n <<
154  " is out of range (only have " << m_buildings.size () << " buildings).");
155  return m_buildings.at (n);
156 }
157 
158 }
159 
165 namespace ns3 {
166 
167 uint32_t
169 {
170  return BuildingListPriv::Get ()->Add (building);
171 }
174 {
175  return BuildingListPriv::Get ()->Begin ();
176 }
179 {
180  return BuildingListPriv::Get ()->End ();
181 }
184 {
185  return BuildingListPriv::Get ()->GetBuilding (n);
186 }
187 uint32_t
189 {
190  return BuildingListPriv::Get ()->GetNBuildings ();
191 }
192 
193 } // namespace ns3
static Ptr< BuildingListPriv > Get(void)
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
static TypeId GetTypeId(void)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
static uint32_t GetNBuildings(void)
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:866
static Ptr< Building > GetBuilding(uint32_t n)
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:202
private implementation detail of the BuildingList API.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
static Iterator End(void)
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
static Iterator Begin(void)
uint32_t Add(Ptr< Building > building)
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:860
static void Delete(void)
BuildingList::Iterator End(void) const
BuildingList::Iterator Begin(void) const
std::vector< Ptr< Building > >::const_iterator Iterator
Definition: building-list.h:36
Ptr< Building > GetBuilding(uint32_t n)
virtual void DoDispose(void)
Destructor implementation.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time TimeStep(uint64_t ts)
Definition: nstime.h:1071
static uint32_t Add(Ptr< Building > building)
static void ScheduleWithContext(uint32_t context, Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
Definition: simulator.h:1475
uint32_t GetNBuildings(void)
static EventId ScheduleDestroy(MEM mem_ptr, OBJ obj)
Schedule an event to expire when Simulator::Destroy is called.
Definition: simulator.h:1677
A base class which provides memory management and object aggregation.
Definition: object.h:87
Container for a set of ns3::Object pointers.
std::vector< Ptr< Building > > m_buildings
static Ptr< BuildingListPriv > * DoGet(void)
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void Initialize(void)
Invoke DoInitialize on all Objects aggregated to this one.
Definition: object.cc:183