owlps/owlps-positioning/building.cc

89 lines
1.4 KiB
C++
Raw Normal View History

#include "building.hh"
#include "area.hh"
#include "waypoint.hh"
using namespace std ;
/* *** Constructors *** */
Building::Building(const string &_name)
{
name = _name ;
}
Building::Building(const Building &b)
{
name = b.name ;
areas = b.areas ;
waypoints = b.waypoints ;
}
/**
* Note: deletes (unallocates) all elements in #areas; deletes elements
* in #waypoints that belong only to this Building (waypoints that link
* several buildings are preserved).
*/
Building::~Building()
{
// Empty Area list
for (vector<Area*>::iterator i = areas.begin() ; i != areas.end() ; ++i)
delete *i ;
areas.clear() ;
// Empty Waypoint list
for (vector<Waypoint*>::iterator i = waypoints.begin() ;
i != waypoints.end() ; ++i)
{
// Delete current waypoint only if it is not linked to another building
if ((*i)->get_buildings().size() <= 1)
delete *i ;
}
waypoints.clear() ;
}
/* *** Operators *** */
const Building& Building::operator=(const Building &b)
{
if (this == &b)
return *this ;
name = b.name ;
areas = b.areas ;
waypoints = b.waypoints ;
return *this;
}
bool Building::operator==(const Building &b) const
{
if (this == &b)
return true ;
return
name == b.name &&
areas == b.areas &&
waypoints == b.waypoints ;
}
ostream& operator<<(ostream &os, const Building &b)
{
os << b.name ;
return os ;
}