#include "request.hh" #include "mobile.hh" using namespace std ; using std::tr1::unordered_map ; /* *** Constructors *** */ /** * Note that the value pointed by #mobile is not deleted. */ Request::~Request() { measurements.clear() ; } /* *** Write accessors *** */ /// Reinitialises all attributes /** * - #mobile is NULLified, but the value it pointed to is not deleted. * - The fields of #time_sent are initialised to 0. * - #measurements is cleared. */ void Request::clear() { type = OWL_REQUEST_UNDEFINED ; mobile = NULL ; time_sent.clear() ; measurements.clear() ; } /* *** Operators *** */ const Request& Request::operator=(const Request &source) { if (this == &source) return *this ; type = source.type ; mobile = source.mobile ; time_sent = source.time_sent ; measurements = source.measurements ; return *this ; } bool Request::operator==(const Request &source) const { if (this == &source) return true ; return type == source.type && mobile == source.mobile && time_sent == source.time_sent && measurements == source.measurements ; } ostream& operator<<(ostream &os, const Request &r) { // Timestamp os << "At " << r.time_sent << "; " ; // MAC address os << "Type: " << static_cast(r.type) << ", Mobile: " << (r.mobile != NULL ? r.mobile->get_mac_addr() : "Unknown_Mobile") << ":" ; // List of Measurements if (r.measurements.empty()) 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 ; } /** * The Mobile MAC address and the Timestamp are sufficient to identify * uniquely a Request. */ size_t hash_value(const Request &source) { size_t seed = 0 ; boost::hash_combine(seed, source.type) ; boost::hash_combine(seed, source.time_sent) ; if (source.mobile != NULL) boost::hash_combine(seed, source.mobile->get_mac_addr()) ; return seed ; }