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 "waypoint.hh"
|
2010-04-13 10:47:10 +02:00
|
|
|
#include "building.hh"
|
2009-12-07 16:03:53 +01:00
|
|
|
|
2010-04-13 10:47:10 +02:00
|
|
|
#include <sstream>
|
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
|
|
|
/**
|
|
|
|
* @param _b A pointer to the (first) Building to add to #buildings.
|
2014-05-13 23:50:53 +02:00
|
|
|
* If it is null, #buildings will remain empty.
|
2010-03-05 17:24:18 +01:00
|
|
|
* @param _x X coordinate.
|
|
|
|
* @param _y Y coordinate.
|
|
|
|
* @param _z Z coordinate.
|
2010-01-16 12:23:07 +01:00
|
|
|
*/
|
2013-10-02 20:38:45 +02:00
|
|
|
Waypoint::Waypoint(Building *const _b,
|
2013-10-02 20:50:39 +02:00
|
|
|
const float _x, const float _y, const float _z):
|
|
|
|
Point3D(_x, _y, _z)
|
2009-12-07 16:03:53 +01:00
|
|
|
{
|
2014-05-13 23:29:08 +02:00
|
|
|
if (_b)
|
2013-10-02 20:38:45 +02:00
|
|
|
buildings.insert(_b) ;
|
2009-12-07 16:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
|
|
|
* @param _b A pointer to the (first) Building to add to #buildings.
|
2014-05-13 23:50:53 +02:00
|
|
|
* If it is null, #buildings will remain empty.
|
2010-03-05 17:24:18 +01:00
|
|
|
* @param p Coordinates of the Waypoint.
|
2010-01-16 12:23:07 +01:00
|
|
|
*/
|
2013-10-02 20:38:45 +02:00
|
|
|
Waypoint::Waypoint(Building *const _b, const Point3D &p): Point3D(p)
|
2009-12-07 16:03:53 +01:00
|
|
|
{
|
2014-05-13 23:29:08 +02:00
|
|
|
if (_b)
|
2013-10-02 20:38:45 +02:00
|
|
|
buildings.insert(_b) ;
|
2009-12-07 16:03:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
|
|
|
* Clears #buildings, but does not deallocate the values pointed by
|
|
|
|
* the elements into it.
|
|
|
|
*/
|
2009-12-07 16:03:53 +01:00
|
|
|
Waypoint::~Waypoint()
|
|
|
|
{
|
|
|
|
buildings.clear() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
Waypoint& Waypoint::operator=(const Waypoint &wp)
|
2009-12-07 16:03:53 +01:00
|
|
|
{
|
|
|
|
if (this == &wp)
|
|
|
|
return *this ;
|
|
|
|
|
|
|
|
this->Point3D::operator=(wp) ;
|
|
|
|
buildings = wp.buildings ;
|
|
|
|
|
|
|
|
return *this ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Waypoint::operator==(const Waypoint &wp) const
|
|
|
|
{
|
|
|
|
if (this == &wp)
|
|
|
|
return true ;
|
|
|
|
|
|
|
|
return
|
|
|
|
this->Point3D::operator==(wp) &&
|
|
|
|
buildings == wp.buildings ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-06 14:10:51 +02:00
|
|
|
Waypoint::operator std::string() const
|
2010-04-13 10:47:10 +02:00
|
|
|
{
|
|
|
|
ostringstream csv ;
|
2014-05-13 23:12:52 +02:00
|
|
|
csv << static_cast<Point3D>(*this) ;
|
2010-04-13 10:47:10 +02:00
|
|
|
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = buildings.begin() ; i != buildings.end() ; ++i)
|
2010-04-13 10:47:10 +02:00
|
|
|
csv << ';' << (*i)->get_name() ;
|
|
|
|
|
|
|
|
return csv.str() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-07 16:03:53 +01:00
|
|
|
|
2010-01-04 16:37:18 +01:00
|
|
|
ostream &operator<<(ostream &os, const Waypoint &wp)
|
2009-12-07 16:03:53 +01:00
|
|
|
{
|
2010-01-04 16:37:18 +01:00
|
|
|
// Coordinates
|
2014-05-13 23:12:52 +02:00
|
|
|
os << static_cast<Point3D>(wp) ;
|
2010-01-04 16:37:18 +01:00
|
|
|
|
|
|
|
// List of buildings
|
2010-02-26 13:09:45 +01:00
|
|
|
if (wp.buildings.empty())
|
2010-01-13 15:29:44 +01:00
|
|
|
os << '\n' << "Belongs to no building!" ;
|
2009-12-07 16:03:53 +01:00
|
|
|
else
|
2013-10-02 22:22:20 +02:00
|
|
|
for (auto i = wp.buildings.begin() ; i != wp.buildings.end() ; ++i)
|
2010-04-13 10:47:10 +02:00
|
|
|
os << '\n' << **i ;
|
2009-12-07 16:03:53 +01:00
|
|
|
|
|
|
|
return os ;
|
|
|
|
}
|