merge
This commit is contained in:
192
src/buildings/model/building-list.cc
Normal file
192
src/buildings/model/building-list.cc
Normal file
@@ -0,0 +1,192 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Jaume Nin <jaume.nin@cttc,cat>
|
||||
* Based on BuildingList implemenation by Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*
|
||||
*/
|
||||
#include "building-list.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/object-vector.h"
|
||||
#include "ns3/config.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/assert.h"
|
||||
#include "building-list.h"
|
||||
#include "building.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("BuildingList");
|
||||
|
||||
/**
|
||||
* \brief private implementation detail of the BuildingList API.
|
||||
*/
|
||||
class BuildingListPriv : public Object
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
BuildingListPriv ();
|
||||
~BuildingListPriv ();
|
||||
|
||||
uint32_t Add (Ptr<Building> building);
|
||||
BuildingList::Iterator Begin (void) const;
|
||||
BuildingList::Iterator End (void) const;
|
||||
Ptr<Building> GetBuilding (uint32_t n);
|
||||
uint32_t GetNBuildings (void);
|
||||
|
||||
static Ptr<BuildingListPriv> Get (void);
|
||||
|
||||
private:
|
||||
virtual void DoDispose (void);
|
||||
static Ptr<BuildingListPriv> *DoGet (void);
|
||||
static void Delete (void);
|
||||
std::vector<Ptr<Building> > m_buildings;
|
||||
};
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (BuildingListPriv);
|
||||
|
||||
TypeId
|
||||
BuildingListPriv::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::BuildingListPriv")
|
||||
.SetParent<Object> ()
|
||||
.AddAttribute ("BuildingList", "The list of all buildings created during the simulation.",
|
||||
ObjectVectorValue (),
|
||||
MakeObjectVectorAccessor (&BuildingListPriv::m_buildings),
|
||||
MakeObjectVectorChecker<Building> ())
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
Ptr<BuildingListPriv>
|
||||
BuildingListPriv::Get (void)
|
||||
{
|
||||
return *DoGet ();
|
||||
}
|
||||
Ptr<BuildingListPriv> *
|
||||
BuildingListPriv::DoGet (void)
|
||||
{
|
||||
static Ptr<BuildingListPriv> ptr = 0;
|
||||
if (ptr == 0)
|
||||
{
|
||||
ptr = CreateObject<BuildingListPriv> ();
|
||||
Config::RegisterRootNamespaceObject (ptr);
|
||||
Simulator::ScheduleDestroy (&BuildingListPriv::Delete);
|
||||
}
|
||||
return &ptr;
|
||||
}
|
||||
void
|
||||
BuildingListPriv::Delete (void)
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
Config::UnregisterRootNamespaceObject (Get ());
|
||||
(*DoGet ()) = 0;
|
||||
}
|
||||
|
||||
|
||||
BuildingListPriv::BuildingListPriv ()
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
}
|
||||
BuildingListPriv::~BuildingListPriv ()
|
||||
{
|
||||
}
|
||||
void
|
||||
BuildingListPriv::DoDispose (void)
|
||||
{
|
||||
NS_LOG_FUNCTION_NOARGS ();
|
||||
for (std::vector<Ptr<Building> >::iterator i = m_buildings.begin ();
|
||||
i != m_buildings.end (); i++)
|
||||
{
|
||||
Ptr<Building> building = *i;
|
||||
building->Dispose ();
|
||||
*i = 0;
|
||||
}
|
||||
m_buildings.erase (m_buildings.begin (), m_buildings.end ());
|
||||
Object::DoDispose ();
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
BuildingListPriv::Add (Ptr<Building> building)
|
||||
{
|
||||
uint32_t index = m_buildings.size ();
|
||||
m_buildings.push_back (building);
|
||||
Simulator::ScheduleWithContext (index, TimeStep (0), &Building::Start, building);
|
||||
return index;
|
||||
|
||||
}
|
||||
BuildingList::Iterator
|
||||
BuildingListPriv::Begin (void) const
|
||||
{
|
||||
return m_buildings.begin ();
|
||||
}
|
||||
BuildingList::Iterator
|
||||
BuildingListPriv::End (void) const
|
||||
{
|
||||
return m_buildings.end ();
|
||||
}
|
||||
uint32_t
|
||||
BuildingListPriv::GetNBuildings (void)
|
||||
{
|
||||
return m_buildings.size ();
|
||||
}
|
||||
|
||||
Ptr<Building>
|
||||
BuildingListPriv::GetBuilding (uint32_t n)
|
||||
{
|
||||
NS_ASSERT_MSG (n < m_buildings.size (), "Building index " << n <<
|
||||
" is out of range (only have " << m_buildings.size () << " buildings).");
|
||||
return m_buildings[n];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The implementation of the public static-based API
|
||||
* which calls into the private implementation through
|
||||
* the simulation singleton.
|
||||
*/
|
||||
namespace ns3 {
|
||||
|
||||
uint32_t
|
||||
BuildingList::Add (Ptr<Building> building)
|
||||
{
|
||||
return BuildingListPriv::Get ()->Add (building);
|
||||
}
|
||||
BuildingList::Iterator
|
||||
BuildingList::Begin (void)
|
||||
{
|
||||
return BuildingListPriv::Get ()->Begin ();
|
||||
}
|
||||
BuildingList::Iterator
|
||||
BuildingList::End (void)
|
||||
{
|
||||
return BuildingListPriv::Get ()->End ();
|
||||
}
|
||||
Ptr<Building>
|
||||
BuildingList::GetBuilding (uint32_t n)
|
||||
{
|
||||
return BuildingListPriv::Get ()->GetBuilding (n);
|
||||
}
|
||||
uint32_t
|
||||
BuildingList::GetNBuildings (void)
|
||||
{
|
||||
return BuildingListPriv::Get ()->GetNBuildings ();
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
71
src/buildings/model/building-list.h
Normal file
71
src/buildings/model/building-list.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Jaume Nin <jaume.nin@cttc,cat>
|
||||
* Based on NodeList implemenation by Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BUILDING_LIST_H_
|
||||
#define BUILDING_LIST_H_
|
||||
|
||||
#include <vector>
|
||||
#include "ns3/ptr.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Building;
|
||||
|
||||
class BuildingList
|
||||
{
|
||||
public:
|
||||
typedef std::vector< Ptr<Building> >::const_iterator Iterator;
|
||||
|
||||
/**
|
||||
* \param building building to add
|
||||
* \returns index of building in list.
|
||||
*
|
||||
* This method is called automatically from Building::Building so
|
||||
* the user has little reason to call it himself.
|
||||
*/
|
||||
static uint32_t Add (Ptr<Building> building);
|
||||
/**
|
||||
* \returns a C++ iterator located at the beginning of this
|
||||
* list.
|
||||
*/
|
||||
static Iterator Begin (void);
|
||||
/**
|
||||
* \returns a C++ iterator located at the end of this
|
||||
* list.
|
||||
*/
|
||||
static Iterator End (void);
|
||||
/**
|
||||
* \param n index of requested building.
|
||||
* \returns the Building associated to index n.
|
||||
*/
|
||||
static Ptr<Building> GetBuilding (uint32_t n);
|
||||
/**
|
||||
* \returns the number of buildings currently in the list.
|
||||
*/
|
||||
static uint32_t GetNBuildings (void);
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* BUILDING_LIST_H_ */
|
||||
|
||||
|
||||
@@ -21,12 +21,43 @@
|
||||
|
||||
|
||||
#include <ns3/building.h>
|
||||
#include <ns3/building-list.h>
|
||||
#include <ns3/enum.h>
|
||||
|
||||
#include "ns3/uinteger.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
|
||||
TypeId
|
||||
Building::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::Building")
|
||||
.SetParent<Object> ()
|
||||
.AddConstructor<Building> ()
|
||||
.AddAttribute ("roomX", "The number of rooms in the X axis.",
|
||||
TypeId::ATTR_GET, // allow only getting it.
|
||||
UintegerValue (4),
|
||||
MakeUintegerAccessor (&Building::m_roomX),
|
||||
MakeUintegerChecker<uint32_t> ())
|
||||
.AddAttribute ("roomY", "The number of rooms in the Y axis.",
|
||||
TypeId::ATTR_GET, // allow only getting it.
|
||||
UintegerValue (1),
|
||||
MakeUintegerAccessor (&Building::m_roomY),
|
||||
MakeUintegerChecker<uint32_t> ())
|
||||
.AddAttribute ("nFloor", "The number of floors of this building.",
|
||||
TypeId::ATTR_GET, // allow only getting it.
|
||||
UintegerValue (1),
|
||||
MakeUintegerAccessor (&Building::m_floor),
|
||||
MakeUintegerChecker<uint32_t> ())
|
||||
.AddAttribute ("Id", "The id (unique integer) of this Building.",
|
||||
TypeId::ATTR_GET, // allow only getting it.
|
||||
UintegerValue (0),
|
||||
MakeUintegerAccessor (&Building::m_buildingId),
|
||||
MakeUintegerChecker<uint32_t> ())
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
Building::Building (double _xMin, double _xMax,
|
||||
double _yMin, double _yMax,
|
||||
double _zMin, double _zMax/*,
|
||||
@@ -39,6 +70,7 @@ Building::Building (double _xMin, double _xMax,
|
||||
|
||||
{
|
||||
m_buldingBounds = Box (_xMin, _xMax, _yMin, _yMax, _zMin, _zMax);
|
||||
Construct();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +82,14 @@ Building::Building ()
|
||||
m_externalWalls (ConcreteWithWindows)
|
||||
{
|
||||
m_buldingBounds = Box ();
|
||||
Construct();
|
||||
}
|
||||
|
||||
void
|
||||
Building::Construct ()
|
||||
{
|
||||
m_buildingId = BuildingList::Add(this);
|
||||
}
|
||||
|
||||
void
|
||||
Building::SetBuildingType (Building::BuildingType_t t)
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <ns3/vector.h>
|
||||
#include <ns3/box.h>
|
||||
#include <ns3/simple-ref-count.h>
|
||||
|
||||
#include <ns3/object.h>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -34,9 +34,11 @@ namespace ns3 {
|
||||
* \ingroup mobility
|
||||
* \brief a 3d building block
|
||||
*/
|
||||
class Building : public SimpleRefCount<Building>
|
||||
class Building : public Object
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
enum BuildingType_t
|
||||
{
|
||||
Residential, Office, Commercial
|
||||
@@ -69,7 +71,6 @@ public:
|
||||
*/
|
||||
Building ();
|
||||
|
||||
|
||||
/**
|
||||
* \param t the type of building (i.e., Residential, Office, Commercial)
|
||||
*
|
||||
@@ -150,6 +151,9 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void Construct ();
|
||||
|
||||
Box m_buldingBounds;
|
||||
/**
|
||||
* number of floors must be greater then 0 and 1 means only one floor
|
||||
@@ -159,7 +163,7 @@ private:
|
||||
uint8_t m_roomX;
|
||||
uint8_t m_roomY;
|
||||
|
||||
uint8_t m_buildingId;
|
||||
uint32_t m_buildingId;
|
||||
BuildingType_t m_buildingType;
|
||||
ExtWallsType_t m_externalWalls;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ def build(bld):
|
||||
module = bld.create_ns3_module('buildings', ['mobility', 'propagation'])
|
||||
module.source = [
|
||||
'model/building.cc',
|
||||
'model/building-list.cc',
|
||||
'model/buildings-mobility-model.cc',
|
||||
'model/buildings-propagation-loss-model.cc',
|
||||
]
|
||||
@@ -19,6 +20,7 @@ def build(bld):
|
||||
headers.module = 'buildings'
|
||||
headers.source = [
|
||||
'model/building.h',
|
||||
'model/building-list.h',
|
||||
'model/buildings-mobility-model.h',
|
||||
'model/buildings-propagation-loss-model.h',
|
||||
'test/buildings-pathloss-test.h',
|
||||
|
||||
Reference in New Issue
Block a user