diff --git a/owlps-positioning/src/stock.cc b/owlps-positioning/src/stock.cc index dee9a44..51a15bf 100644 --- a/owlps-positioning/src/stock.cc +++ b/owlps-positioning/src/stock.cc @@ -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::const_iterator i = mobiles.find(mac) ; + if (i != mobiles.end()) + return i->second ; + + mobiles[mac] = source ; + return mobiles[mac] ; +} + + /* *** AccessPoint operations *** */ diff --git a/owlps-positioning/src/stock.hh b/owlps-positioning/src/stock.hh index ab4cbab..db58fd3 100644 --- a/owlps-positioning/src/stock.hh +++ b/owlps-positioning/src/stock.hh @@ -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) ;