#include "request.hh" #include "mobile.hh" using namespace std ; using std::tr1::unordered_map ; /* *** Constructors *** */ Request::Request(const unordered_map &_measurements) { mobile = NULL ; timestamp.tv_sec = 0 ; timestamp.tv_nsec = 0 ; measurements = _measurements ; } Request::Request(const struct timespec &_timestamp, const unordered_map &_measurements) { mobile = NULL ; timestamp = _timestamp ; measurements = _measurements ; } Request::Request(const Mobile *_mobile, const struct timespec &_timestamp, const unordered_map &_measurements) { mobile = (Mobile*) _mobile ; timestamp = _timestamp ; measurements = _measurements ; } /** * Note that the value pointed by #mobile is not deleted. */ Request::~Request() { measurements.clear() ; } /* *** Write accessors *** */ /** * - #mobile is NULLified, but the value it pointed to is not deleted. * - The fields of #timestamp are initialised to 0. * - #measurements is cleared. */ void Request::clear() { mobile = NULL ; timestamp.tv_sec = 0 ; timestamp.tv_nsec = 0 ; measurements.clear() ; } /* *** Operators *** */ ostream &operator<<(ostream &os, const Request &r) { // Timestamp os << "At " << PosUtil::timespec_to_ns(r.timestamp) << "; " ; // MAC address os << "Mobile: " << (r.mobile != NULL ? r.mobile->get_mac_addr() : "Unknown_Mobile") << ":" ; // List of Measurements if (r.measurements.size() == 0) os << " No values" ; else for (unordered_map::const_iterator i = r.measurements.begin() ; i != r.measurements.end() ; ++i) { os << '\n' << i->first << ": " << i->second ; } return os ; }