A Discrete-Event Network Simulator
API
building-allocator.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 INRIA
3  * Copyright (C) 2012 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Author: Nicola Baldo <nbaldo@cttc.es> (took position-allocator and turned it into
20  * building-allocator)
21  */
22 #include "building-allocator.h"
23 
24 #include "ns3/building.h"
25 #include "ns3/double.h"
26 #include "ns3/enum.h"
27 #include "ns3/log.h"
28 #include "ns3/uinteger.h"
29 
30 #include <cmath>
31 
32 namespace ns3
33 {
34 
35 NS_LOG_COMPONENT_DEFINE("BuildingAllocator");
36 
37 NS_OBJECT_ENSURE_REGISTERED(GridBuildingAllocator);
38 
40  : m_current(0)
41 {
42  m_buildingFactory.SetTypeId("ns3::Building");
43  m_lowerLeftPositionAllocator = CreateObject<GridPositionAllocator>();
44  m_upperRightPositionAllocator = CreateObject<GridPositionAllocator>();
45 }
46 
48 {
49 }
50 
51 TypeId
53 {
54  static TypeId tid =
55  TypeId("ns3::GridBuildingAllocator")
56  .SetParent<Object>()
57  .AddConstructor<GridBuildingAllocator>()
58  .SetGroupName("Buildings")
59  .AddAttribute("GridWidth",
60  "The number of objects laid out on a line.",
61  UintegerValue(10),
63  MakeUintegerChecker<uint32_t>())
64  .AddAttribute("MinX",
65  "The x coordinate where the grid starts.",
66  DoubleValue(1.0),
68  MakeDoubleChecker<double>())
69  .AddAttribute("MinY",
70  "The y coordinate where the grid starts.",
71  DoubleValue(0.0),
73  MakeDoubleChecker<double>())
74  .AddAttribute("LengthX",
75  "The length of the wall of each building along the X axis.",
76  DoubleValue(1.0),
78  MakeDoubleChecker<double>())
79  .AddAttribute("LengthY",
80  "The length of the wall of each building along the X axis.",
81  DoubleValue(1.0),
83  MakeDoubleChecker<double>())
84  .AddAttribute("DeltaX",
85  "The x space between buildings.",
86  DoubleValue(1.0),
88  MakeDoubleChecker<double>())
89  .AddAttribute("DeltaY",
90  "The y space between buildings.",
91  DoubleValue(1.0),
93  MakeDoubleChecker<double>())
94  .AddAttribute("Height",
95  "The height of the building (roof level)",
96  DoubleValue(10),
98  MakeDoubleChecker<double>())
99  .AddAttribute("LayoutType",
100  "The type of layout.",
102  MakeEnumAccessor<GridPositionAllocator::LayoutType>(
105  "RowFirst",
107  "ColumnFirst"));
108  return tid;
109 }
110 
111 void
113 {
114  NS_LOG_FUNCTION(this);
115  m_buildingFactory.Set(n, v);
116 }
117 
120 {
121  NS_LOG_FUNCTION(this);
122  PushAttributes();
124  uint32_t limit = n + m_current;
125  for (; m_current < limit; ++m_current)
126  {
127  Vector lowerLeft = m_lowerLeftPositionAllocator->GetNext();
128  Vector upperRight = m_upperRightPositionAllocator->GetNext();
129  Box box(lowerLeft.x, upperRight.x, lowerLeft.y, upperRight.y, 0, m_height);
130  NS_LOG_LOGIC("new building : " << box);
131  BoxValue boxValue(box);
132  m_buildingFactory.Set("Boundaries", boxValue);
134  bc.Add(b);
135  }
136  return bc;
137 }
138 
139 void
141 {
142  NS_LOG_FUNCTION(this);
147 
152 
155 
158 }
159 
160 } // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
a 3d box
Definition: box.h:35
keep track of a set of building pointers.
void Add(BuildingContainer other)
Append the contents of another BuildingContainer to the end of this container.
a 3d building block
Definition: building.h:38
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold variables of type enum.
Definition: enum.h:62
void SetBuildingAttribute(std::string n, const AttributeValue &v)
Set an attribute to be used for each new building to be created.
double m_yMin
The y coordinate where the grid starts.
ObjectFactory m_buildingFactory
The building factory.
GridPositionAllocator::LayoutType m_layoutType
Layout type.
static TypeId GetTypeId()
Get the type ID.
double m_xMin
The x coordinate where the grid starts.
uint32_t m_n
The number of objects laid out on a line.
BuildingContainer Create(uint32_t n) const
Create a set of buildings allocated on a grid.
double m_deltaX
The x space between buildings.
Ptr< GridPositionAllocator > m_lowerLeftPositionAllocator
The upper left position allocator.
double m_lengthX
The length of the wall of each building along the X axis.
void PushAttributes() const
Pushes the attributes into the relevant position allocators.
uint32_t m_current
Current building number.
double m_deltaY
The y space between buildings.
double m_height
The height of the building (roof level)
double m_lengthY
The length of the wall of each building along the Y axis.
Ptr< GridPositionAllocator > m_upperRightPositionAllocator
The upper right position allocator.
@ COLUMN_FIRST
In column-first mode, positions are allocated on the first column until N positions have been allocat...
@ ROW_FIRST
In row-first mode, positions are allocated on the first row until N positions have been allocated.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:194
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46