A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
building-list.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Jaume Nin <jaume.nin@cttc,cat>
7 * Based on BuildingList implementation by Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8 *
9 */
10#include "building-list.h"
11
12#include "building.h"
13
14#include "ns3/assert.h"
15#include "ns3/config.h"
16#include "ns3/log.h"
17#include "ns3/object-vector.h"
18#include "ns3/simulator.h"
19
20namespace ns3
21{
22
23NS_LOG_COMPONENT_DEFINE("BuildingList");
24
25/**
26 * \brief private implementation detail of the BuildingList API.
27 */
29{
30 public:
31 /**
32 * \brief Get the type ID.
33 * \return The object TypeId.
34 */
35 static TypeId GetTypeId();
37 ~BuildingListPriv() override;
38
39 /**
40 * Add a Building to the list.
41 *
42 * \param building building to add
43 * \returns index of building in list.
44 */
45 uint32_t Add(Ptr<Building> building);
46 /**
47 * Returns an iterator to the start of the list.
48 *
49 * \returns iterator to the begin of the container.
50 */
52 /**
53 * Returns an iterator to the end of the list.
54 *
55 * \returns iterator to the end of the container.
56 */
58 /**
59 * Gets the n-th Building in the container
60 * \param n Building position
61 * \returns a pointer to the Building
62 */
64 /**
65 * Gets the number of Building in the container
66 * \returns the container size
67 */
69
70 /**
71 * Get the Singleton instance of BuildingListPriv (or create one)
72 * \return the BuildingListPriv instance
73 */
75
76 private:
77 void DoDispose() override;
78 /**
79 * Get the Singleton instance of BuildingListPriv (or create one)
80 * \return the BuildingListPriv instance
81 */
83 /**
84 * Dispose the Singleton instance of BuildingListPriv.
85 *
86 * \note: this function is automatically called at the simulation end.
87 *
88 */
89 static void Delete();
90 std::vector<Ptr<Building>> m_buildings; //!< Container of Building
91};
92
94
97{
98 static TypeId tid =
99 TypeId("ns3::BuildingListPriv")
100 .SetParent<Object>()
101 .SetGroupName("Buildings")
102 .AddAttribute("BuildingList",
103 "The list of all buildings created during the simulation.",
107 return tid;
108}
109
112{
113 return *DoGet();
114}
115
118{
119 static Ptr<BuildingListPriv> ptr = nullptr;
120 if (!ptr)
121 {
125 }
126 return &ptr;
127}
128
129void
136
141
145
146void
148{
150 for (auto i = m_buildings.begin(); i != m_buildings.end(); i++)
151 {
152 Ptr<Building> building = *i;
153 building->Dispose();
154 *i = nullptr;
155 }
156 m_buildings.erase(m_buildings.begin(), m_buildings.end());
158}
159
162{
163 uint32_t index = m_buildings.size();
164 m_buildings.push_back(building);
165 Simulator::ScheduleWithContext(index, TimeStep(0), &Building::Initialize, building);
166 return index;
167}
168
171{
172 return m_buildings.begin();
173}
174
177{
178 return m_buildings.end();
179}
180
183{
184 return m_buildings.size();
185}
186
189{
190 NS_ASSERT_MSG(n < m_buildings.size(),
191 "Building index " << n << " is out of range (only have " << m_buildings.size()
192 << " buildings).");
193 return m_buildings.at(n);
194}
195
196} // namespace ns3
197
198/**
199 * The implementation of the public static-based API
200 * which calls into the private implementation through
201 * the simulation singleton.
202 */
203namespace ns3
204{
205
208{
209 return BuildingListPriv::Get()->Add(building);
210}
211
214{
215 return BuildingListPriv::Get()->Begin();
216}
217
220{
221 return BuildingListPriv::Get()->End();
222}
223
226{
227 return BuildingListPriv::Get()->GetBuilding(n);
228}
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.
static uint32_t GetNBuildings()
static Iterator End()
static uint32_t Add(Ptr< Building > building)
static Iterator Begin()
private implementation detail of the BuildingList API.
std::vector< Ptr< Building > > m_buildings
Container of Building.
void DoDispose() override
Destructor implementation.
Ptr< Building > GetBuilding(uint32_t n)
Gets the n-th Building in the container.
uint32_t GetNBuildings()
Gets the number of Building in the container.
static TypeId GetTypeId()
Get the type ID.
uint32_t Add(Ptr< Building > building)
Add a Building to the list.
static Ptr< BuildingListPriv > Get()
Get the Singleton instance of BuildingListPriv (or create one)
BuildingList::Iterator Begin() const
Returns an iterator to the start of the list.
static Ptr< BuildingListPriv > * DoGet()
Get the Singleton instance of BuildingListPriv (or create one)
static void Delete()
Dispose the Singleton instance of BuildingListPriv.
BuildingList::Iterator End() const
Returns an iterator to the end of the list.
A base class which provides memory management and object aggregation.
Definition object.h:78
void Initialize()
Invoke DoInitialize on all Objects aggregated to this one.
Definition object.cc:203
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
static void ScheduleWithContext(uint32_t context, const Time &delay, FUNC f, Ts &&... args)
Schedule an event with the given context.
Definition simulator.h:577
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:611
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#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:75
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition config.cc:1005
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition config.cc:998
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeObjectVectorChecker()
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.