2012-02-06 16:44:09 +01:00
|
|
|
/*
|
2013-05-29 18:43:35 +02:00
|
|
|
* This file is part of the Owl Positioning System (OwlPS) project.
|
|
|
|
* It is subject to the copyright notice and license terms in the
|
|
|
|
* COPYRIGHT.t2t file found in the top-level directory of this
|
|
|
|
* distribution and at
|
2016-11-03 05:10:34 +01:00
|
|
|
* https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
|
2013-05-29 18:43:35 +02:00
|
|
|
* No part of the OwlPS Project, including this file, may be copied,
|
|
|
|
* modified, propagated, or distributed except according to the terms
|
|
|
|
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
|
|
|
|
* distributed along with this file, either separately or by replacing
|
2013-06-22 23:30:17 +02:00
|
|
|
* this notice by the COPYRIGHT.t2t file's contents.
|
2012-02-06 16:44:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-12-07 16:03:53 +01:00
|
|
|
#include "building.hh"
|
|
|
|
#include "area.hh"
|
2010-01-06 01:18:14 +01:00
|
|
|
#include "waypoint.hh"
|
2010-04-13 10:47:10 +02:00
|
|
|
#include "stock.hh"
|
2013-10-02 23:33:53 +02:00
|
|
|
#include "posexcept.hh"
|
2009-12-07 16:03:53 +01:00
|
|
|
|
|
|
|
|
2010-01-04 17:10:42 +01:00
|
|
|
using namespace std ;
|
|
|
|
|
|
|
|
|
2009-12-07 16:03:53 +01:00
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Constructors *** */
|
2009-12-07 16:03:53 +01:00
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
|
|
|
* Note: deletes (unallocates) all elements in #areas; deletes elements
|
|
|
|
* in #waypoints that belong only to this Building (waypoints that link
|
|
|
|
* several buildings are preserved).
|
2009-12-07 16:03:53 +01:00
|
|
|
*/
|
|
|
|
Building::~Building()
|
|
|
|
{
|
|
|
|
// Empty Area list
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = areas.begin() ; i != areas.end() ; ++i)
|
2010-04-02 10:56:52 +02:00
|
|
|
delete i->second ;
|
2009-12-07 16:03:53 +01:00
|
|
|
areas.clear() ;
|
|
|
|
|
|
|
|
// Empty Waypoint list
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = waypoints.begin() ; i != waypoints.end() ; ++i)
|
2010-04-13 10:47:10 +02:00
|
|
|
Stock::waypoint_remove_building(**i, this) ;
|
2009-12-07 16:03:53 +01:00
|
|
|
waypoints.clear() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 10:56:52 +02:00
|
|
|
/* *** Write accessors *** */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-05-13 23:50:53 +02:00
|
|
|
* If `area` is null, nothing is done.
|
2013-10-02 23:33:53 +02:00
|
|
|
* If `area` is a pointer to an Area that is already stored in #areas,
|
|
|
|
* nothing is done.
|
|
|
|
* If `area` has the same name as (but is not identical to) an Area that
|
|
|
|
* is already stored in #areas, an exception is thrown.
|
|
|
|
*
|
|
|
|
* @param area A pointer to the Area to add.
|
|
|
|
* @throws element_already_exists
|
2010-04-02 10:56:52 +02:00
|
|
|
*/
|
2013-10-02 23:33:53 +02:00
|
|
|
void Building::add_area(const Area *const area)
|
2010-04-02 10:56:52 +02:00
|
|
|
{
|
2014-05-13 23:29:08 +02:00
|
|
|
if (!area)
|
2010-04-02 10:56:52 +02:00
|
|
|
return ;
|
|
|
|
|
|
|
|
string area_name = area->get_name() ;
|
|
|
|
|
|
|
|
// Check if the area already exist in areas
|
2013-10-02 22:22:20 +02:00
|
|
|
auto i = areas.find(area_name) ;
|
2010-04-02 10:56:52 +02:00
|
|
|
if (i != areas.end())
|
|
|
|
{
|
2013-10-02 23:33:53 +02:00
|
|
|
// Just return if area points to the already stored Area
|
|
|
|
if (i->second == area)
|
|
|
|
return ;
|
|
|
|
// Otherwise throw an exception
|
|
|
|
throw element_already_exists(
|
|
|
|
"an Area named \""+ area_name +"\" is already stored") ;
|
2010-04-02 10:56:52 +02:00
|
|
|
}
|
|
|
|
|
2013-10-02 23:33:53 +02:00
|
|
|
// Store the area
|
2013-10-02 23:14:41 +02:00
|
|
|
areas[area_name] = area ;
|
2010-04-02 10:56:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Operators *** */
|
2009-12-07 16:03:53 +01:00
|
|
|
|
|
|
|
|
2011-07-30 20:38:42 +02:00
|
|
|
Building& Building::operator=(const Building &source)
|
2009-12-07 16:03:53 +01:00
|
|
|
{
|
2010-03-05 17:24:18 +01:00
|
|
|
if (this == &source)
|
2009-12-07 16:03:53 +01:00
|
|
|
return *this ;
|
|
|
|
|
2010-03-05 17:24:18 +01:00
|
|
|
name = source.name ;
|
|
|
|
areas = source.areas ;
|
|
|
|
waypoints = source.waypoints ;
|
2009-12-07 16:03:53 +01:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-05 17:24:18 +01:00
|
|
|
bool Building::operator==(const Building &source) const
|
2009-12-07 16:03:53 +01:00
|
|
|
{
|
2010-03-05 17:24:18 +01:00
|
|
|
if (this == &source)
|
2009-12-07 16:03:53 +01:00
|
|
|
return true ;
|
|
|
|
|
|
|
|
return
|
2010-03-05 17:24:18 +01:00
|
|
|
name == source.name &&
|
|
|
|
areas == source.areas &&
|
|
|
|
waypoints == source.waypoints ;
|
2009-12-07 16:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-04 16:37:18 +01:00
|
|
|
ostream& operator<<(ostream &os, const Building &b)
|
2009-12-07 16:03:53 +01:00
|
|
|
{
|
2010-04-02 10:56:52 +02:00
|
|
|
os
|
|
|
|
<< b.name << " ("
|
|
|
|
<< b.areas.size() << " areas, "
|
|
|
|
<< b.waypoints.size() << " waypoints)" ;
|
2009-12-07 16:03:53 +01:00
|
|
|
|
|
|
|
return os ;
|
|
|
|
}
|