owlps/owlps-positioning/src/request.hh

144 lines
3.3 KiB
C++
Raw Normal View History

#ifndef _OWLPS_POSITIONING_REQUEST_HH_
#define _OWLPS_POSITIONING_REQUEST_HH_
class Mobile ;
#include "measurement.hh"
#include "timestamp.hh"
#include <ctime>
#include <boost/tr1/unordered_map.hpp>
#include <ostream>
/// Represents a request sent by a Mobile
class Request
{
protected:
/// The mobile that sent the request
Mobile *mobile ;
/// Local date of the request on the mobile
Timestamp timestamp ;
/// List of Measurement of the request
/** Note that this is not a pointer list, values are actually stored.
The \em string parameter is the MAC address of the AP. */
std::tr1::unordered_map<std::string, Measurement> measurements ;
public:
Request(const std::tr1::unordered_map<std::string, Measurement>
&_measurements =
std::tr1::unordered_map<std::string, Measurement>()) ;
Request(const Timestamp &_timestamp,
const std::tr1::unordered_map<std::string, Measurement>
&_measurements =
std::tr1::unordered_map<std::string, Measurement>()) ;
Request(const Mobile *_mobile, const Timestamp &_timestamp,
const std::tr1::unordered_map<std::string, Measurement>
&_measurements =
std::tr1::unordered_map<std::string, Measurement>()) ;
Request(const Request &source) ;
virtual ~Request(void) ;
/** @name Read accessors */
//@{
Mobile* get_mobile(void) const ;
const Timestamp& get_timestamp(void) const ;
const std::tr1::unordered_map<std::string, Measurement>&
get_measurements(void) const ;
//@}
/** @name Write accessors */
//@{
void set_mobile(const Mobile *_mobile) ;
void set_timestamp(const Timestamp &_timestamp) ;
void set_measurements(const std::tr1::unordered_map
<std::string, Measurement> &_measurements) ;
/// Reinitialises all attributes
void clear(void) ;
//@}
/** @name Operators */
//@{
const Request& operator=(const Request &source) ;
bool operator==(const Request &comp) const ;
bool operator!=(const Request &comp) const ;
operator bool(void) const ; ///< Cast to bool operator
//@}
/// Displays a Request
friend std::ostream& operator<<(std::ostream &os, const Request &r) ;
} ;
/* *** Read accessors *** */
inline Mobile* Request::get_mobile() const
{
return mobile ;
}
inline const Timestamp& Request::get_timestamp() const
{
return timestamp ;
}
inline const std::tr1::unordered_map<std::string, Measurement>&
Request::get_measurements(void) const
{
return measurements ;
}
/* *** Write accessors *** */
inline void Request::set_mobile(const Mobile *_mobile)
{
mobile = const_cast<Mobile*>(_mobile) ;
}
inline void Request::set_timestamp(const Timestamp &_timestamp)
{
timestamp = _timestamp ;
}
inline void Request::set_measurements(const std::tr1::unordered_map
<std::string, Measurement> &_measurements)
{
measurements = _measurements ;
}
/* *** Operators *** */
inline bool Request::operator!=(const Request &comp) const
{
return !(*this == comp) ;
}
/**
* @return \em false if the Request is empty.
* @return \em true if at least one attribute is initialised.
*/
inline Request::operator bool() const
{
return
mobile != NULL ||
timestamp ||
measurements.size() > 0 ;
}
#endif // _OWLPS_POSITIONING_REQUEST_HH_