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-allocator.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 INRIA
4
* Copyright (C) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
* Author: Nicola Baldo <nbaldo@cttc.es> (took position-allocator and turned it into building-allocator)
21
*/
22
#include "
building-allocator.h
"
23
#include "ns3/building.h"
24
#include "ns3/double.h"
25
#include "ns3/uinteger.h"
26
#include "ns3/enum.h"
27
#include "ns3/log.h"
28
#include <cmath>
29
30
NS_LOG_COMPONENT_DEFINE
(
"BuildingAllocator"
);
31
32
namespace
ns3 {
33
34
NS_OBJECT_ENSURE_REGISTERED
(GridBuildingAllocator);
35
36
GridBuildingAllocator::GridBuildingAllocator
()
37
: m_current (0)
38
{
39
m_buildingFactory
.
SetTypeId
(
"ns3::Building"
);
40
m_lowerLeftPositionAllocator
= CreateObject<GridPositionAllocator> ();
41
m_upperRightPositionAllocator
= CreateObject<GridPositionAllocator> ();
42
}
43
44
GridBuildingAllocator::~GridBuildingAllocator
()
45
{
46
}
47
48
TypeId
49
GridBuildingAllocator::GetTypeId
(
void
)
50
{
51
static
TypeId
tid =
TypeId
(
"ns3::GridBuildingAllocator"
)
52
.
SetParent
<
Object
> ()
53
.AddConstructor<GridBuildingAllocator> ()
54
.AddAttribute (
"GridWidth"
,
"The number of objects layed out on a line."
,
55
UintegerValue
(10),
56
MakeUintegerAccessor (&
GridBuildingAllocator::m_n
),
57
MakeUintegerChecker<uint32_t> ())
58
.AddAttribute (
"MinX"
,
"The x coordinate where the grid starts."
,
59
DoubleValue
(1.0),
60
MakeDoubleAccessor (&
GridBuildingAllocator::m_xMin
),
61
MakeDoubleChecker<double> ())
62
.AddAttribute (
"MinY"
,
"The y coordinate where the grid starts."
,
63
DoubleValue
(0.0),
64
MakeDoubleAccessor (&
GridBuildingAllocator::m_yMin
),
65
MakeDoubleChecker<double> ())
66
.AddAttribute (
"LengthX"
,
" the length of the wall of each building along the X axis."
,
67
DoubleValue
(1.0),
68
MakeDoubleAccessor (&
GridBuildingAllocator::m_lengthX
),
69
MakeDoubleChecker<double> ())
70
.AddAttribute (
"LengthY"
,
" the length of the wall of each building along the X axis."
,
71
DoubleValue
(1.0),
72
MakeDoubleAccessor (&
GridBuildingAllocator::m_lengthY
),
73
MakeDoubleChecker<double> ())
74
.AddAttribute (
"DeltaX"
,
"The x space between buildings."
,
75
DoubleValue
(1.0),
76
MakeDoubleAccessor (&
GridBuildingAllocator::m_deltaX
),
77
MakeDoubleChecker<double> ())
78
.AddAttribute (
"DeltaY"
,
"The y space between buildings."
,
79
DoubleValue
(1.0),
80
MakeDoubleAccessor (&
GridBuildingAllocator::m_deltaY
),
81
MakeDoubleChecker<double> ())
82
.AddAttribute (
"Height"
,
"The height of the building (roof level)"
,
83
DoubleValue
(10),
84
MakeDoubleAccessor (&
GridBuildingAllocator::m_height
),
85
MakeDoubleChecker<double> ())
86
.AddAttribute (
"LayoutType"
,
"The type of layout."
,
87
EnumValue
(
GridPositionAllocator::ROW_FIRST
),
88
MakeEnumAccessor
(&
GridBuildingAllocator::m_layoutType
),
89
MakeEnumChecker
(
GridPositionAllocator::ROW_FIRST
,
"RowFirst"
,
90
GridPositionAllocator::COLUMN_FIRST
,
"ColumnFirst"
))
91
;
92
return
tid;
93
}
94
95
void
96
GridBuildingAllocator::SetBuildingAttribute
(std::string n,
const
AttributeValue
&v)
97
{
98
NS_LOG_FUNCTION
(
this
);
99
m_buildingFactory
.
Set
(n, v);
100
}
101
102
BuildingContainer
103
GridBuildingAllocator::Create
(uint32_t n)
const
104
{
105
NS_LOG_FUNCTION
(
this
);
106
PushAttributes
();
107
BuildingContainer
bc;
108
uint32_t limit = n +
m_current
;
109
for
(; m_current < limit; ++
m_current
)
110
{
111
Vector
lowerLeft =
m_lowerLeftPositionAllocator
->
GetNext
();
112
Vector
upperRight =
m_upperRightPositionAllocator
->
GetNext
();
113
Box
box (lowerLeft.
x
, upperRight.
x
, lowerLeft.
y
, upperRight.
y
, 0,
m_height
);
114
NS_LOG_LOGIC
(
"new building : "
<< box);
115
BoxValue
boxValue (box);
116
m_buildingFactory
.
Set
(
"Boundaries"
, boxValue);
117
Ptr<Building>
b =
m_buildingFactory
.
Create
<
Building
> ();
118
bc.
Add
(b);
119
}
120
return
bc;
121
}
122
123
void
124
GridBuildingAllocator::PushAttributes
()
const
125
{
126
NS_LOG_FUNCTION
(
this
);
127
m_lowerLeftPositionAllocator
->
SetMinX
(
m_xMin
);
128
m_upperRightPositionAllocator
->
SetMinX
(
m_xMin
+
m_lengthX
);
129
m_lowerLeftPositionAllocator
->
SetDeltaX
(
m_lengthX
+
m_deltaX
);
130
m_upperRightPositionAllocator
->
SetDeltaX
(
m_lengthX
+
m_deltaX
);
131
132
m_lowerLeftPositionAllocator
->
SetMinY
(
m_yMin
);
133
m_upperRightPositionAllocator
->
SetMinY
(
m_yMin
+
m_lengthY
);
134
m_lowerLeftPositionAllocator
->
SetDeltaY
(
m_lengthY
+
m_deltaY
);
135
m_upperRightPositionAllocator
->
SetDeltaY
(
m_lengthY
+
m_deltaY
);
136
137
m_lowerLeftPositionAllocator
->
SetLayoutType
(
m_layoutType
);
138
m_upperRightPositionAllocator
->
SetLayoutType
(
m_layoutType
);
139
140
m_lowerLeftPositionAllocator
->
SetN
(
m_n
);
141
m_upperRightPositionAllocator
->
SetN
(
m_n
);
142
}
143
144
145
}
// namespace ns3
src
buildings
helper
building-allocator.cc
Generated on Tue Oct 9 2012 16:45:33 for ns-3 by
1.8.1.2