#include "stock.hh" #include using namespace std ; using std::tr1::unordered_map ; /* *** Attribute definitions *** */ unordered_map Stock::mobiles ; unordered_map 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::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::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() ; }