#include "result.hh" #include "request.hh" #include "area.hh" #include "stock.hh" #include using namespace std ; /* *** Constructors *** */ Result::Result(const Request *_request, const std::string &_algorithm, const Point3D &_position, const Point3D &real_position): request(_request), algorithm(_algorithm), position(_position) { compute_error(real_position) ; } /* *** 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() ; } /* *** Write accessors *** */ void Result::compute_error(const Point3D &real_position) { error = position.distance(real_position) ; } /* *** Operators *** */ const Result& Result::operator=(const Result &source) { if (this == &source) return *this ; request = source.request ; algorithm = source.algorithm ; position = source.position ; error = source.error ; return *this ; } bool Result::operator==(const Result &source) const { return request == source.request && algorithm == source.algorithm && position == source.position && error == source.error ; } /** * @return The result as a CSV string, \em without trailing '\n'. */ const string Result::to_csv() const { ostringstream csv_line ; csv_line << algorithm << ';' << position.get_x() << ';' << position.get_y() << ';' << position.get_z() << ';' << "Error" << ';' << error ; return csv_line.str() ; } std::ostream& operator<<(ostream &os, const Result &r) { os << "The result of the algorithm " << r.algorithm << " is: " << r.position ; if (r.error >= 0) os << ", error = " << r.error << " m" ; return os ; }