A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
8 * Author: Nicola Baldo <nbaldo@cttc.es> (took position-allocator and turned it into
9 * building-allocator)
10 */
11#include "building-allocator.h"
12
13#include "ns3/building.h"
14#include "ns3/double.h"
15#include "ns3/enum.h"
16#include "ns3/log.h"
17#include "ns3/uinteger.h"
18
19#include <cmath>
20
21namespace ns3
22{
23
24NS_LOG_COMPONENT_DEFINE("BuildingAllocator");
25
26NS_OBJECT_ENSURE_REGISTERED(GridBuildingAllocator);
27
35
39
42{
43 static TypeId tid =
44 TypeId("ns3::GridBuildingAllocator")
46 .AddConstructor<GridBuildingAllocator>()
47 .SetGroupName("Buildings")
48 .AddAttribute("GridWidth",
49 "The number of objects laid out on a line.",
50 UintegerValue(10),
53 .AddAttribute("MinX",
54 "The x coordinate where the grid starts.",
55 DoubleValue(1.0),
58 .AddAttribute("MinY",
59 "The y coordinate where the grid starts.",
60 DoubleValue(0.0),
63 .AddAttribute("LengthX",
64 "The length of the wall of each building along the X axis.",
65 DoubleValue(1.0),
68 .AddAttribute("LengthY",
69 "The length of the wall of each building along the X axis.",
70 DoubleValue(1.0),
73 .AddAttribute("DeltaX",
74 "The x space between buildings.",
75 DoubleValue(1.0),
78 .AddAttribute("DeltaY",
79 "The y space between buildings.",
80 DoubleValue(1.0),
83 .AddAttribute("Height",
84 "The height of the building (roof level)",
85 DoubleValue(10),
88 .AddAttribute("LayoutType",
89 "The type of layout.",
94 "RowFirst",
96 "ColumnFirst"));
97 return tid;
98}
99
100void
106
109{
110 NS_LOG_FUNCTION(this);
113 uint32_t limit = n + m_current;
114 for (; m_current < limit; ++m_current)
115 {
116 Vector lowerLeft = m_lowerLeftPositionAllocator->GetNext();
117 Vector upperRight = m_upperRightPositionAllocator->GetNext();
118 Box box(lowerLeft.x, upperRight.x, lowerLeft.y, upperRight.y, 0, m_height);
119 NS_LOG_LOGIC("new building : " << box);
120 BoxValue boxValue(box);
121 m_buildingFactory.Set("Boundaries", boxValue);
123 bc.Add(b);
124 }
125 return bc;
126}
127
128void
148
149} // namespace ns3
Hold a value for an Attribute.
Definition attribute.h:59
a 3d box
Definition box.h:24
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:33
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Hold variables of type enum.
Definition enum.h:52
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:78
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
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 > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeDoubleChecker()
Definition double.h:82
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:179
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition double.h:32
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition enum.h:221