2010-03-03 16:06:41 +01:00
|
|
|
#include "result.hh"
|
2010-03-03 17:57:32 +01:00
|
|
|
#include "request.hh"
|
2011-07-29 00:05:52 +02:00
|
|
|
#include "area.hh"
|
|
|
|
#include "stock.hh"
|
2010-03-03 16:06:41 +01:00
|
|
|
|
2011-04-05 14:45:27 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
using namespace std ;
|
|
|
|
|
2010-03-03 16:06:41 +01:00
|
|
|
|
|
|
|
|
2011-05-03 15:16:03 +02:00
|
|
|
/* *** Constructors *** */
|
|
|
|
|
|
|
|
|
2011-07-24 12:32:07 +02:00
|
|
|
Result::Result(const Request *_request,
|
|
|
|
const std::string &_algorithm,
|
|
|
|
const Point3D &_position,
|
2011-05-03 15:16:03 +02:00
|
|
|
const Point3D &real_position):
|
2011-07-24 12:32:07 +02:00
|
|
|
request(_request), algorithm(_algorithm), position(_position)
|
2011-05-03 15:16:03 +02:00
|
|
|
{
|
|
|
|
compute_error(real_position) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-29 00:05:52 +02:00
|
|
|
/* *** Read accessors *** */
|
|
|
|
|
|
|
|
|
|
|
|
string Result::in_which_area() const
|
|
|
|
{
|
|
|
|
const Area *area = Stock::in_which_area_is(position) ;
|
|
|
|
if (area == NULL)
|
|
|
|
return "" ;
|
|
|
|
|
|
|
|
return area->get_name() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-03 15:16:03 +02:00
|
|
|
/* *** Write accessors *** */
|
|
|
|
|
|
|
|
|
|
|
|
void Result::compute_error(const Point3D &real_position)
|
|
|
|
{
|
|
|
|
error = position.distance(real_position) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-03 16:06:41 +01:00
|
|
|
/* *** Operators *** */
|
|
|
|
|
|
|
|
|
|
|
|
const Result& Result::operator=(const Result &source)
|
|
|
|
{
|
|
|
|
if (this == &source)
|
|
|
|
return *this ;
|
|
|
|
|
2011-07-24 12:32:07 +02:00
|
|
|
request = source.request ;
|
2011-03-31 19:42:35 +02:00
|
|
|
algorithm = source.algorithm ;
|
2010-03-03 16:06:41 +01:00
|
|
|
position = source.position ;
|
2011-05-11 09:44:49 +02:00
|
|
|
error = source.error ;
|
2010-03-03 16:06:41 +01:00
|
|
|
|
|
|
|
return *this ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-08 14:37:49 +02:00
|
|
|
bool Result::operator==(const Result &source) const
|
2010-03-03 16:06:41 +01:00
|
|
|
{
|
|
|
|
return
|
2011-07-24 12:32:07 +02:00
|
|
|
request == source.request &&
|
2011-03-31 19:42:35 +02:00
|
|
|
algorithm == source.algorithm &&
|
2011-05-11 09:44:49 +02:00
|
|
|
position == source.position &&
|
|
|
|
error == source.error ;
|
2010-03-03 16:06:41 +01:00
|
|
|
}
|
2010-03-03 17:57:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-04-06 14:10:51 +02:00
|
|
|
/**
|
2011-06-14 16:44:17 +02:00
|
|
|
* @return The result as a CSV string, \em without trailing '\n'.
|
2011-04-06 14:10:51 +02:00
|
|
|
*/
|
2011-04-05 14:45:27 +02:00
|
|
|
const string Result::to_csv() const
|
|
|
|
{
|
|
|
|
ostringstream csv_line ;
|
|
|
|
|
|
|
|
csv_line
|
|
|
|
<< algorithm
|
|
|
|
<< ';' << position.get_x()
|
|
|
|
<< ';' << position.get_y()
|
2011-05-03 15:16:03 +02:00
|
|
|
<< ';' << position.get_z()
|
|
|
|
<< ';' << "Error"
|
2011-07-30 19:35:47 +02:00
|
|
|
<< ';' << error
|
|
|
|
<< ';' ;
|
|
|
|
|
|
|
|
const Area *const area = Stock::in_which_area_is(position) ;
|
|
|
|
if (area != NULL)
|
|
|
|
csv_line << area->get_name() ;
|
2011-04-05 14:45:27 +02:00
|
|
|
|
|
|
|
return csv_line.str() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(ostream &os, const Result &r)
|
2010-03-03 17:57:32 +01:00
|
|
|
{
|
2011-03-31 19:42:35 +02:00
|
|
|
os
|
2011-04-05 11:52:06 +02:00
|
|
|
<< "The result of the algorithm " << r.algorithm
|
2011-07-29 00:06:40 +02:00
|
|
|
<< " is: " << r.position
|
|
|
|
<< " (area: « " << r.in_which_area() << " »)" ;
|
2011-05-03 15:16:03 +02:00
|
|
|
if (r.error >= 0)
|
|
|
|
os << ", error = " << r.error << " m" ;
|
2010-03-03 17:57:32 +01:00
|
|
|
return os ;
|
|
|
|
}
|