136 lines
2.0 KiB
C++
136 lines
2.0 KiB
C++
|
#include "building.hh"
|
||
|
#include "waypoint.hh"
|
||
|
#include "area.hh"
|
||
|
|
||
|
|
||
|
|
||
|
/*** 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()
|
||
|
{
|
||
|
cout << "Building "<< name <<" area size : " << areas.size() << endl;
|
||
|
// Empty Area list
|
||
|
for (unsigned int i = 0 ; i < areas.size() ; i++)
|
||
|
delete areas[i] ;
|
||
|
areas.clear() ;
|
||
|
|
||
|
// Empty Waypoint list
|
||
|
for (unsigned int i = 0 ; i < waypoints.size() ; i++)
|
||
|
{
|
||
|
// Delete current waypoint only if it is not linked to another building
|
||
|
if (waypoints[i]->get_buildings().size() <= 1)
|
||
|
delete waypoints[i] ;
|
||
|
}
|
||
|
waypoints.clear() ;
|
||
|
}
|
||
|
|
||
|
|
||
|
/*** Accesseurs lecture ***/
|
||
|
|
||
|
|
||
|
string Building::get_name() const
|
||
|
{
|
||
|
return name ;
|
||
|
}
|
||
|
|
||
|
|
||
|
vector<Area*> Building::get_areas() const
|
||
|
{
|
||
|
return areas ;
|
||
|
}
|
||
|
|
||
|
|
||
|
vector<Waypoint*> Building::get_waypoints() const
|
||
|
{
|
||
|
return waypoints ;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/*** Accesseurs écriture ***/
|
||
|
|
||
|
|
||
|
void Building::set_name(const string &_name)
|
||
|
{
|
||
|
name = _name ;
|
||
|
}
|
||
|
|
||
|
|
||
|
void Building::add_area(const Area *a)
|
||
|
{
|
||
|
areas.push_back((Area *) a) ;
|
||
|
}
|
||
|
|
||
|
|
||
|
void Building::add_waypoint(const Waypoint *wp)
|
||
|
{
|
||
|
waypoints.push_back((Waypoint *) wp) ;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/*** 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 ;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool Building::operator!=(const Building &b) const
|
||
|
{
|
||
|
return !(*this == b) ;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
ostream& operator<<(ostream &os, Building &b)
|
||
|
{
|
||
|
os << b.name ;
|
||
|
|
||
|
return os ;
|
||
|
}
|