A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 implemenation 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  ;
35 
39 class BuildingListPriv : public Object
40 {
41 public:
42  static TypeId GetTypeId (void);
45 
46  uint32_t Add (Ptr<Building> building);
47  BuildingList::Iterator Begin (void) const;
48  BuildingList::Iterator End (void) const;
49  Ptr<Building> GetBuilding (uint32_t n);
50  uint32_t GetNBuildings (void);
51 
52  static Ptr<BuildingListPriv> Get (void);
53 
54 private:
55  virtual void DoDispose (void);
56  static Ptr<BuildingListPriv> *DoGet (void);
57  static void Delete (void);
58  std::vector<Ptr<Building> > m_buildings;
59 };
60 
62  ;
63 
64 TypeId
66 {
67  static TypeId tid = TypeId ("ns3::BuildingListPriv")
68  .SetParent<Object> ()
69  .AddAttribute ("BuildingList", "The list of all buildings created during the simulation.",
72  MakeObjectVectorChecker<Building> ())
73  ;
74  return tid;
75 }
76 
79 {
80  return *DoGet ();
81 }
84 {
85  static Ptr<BuildingListPriv> ptr = 0;
86  if (ptr == 0)
87  {
88  ptr = CreateObject<BuildingListPriv> ();
91  }
92  return &ptr;
93 }
94 void
96 {
99  (*DoGet ()) = 0;
100 }
101 
102 
104 {
106 }
108 {
109 }
110 void
112 {
114  for (std::vector<Ptr<Building> >::iterator i = m_buildings.begin ();
115  i != m_buildings.end (); i++)
116  {
117  Ptr<Building> building = *i;
118  building->Dispose ();
119  *i = 0;
120  }
121  m_buildings.erase (m_buildings.begin (), m_buildings.end ());
123 }
124 
125 
126 uint32_t
128 {
129  uint32_t index = m_buildings.size ();
130  m_buildings.push_back (building);
132  return index;
133 
134 }
137 {
138  return m_buildings.begin ();
139 }
142 {
143  return m_buildings.end ();
144 }
145 uint32_t
147 {
148  return m_buildings.size ();
149 }
150 
153 {
154  NS_ASSERT_MSG (n < m_buildings.size (), "Building index " << n <<
155  " is out of range (only have " << m_buildings.size () << " buildings).");
156  return m_buildings.at (n);
157 }
158 
159 }
160 
166 namespace ns3 {
167 
168 uint32_t
170 {
171  return BuildingListPriv::Get ()->Add (building);
172 }
175 {
176  return BuildingListPriv::Get ()->Begin ();
177 }
180 {
181  return BuildingListPriv::Get ()->End ();
182 }
185 {
186  return BuildingListPriv::Get ()->GetBuilding (n);
187 }
188 uint32_t
190 {
191  return BuildingListPriv::Get ()->GetNBuildings ();
192 }
193 
194 } // namespace ns3
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
Definition: object-vector.h:51
static Ptr< BuildingListPriv > Get(void)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
static TypeId GetTypeId(void)
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
static uint32_t GetNBuildings(void)
Time TimeStep(uint64_t ts)
Definition: nstime.h:950
static Ptr< Building > GetBuilding(uint32_t n)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
private implementation detail of the BuildingList API.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:336
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:751
static Iterator End(void)
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition: log.h:309
static Iterator Begin(void)
uint32_t Add(Ptr< Building > building)
static void Delete(void)
BuildingList::Iterator End(void) const
std::vector< Ptr< Building > >::const_iterator Iterator
Definition: building-list.h:36
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
Ptr< Building > GetBuilding(uint32_t n)
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:745
static uint32_t Add(Ptr< Building > building)
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
void Initialize(void)
This method calls the virtual DoInitialize method on all the objects aggregated to this object...
Definition: object.cc:180
uint32_t GetNBuildings(void)
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
contain a set of ns3::Object pointers.
std::vector< Ptr< Building > > m_buildings
static Ptr< BuildingListPriv > * DoGet(void)
BuildingList::Iterator Begin(void) const
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611