owlps/owlps-positioning/stock.cc

62 lines
1.4 KiB
C++

#include "stock.hh"
#include <stdexcept>
using namespace std ;
using std::tr1::unordered_map ;
/* *** Attribute definitions *** */
unordered_map<string, Mobile> Stock::mobiles ;
unordered_map<string, AccessPoint> Stock::aps ;
/* *** Read 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 std::out_of_range 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 out_of_range("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 std::out_of_range 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 out_of_range("No AccessPoint with MAC address « " + mac + " »!") ;
}
/* *** Write accessors *** */
void Stock::clear()
{
mobiles.clear() ;
aps.clear() ;
}