[Positioning] Add Stock::find_create_mobile(Mobile&)

This commit is contained in:
Matteo Cypriani 2011-07-19 18:20:20 +02:00
parent d9bfd9e2c2
commit b04cd1cdb8
2 changed files with 19 additions and 1 deletions

View File

@ -148,6 +148,21 @@ const Mobile& Stock::find_create_mobile(const string &mac)
}
/**
* If the Mobile already exists, it is replaced by the \em source.
*/
const Mobile& Stock::find_create_mobile(const Mobile &source)
{
const string &mac = source.get_mac_addr() ;
unordered_map<string, Mobile>::const_iterator i = mobiles.find(mac) ;
if (i != mobiles.end())
return i->second ;
mobiles[mac] = source ;
return mobiles[mac] ;
}
/* *** AccessPoint operations *** */

View File

@ -70,8 +70,11 @@ public:
//@{
/// Reads the Mobile corresponding to a given MAC address
static const Mobile& get_mobile(const std::string &mac) ;
/// Searches for a Mobile and creates it if it does not exist
/// \brief Searches for a Mobile given its MAC address and creates
/// it if it does not exist
static const Mobile& find_create_mobile(const std::string &mac) ;
/// Searches for a Mobile and create it if it does not exist
static const Mobile& find_create_mobile(const Mobile &source) ;
/// \brief Returns a reference to the Mobile corresponding to a
/// given MAC address
static Mobile& getw_mobile(const std::string &mac) ;