91 lines
2.3 KiB
C++
91 lines
2.3 KiB
C++
#include "stock.hh"
|
|
#include "posexcept.hh"
|
|
|
|
using namespace std ;
|
|
using std::tr1::unordered_map ;
|
|
using std::tr1::unordered_set ;
|
|
|
|
|
|
/// Hash function, required to put ReferencePoint in a set
|
|
size_t hash_value(const ReferencePoint &object)
|
|
{
|
|
return boost::hash_value(static_cast<string>(object)) ;
|
|
}
|
|
|
|
|
|
/* *** Attribute definitions *** */
|
|
|
|
unordered_map<string, Mobile> Stock::mobiles ;
|
|
|
|
unordered_map<string, AccessPoint> Stock::aps ;
|
|
|
|
unordered_set<ReferencePoint> Stock::reference_points ;
|
|
|
|
unordered_set<CalibrationRequest> Stock::calibration_requests ;
|
|
|
|
|
|
|
|
/* *** Accessors *** */
|
|
|
|
|
|
/**
|
|
* @param mac The MAC address of the Mobile to search for.
|
|
* It must be a valid MAC address, as no check is performed.
|
|
* @return A const reference to the Mobile.
|
|
* @throw element_not_found is thrown if the Mobile corresponding
|
|
* to \em mac does not exist.
|
|
*/
|
|
const Mobile& Stock::get_mobile(const string &mac)
|
|
{
|
|
unordered_map<string, Mobile>::const_iterator i = mobiles.find(mac) ;
|
|
if (i != mobiles.end())
|
|
return i->second ;
|
|
throw element_not_found("No Mobile with MAC address « " + mac + " »!") ;
|
|
}
|
|
|
|
|
|
/**
|
|
* @param mac The MAC address of the AccessPoint to search for.
|
|
* It must be a valid MAC address, as no check is performed.
|
|
* @return A const reference to the AccessPoint.
|
|
* @throw element_not_found is thrown if the AccessPoint corresponding
|
|
* to \em mac does not exist.
|
|
*/
|
|
const AccessPoint& Stock::get_ap(const string &mac)
|
|
{
|
|
unordered_map<string, AccessPoint>::const_iterator i = aps.find(mac) ;
|
|
if (i != aps.end())
|
|
return i->second ;
|
|
throw element_not_found("No AccessPoint with MAC address « " +
|
|
mac + " »!") ;
|
|
}
|
|
|
|
|
|
const ReferencePoint& Stock::
|
|
find_create_reference_point(const ReferencePoint &point)
|
|
{
|
|
// unordered_set::insert() do all the job: see the documentation at
|
|
// http://www.boost.org/doc/libs/1_41_0/doc/html/boost/unordered_set.html
|
|
pair<unordered_set<ReferencePoint>::iterator, bool> ret =
|
|
reference_points.insert(point) ;
|
|
return *ret.first ;
|
|
}
|
|
|
|
|
|
const CalibrationRequest& Stock::
|
|
find_create_calibration_request(const CalibrationRequest &request)
|
|
{
|
|
pair<unordered_set<CalibrationRequest>::iterator, bool> ret =
|
|
calibration_requests.insert(request) ;
|
|
return *ret.first ;
|
|
}
|
|
|
|
|
|
void Stock::clear()
|
|
{
|
|
mobiles.clear() ;
|
|
aps.clear() ;
|
|
reference_points.clear() ;
|
|
calibration_requests.clear() ;
|
|
}
|