A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
38
class
BuildingListPriv
:
public
Object
39
{
40
public
:
41
static
TypeId
GetTypeId
(
void
);
42
BuildingListPriv
();
43
~BuildingListPriv
();
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
60
NS_OBJECT_ENSURE_REGISTERED
(
BuildingListPriv
);
61
62
TypeId
63
BuildingListPriv::GetTypeId
(
void
)
64
{
65
static
TypeId
tid =
TypeId
(
"ns3::BuildingListPriv"
)
66
.
SetParent
<
Object
> ()
67
.AddAttribute (
"BuildingList"
,
"The list of all buildings created during the simulation."
,
68
ObjectVectorValue
(),
69
MakeObjectVectorAccessor
(&
BuildingListPriv::m_buildings
),
70
MakeObjectVectorChecker<Building> ())
71
;
72
return
tid;
73
}
74
75
Ptr<BuildingListPriv>
76
BuildingListPriv::Get
(
void
)
77
{
78
return
*
DoGet
();
79
}
80
Ptr<BuildingListPriv>
*
81
BuildingListPriv::DoGet
(
void
)
82
{
83
static
Ptr<BuildingListPriv>
ptr = 0;
84
if
(ptr == 0)
85
{
86
ptr = CreateObject<BuildingListPriv> ();
87
Config::RegisterRootNamespaceObject
(ptr);
88
Simulator::ScheduleDestroy
(&
BuildingListPriv::Delete
);
89
}
90
return
&ptr;
91
}
92
void
93
BuildingListPriv::Delete
(
void
)
94
{
95
NS_LOG_FUNCTION_NOARGS
();
96
Config::UnregisterRootNamespaceObject
(
Get
());
97
(*
DoGet
()) = 0;
98
}
99
100
101
BuildingListPriv::BuildingListPriv
()
102
{
103
NS_LOG_FUNCTION_NOARGS
();
104
}
105
BuildingListPriv::~BuildingListPriv
()
106
{
107
}
108
void
109
BuildingListPriv::DoDispose
(
void
)
110
{
111
NS_LOG_FUNCTION_NOARGS
();
112
for
(std::vector<
Ptr<Building>
>::iterator i =
m_buildings
.begin ();
113
i !=
m_buildings
.end (); i++)
114
{
115
Ptr<Building>
building = *i;
116
building->
Dispose
();
117
*i = 0;
118
}
119
m_buildings
.erase (
m_buildings
.begin (),
m_buildings
.end ());
120
Object::DoDispose
();
121
}
122
123
124
uint32_t
125
BuildingListPriv::Add
(
Ptr<Building>
building)
126
{
127
uint32_t index =
m_buildings
.size ();
128
m_buildings
.push_back (building);
129
Simulator::ScheduleWithContext
(index,
TimeStep
(0), &
Building::Start
, building);
130
return
index;
131
132
}
133
BuildingList::Iterator
134
BuildingListPriv::Begin
(
void
)
const
135
{
136
return
m_buildings
.begin ();
137
}
138
BuildingList::Iterator
139
BuildingListPriv::End
(
void
)
const
140
{
141
return
m_buildings
.end ();
142
}
143
uint32_t
144
BuildingListPriv::GetNBuildings
(
void
)
145
{
146
return
m_buildings
.size ();
147
}
148
149
Ptr<Building>
150
BuildingListPriv::GetBuilding
(uint32_t n)
151
{
152
NS_ASSERT_MSG
(n <
m_buildings
.size (),
"Building index "
<< n <<
153
" is out of range (only have "
<<
m_buildings
.size () <<
" buildings)."
);
154
return
m_buildings
.at (n);
155
}
156
157
}
158
164
namespace
ns3 {
165
166
uint32_t
167
BuildingList::Add
(
Ptr<Building>
building)
168
{
169
return
BuildingListPriv::Get
()->Add (building);
170
}
171
BuildingList::Iterator
172
BuildingList::Begin
(
void
)
173
{
174
return
BuildingListPriv::Get
()->Begin ();
175
}
176
BuildingList::Iterator
177
BuildingList::End
(
void
)
178
{
179
return
BuildingListPriv::Get
()->End ();
180
}
181
Ptr<Building>
182
BuildingList::GetBuilding
(uint32_t n)
183
{
184
return
BuildingListPriv::Get
()->GetBuilding (n);
185
}
186
uint32_t
187
BuildingList::GetNBuildings
(
void
)
188
{
189
return
BuildingListPriv::Get
()->GetNBuildings ();
190
}
191
192
}
// namespace ns3
src
buildings
model
building-list.cc
Generated on Tue Oct 9 2012 16:45:33 for ns-3 by
1.8.1.2