A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
buildings-mobility-model.cc
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 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: Marco Miozzo <marco.miozzo@cttc.es>
19  *
20  */
21 
22 #include <ns3/simulator.h>
23 #include <ns3/position-allocator.h>
24 #include <ns3/buildings-mobility-model.h>
25 #include <ns3/pointer.h>
26 #include <ns3/log.h>
27 #include <ns3/assert.h>
28 
29 NS_LOG_COMPONENT_DEFINE ("BuildingsMobilityModel");
30 
31 namespace ns3 {
32 
33 NS_OBJECT_ENSURE_REGISTERED (BuildingsMobilityModel);
34 
35 TypeId
36 BuildingsMobilityModel::GetTypeId (void)
37 {
38  static TypeId tid = TypeId ("ns3::BuildingsMobilityModel")
39  .SetParent<MobilityModel> ()
40  .SetGroupName ("Mobility")
41  .AddConstructor<BuildingsMobilityModel> ();
42 
43  return tid;
44 }
45 
46 
47 BuildingsMobilityModel::BuildingsMobilityModel ()
48 {
49  NS_LOG_FUNCTION (this);
50  m_indoor = false;
51  m_nFloor = 1;
52  m_roomX = 1;
53  m_roomY = 1;
54 }
55 
56 void
58 {
59  NS_LOG_FUNCTION (this);
61 }
62 
63 Vector
65 {
66  NS_LOG_FUNCTION (this);
67  m_helper.Update ();
68  return m_helper.GetCurrentPosition ();
69 }
70 void
72 {
73  NS_LOG_FUNCTION (this);
74  m_helper.SetPosition (position);
75 }
76 Vector
78 {
79  NS_LOG_FUNCTION (this);
80  return m_helper.GetVelocity ();
81 }
82 
83 bool
85 {
86  NS_LOG_FUNCTION (this);
87  return (m_indoor);
88 }
89 
90 bool
92 {
93  NS_LOG_FUNCTION (this);
94  return (!m_indoor);
95 }
96 
97 void
98 BuildingsMobilityModel::SetIndoor (Ptr<Building> building, uint8_t nfloor, uint8_t nroomx, uint8_t nroomy)
99 {
100  NS_LOG_FUNCTION (this);
101  m_indoor = true;
102  m_myBuilding = building;
103  m_nFloor = nfloor;
104  m_roomX = nroomx;
105  m_roomY = nroomy;
106 
107  NS_ASSERT_MSG (building->IsInside (m_helper.GetCurrentPosition ()), "Position of the node is outside of building bounds");
108  NS_ASSERT (m_roomX > 0);
109  NS_ASSERT (m_roomX <= building->GetNRoomsX ());
110  NS_ASSERT (m_roomY > 0);
111  NS_ASSERT (m_roomY <= building->GetNRoomsY ());
112  NS_ASSERT (m_nFloor > 0);
113  NS_ASSERT (m_nFloor <= building->GetNFloors ());
114 
115 }
116 
117 
118 void
120 {
121  NS_LOG_FUNCTION (this);
122  m_indoor = false;
123 }
124 
125 uint8_t
127 {
128  NS_LOG_FUNCTION (this);
129  return (m_nFloor);
130 }
131 
132 uint8_t
134 {
135  NS_LOG_FUNCTION (this);
136  return (m_roomX);
137 }
138 
139 uint8_t
141 {
142  NS_LOG_FUNCTION (this);
143  return (m_roomY);
144 }
145 
146 
149 {
150  NS_LOG_FUNCTION (this);
151  return (m_myBuilding);
152 }
153 
154 
155 } // namespace
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
virtual Vector DoGetPosition(void) const
virtual void DoDispose(void)
Definition: object.cc:335
a 3d vector
Definition: vector.h:31
virtual void DoSetPosition(const Vector &position)
virtual Vector DoGetVelocity(void) const
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
void SetIndoor(Ptr< Building > building, uint8_t nfloor, uint8_t nroomx, uint8_t nroomy)