93 lines
1.5 KiB
C++
93 lines
1.5 KiB
C++
#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 #timestamp are initialised to 0.
|
|
* - #measurements is cleared.
|
|
*/
|
|
void Request::clear()
|
|
{
|
|
mobile = NULL ;
|
|
timestamp.clear() ;
|
|
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.empty())
|
|
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 ;
|
|
}
|