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  .AddAttribute ("GridWidth", "The number of objects layed out on a line.",
55  UintegerValue (10),
57  MakeUintegerChecker<uint32_t> ())
58  .AddAttribute ("MinX", "The x coordinate where the grid starts.",
59  DoubleValue (1.0),
61  MakeDoubleChecker<double> ())
62  .AddAttribute ("MinY", "The y coordinate where the grid starts.",
63  DoubleValue (0.0),
65  MakeDoubleChecker<double> ())
66  .AddAttribute ("LengthX", " the length of the wall of each building along the X axis.",
67  DoubleValue (1.0),
69  MakeDoubleChecker<double> ())
70  .AddAttribute ("LengthY", " the length of the wall of each building along the X axis.",
71  DoubleValue (1.0),
73  MakeDoubleChecker<double> ())
74  .AddAttribute ("DeltaX", "The x space between buildings.",
75  DoubleValue (1.0),
77  MakeDoubleChecker<double> ())
78  .AddAttribute ("DeltaY", "The y space between buildings.",
79  DoubleValue (1.0),
81  MakeDoubleChecker<double> ())
82  .AddAttribute ("Height", "The height of the building (roof level)",
83  DoubleValue (10),
85  MakeDoubleChecker<double> ())
86  .AddAttribute ("LayoutType", "The type of layout.",
91  ;
92  return tid;
93 }
94 
95 void
97 {
98  NS_LOG_FUNCTION (this);
99  m_buildingFactory.Set (n, v);
100 }
101 
104 {
105  NS_LOG_FUNCTION (this);
106  PushAttributes ();
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);
118  bc.Add (b);
119  }
120  return bc;
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this);
131 
136 
139 
142 }
143 
144 
145 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
static TypeId GetTypeId(void)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
Hold a value for an Attribute.
Definition: attribute.h:68
void Add(BuildingContainer other)
Append the contents of another BuildingContainer to the end of this container.
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:209
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< GridPositionAllocator > m_lowerLeftPositionAllocator
In row-first mode, positions are allocated on the first row until N positions have been allocated...
a 3d box
Definition: box.h:34
enum GridPositionAllocator::LayoutType m_layoutType
Ptr< GridPositionAllocator > m_upperRightPositionAllocator
Hold variables of type enum.
Definition: enum.h:54
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
BuildingContainer Create(uint32_t n) const
Create a set of buildings allocated on a grid.
Hold an unsigned integer type.
Definition: uinteger.h:44
keep track of a set of building pointers.
AttributeValue implementation for Box.
Definition: box.h:109
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
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
void SetBuildingAttribute(std::string n, const AttributeValue &v)
Set an attribute to be used for each new building to be created.
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
a 3d building block
Definition: building.h:37
A base class which provides memory management and object aggregation.
Definition: object.h:87
In column-first mode, positions are allocated on the first column until N positions have been allocat...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
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
a unique identifier for an interface.
Definition: type-id.h:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631