2010-01-12 00:31:22 +01:00
|
|
|
#include "stock.hh"
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
#include <stdexcept>
|
|
|
|
|
2010-01-12 00:31:22 +01:00
|
|
|
using namespace std ;
|
|
|
|
using std::tr1::unordered_map ;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Attribute definition *** */
|
|
|
|
|
2010-01-12 00:31:22 +01:00
|
|
|
unordered_map<string, Mobile> Stock::mobiles =
|
|
|
|
unordered_map<string, Mobile>() ;
|
|
|
|
|
|
|
|
unordered_map<string, AccessPoint> Stock::aps =
|
|
|
|
unordered_map<string, AccessPoint>() ;
|
2010-01-16 12:23:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** 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>::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>::iterator i = aps.find(mac) ;
|
|
|
|
if (i != aps.end())
|
|
|
|
return i->second ;
|
|
|
|
throw out_of_range("No AccessPoint with MAC address « " + mac + " »!") ;
|
|
|
|
}
|