A Discrete-Event Network Simulator
API
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 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("BuildingAllocator");
33 
34 NS_OBJECT_ENSURE_REGISTERED (GridBuildingAllocator);
35 
37  : m_current (0)
38 {
39  m_buildingFactory.SetTypeId ("ns3::Building");
40  m_lowerLeftPositionAllocator = CreateObject<GridPositionAllocator> ();
41  m_upperRightPositionAllocator = CreateObject<GridPositionAllocator> ();
42 }
43 
45 {
46 }
47 
48 TypeId
50 {
51  static TypeId tid = TypeId ("ns3::GridBuildingAllocator")
52  .SetParent<Object> ()
53  .AddConstructor<GridBuildingAllocator> ()
54  .SetGroupName ("Buildings")
55  .AddAttribute ("GridWidth", "The number of objects laid out on a line.",
56  UintegerValue (10),
58  MakeUintegerChecker<uint32_t> ())
59  .AddAttribute ("MinX", "The x coordinate where the grid starts.",
60  DoubleValue (1.0),
62  MakeDoubleChecker<double> ())
63  .AddAttribute ("MinY", "The y coordinate where the grid starts.",
64  DoubleValue (0.0),
66  MakeDoubleChecker<double> ())
67  .AddAttribute ("LengthX", " the length of the wall of each building along the X axis.",
68  DoubleValue (1.0),
70  MakeDoubleChecker<double> ())
71  .AddAttribute ("LengthY", " the length of the wall of each building along the X axis.",
72  DoubleValue (1.0),
74  MakeDoubleChecker<double> ())
75  .AddAttribute ("DeltaX", "The x space between buildings.",
76  DoubleValue (1.0),
78  MakeDoubleChecker<double> ())
79  .AddAttribute ("DeltaY", "The y space between buildings.",
80  DoubleValue (1.0),
82  MakeDoubleChecker<double> ())
83  .AddAttribute ("Height", "The height of the building (roof level)",
84  DoubleValue (10),
86  MakeDoubleChecker<double> ())
87  .AddAttribute ("LayoutType", "The type of layout.",
92  ;
93  return tid;
94 }
95 
96 void
98 {
99  NS_LOG_FUNCTION (this);
100  m_buildingFactory.Set (n, v);
101 }
102 
105 {
106  NS_LOG_FUNCTION (this);
107  PushAttributes ();
109  uint32_t limit = n + m_current;
110  for (; m_current < limit; ++m_current)
111  {
112  Vector lowerLeft = m_lowerLeftPositionAllocator->GetNext ();
113  Vector upperRight = m_upperRightPositionAllocator->GetNext ();
114  Box box (lowerLeft.x, upperRight.x, lowerLeft.y, upperRight.y, 0, m_height);
115  NS_LOG_LOGIC ("new building : " << box);
116  BoxValue boxValue (box);
117  m_buildingFactory.Set ("Boundaries", boxValue);
119  bc.Add (b);
120  }
121  return bc;
122 }
123 
124 void
126 {
127  NS_LOG_FUNCTION (this);
132 
137 
140 
143 }
144 
145 
146 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::BuildingContainer
keep track of a set of building pointers.
Definition: building-container.h:41
building-allocator.h
ns3::GridBuildingAllocator::m_lengthY
double m_lengthY
Definition: building-allocator.h:79
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::GridBuildingAllocator::m_layoutType
enum GridPositionAllocator::LayoutType m_layoutType
Definition: building-allocator.h:74
ns3::GridBuildingAllocator::m_buildingFactory
ObjectFactory m_buildingFactory
Definition: building-allocator.h:84
ns3::MakeEnumChecker
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:161
ns3::GridBuildingAllocator::m_lowerLeftPositionAllocator
Ptr< GridPositionAllocator > m_lowerLeftPositionAllocator
Definition: building-allocator.h:85
ns3::GridBuildingAllocator::m_upperRightPositionAllocator
Ptr< GridPositionAllocator > m_upperRightPositionAllocator
Definition: building-allocator.h:86
ns3::AttributeValue
Hold a value for an Attribute.
Definition: attribute.h:69
ns3::GridBuildingAllocator::m_current
uint32_t m_current
Definition: building-allocator.h:73
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::EnumValue
Hold variables of type enum.
Definition: enum.h:55
ns3::GridBuildingAllocator::PushAttributes
void PushAttributes() const
Definition: building-allocator.cc:125
ns3::GridBuildingAllocator::m_yMin
double m_yMin
Definition: building-allocator.h:76
ns3::GridBuildingAllocator::GetTypeId
static TypeId GetTypeId(void)
Definition: building-allocator.cc:49
ns3::GridPositionAllocator::COLUMN_FIRST
@ COLUMN_FIRST
In column-first mode, positions are allocated on the first column until N positions have been allocat...
Definition: position-allocator.h:150
ns3::GridBuildingAllocator::~GridBuildingAllocator
virtual ~GridBuildingAllocator()
Definition: building-allocator.cc:44
ns3::GridBuildingAllocator::GridBuildingAllocator
GridBuildingAllocator()
Definition: building-allocator.cc:36
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::GridBuildingAllocator::m_deltaY
double m_deltaY
Definition: building-allocator.h:81
ns3::GridBuildingAllocator::m_deltaX
double m_deltaX
Definition: building-allocator.h:80
ns3::Building
a 3d building block
Definition: building.h:38
ns3::GridBuildingAllocator::m_lengthX
double m_lengthX
Definition: building-allocator.h:78
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
ns3::GridPositionAllocator::ROW_FIRST
@ ROW_FIRST
In row-first mode, positions are allocated on the first row until N positions have been allocated.
Definition: position-allocator.h:144
ns3::GridBuildingAllocator::Create
BuildingContainer Create(uint32_t n) const
Create a set of buildings allocated on a grid.
Definition: building-allocator.cc:104
ns3::GridBuildingAllocator::m_n
uint32_t m_n
Definition: building-allocator.h:77
ns3::BuildingContainer::Add
void Add(BuildingContainer other)
Append the contents of another BuildingContainer to the end of this container.
Definition: building-container.cc:72
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
ns3::MakeDoubleAccessor
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:42
ns3::GridBuildingAllocator::m_height
double m_height
Definition: building-allocator.h:82
ns3::MakeEnumAccessor
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: enum.h:203
ns3::ObjectFactory::Set
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Definition: object-factory.h:223
ns3::GridBuildingAllocator::SetBuildingAttribute
void SetBuildingAttribute(std::string n, const AttributeValue &v)
Set an attribute to be used for each new building to be created.
Definition: building-allocator.cc:97
ns3::Box
a 3d box
Definition: box.h:35
ns3::BoxValue
AttributeValue implementation for Box.
Definition: box.h:126
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::ObjectFactory::SetTypeId
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Definition: object-factory.cc:40
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::ObjectFactory::Create
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Definition: object-factory.cc:98
ns3::MakeUintegerAccessor
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37
ns3::GridBuildingAllocator::m_xMin
double m_xMin
Definition: building-allocator.h:75