owlps/owlps-positioning/request.hh

129 lines
3.1 KiB
C++
Raw Normal View History

#ifndef _OWLPS_POSITIONING_REQUEST_HH_
#define _OWLPS_POSITIONING_REQUEST_HH_
class Mobile ;
#include "measurement.hh"
#include <ctime>
#include <unordered_map>
#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
struct timespec timestamp ;
/// List of Measurement of the request
/** Note that this is not a pointer list, values are actually stored. */
std::tr1::unordered_map<std::string, Measurement> measurements ;
public:
/// Constructs a Request from a list of Measurement (or default constructor)
Request(const std::tr1::unordered_map<std::string, Measurement> &_measurements
= std::tr1::unordered_map<std::string, Measurement>()) ;
/// Constructs a Request from a timestamp and (possibly) a Measurement list
Request(const struct timespec &_timestamp,
const std::tr1::unordered_map<std::string, Measurement> &_measurements
= std::tr1::unordered_map<std::string, Measurement>()) ;
/// \brief Constructs a request from a mobile and a timestamp and (possibly)
/// a Measurement list
Request(const Mobile *_mobile, const struct timespec &_timestamp,
const std::tr1::unordered_map<std::string, Measurement> &_measurements
= std::tr1::unordered_map<std::string, Measurement>()) ;
~Request(void) ; ///< Destructor
/** @name Read accessors */
//@{
/// #mobile read accessor
Mobile* get_mobile(void) const ;
/// #timestamp read accessor
const struct timespec& get_timestamp(void) const ;
//@}
/** @name Write accessors */
//@{
/// #mobile write accessor
void set_mobile(const Mobile *_mobile) ;
/// #timestamp write accessor
void set_timestamp(const struct timespec &_timestamp) ;
/// #measurements write accessor
void set_measurements(const std::tr1::unordered_map
<std::string, Measurement> &_measurements) ;
/// Reinitialises all attributes
void clear(void) ;
//@}
/** @name Operators */
//@{
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 struct timespec& Request::get_timestamp() const
{
return timestamp ;
}
/* *** Write accessors *** */
inline void Request::set_mobile(const Mobile *_mobile)
{
mobile = const_cast<Mobile*>(_mobile) ;
}
inline void Request::set_timestamp(const struct timespec &_timestamp)
{
timestamp = _timestamp ;
}
inline void Request::set_measurements(const std::tr1::unordered_map
<std::string, Measurement> &_measurements)
{
measurements = _measurements ;
}
/* *** Operators *** */
/**
* @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.tv_sec != 0 ||
measurements.size() > 0 ;
}
#endif // _OWLPS_POSITIONING_REQUEST_HH_