2009-12-07 16:03:53 +01:00
|
|
|
#include "building.hh"
|
|
|
|
#include "waypoint.hh"
|
|
|
|
#include "area.hh"
|
|
|
|
|
|
|
|
|
2010-01-04 17:10:42 +01:00
|
|
|
using namespace std ;
|
|
|
|
|
|
|
|
|
2009-12-07 16:03:53 +01:00
|
|
|
|
|
|
|
/*** Constructeurs ***/
|
|
|
|
|
|
|
|
|
|
|
|
Building::Building(const string &_name)
|
|
|
|
{
|
|
|
|
name = _name ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Building::Building(const Building &b)
|
|
|
|
{
|
|
|
|
name = b.name ;
|
|
|
|
areas = b.areas ;
|
|
|
|
waypoints = b.waypoints ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destructor
|
|
|
|
* 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
|
2010-01-04 16:37:18 +01:00
|
|
|
for (vector<Area*>::iterator i = areas.begin() ; i != areas.end() ; i++)
|
|
|
|
delete *i ;
|
2009-12-07 16:03:53 +01:00
|
|
|
areas.clear() ;
|
|
|
|
|
|
|
|
// Empty Waypoint list
|
2010-01-04 16:37:18 +01:00
|
|
|
for (vector<Waypoint*>::iterator i = waypoints.begin() ;
|
|
|
|
i != waypoints.end() ; i++)
|
2009-12-07 16:03:53 +01:00
|
|
|
{
|
|
|
|
// Delete current waypoint only if it is not linked to another building
|
2010-01-04 16:37:18 +01:00
|
|
|
if ((*i)->get_buildings().size() <= 1)
|
|
|
|
delete *i ;
|
2009-12-07 16:03:53 +01:00
|
|
|
}
|
|
|
|
waypoints.clear() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** Opérateurs ***/
|
|
|
|
|
|
|
|
|
|
|
|
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 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-04 16:37:18 +01:00
|
|
|
ostream& operator<<(ostream &os, const Building &b)
|
2009-12-07 16:03:53 +01:00
|
|
|
{
|
|
|
|
os << b.name ;
|
|
|
|
|
|
|
|
return os ;
|
|
|
|
}
|