owlps/owlps-positioning/request.cc

126 lines
2.2 KiB
C++
Raw Normal View History

#include "request.hh"
#include "mobile.hh"
using namespace std ;
using std::tr1::unordered_map ;
/* *** Constructors *** */
Request::Request(const unordered_map<string, Measurement> &_measurements)
{
mobile = NULL ;
measurements = _measurements ;
}
Request::Request(const Timestamp &_timestamp,
const unordered_map<string, Measurement> &_measurements)
{
mobile = NULL ;
timestamp = _timestamp ;
measurements = _measurements ;
}
Request::Request(const Mobile *_mobile, const Timestamp &_timestamp,
const unordered_map<string, Measurement> &_measurements)
{
mobile = const_cast<Mobile*>(_mobile) ;
timestamp = _timestamp ;
measurements = _measurements ;
}
Request::Request(const Request &source)
{
mobile = source.mobile ;
timestamp = source.timestamp ;
measurements = source.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.set_timestamp_ms(0) ;
measurements.clear() ;
}
/* *** Operators *** */
const Request& Request::operator=(const Request &source)
{
if (this == &source)
return *this ;
mobile = source.mobile ;
timestamp = source.timestamp ;
measurements = source.measurements ;
return *this ;
}
bool Request::operator==(const Request &comp) const
{
if (this == &comp)
return true ;
return
mobile == comp.mobile &&
timestamp == comp.timestamp &&
measurements == comp.measurements ;
}
ostream &operator<<(ostream &os, const Request &r)
{
// Timestamp
os
<< "At " << 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<string, Measurement>::const_iterator i
= r.measurements.begin() ; i != r.measurements.end() ; ++i)
{
os << '\n' << i->first << ": " << i->second ;
}
return os ;
}