[Positioning] Stock::find_create_{ap,mobile}()
Add function find_create_ap() and find_create_mobile() in Stock. Use these functions in InputCSV instead of Stock::get_mobile() and try… catch blocks.
This commit is contained in:
parent
b707dae1f1
commit
c82b95f8f0
|
@ -90,17 +90,8 @@ const Request& InputCSV::get_next_request()
|
||||||
// Read Mobile MAC field
|
// Read Mobile MAC field
|
||||||
if (ti == tok.end()) // Wrong number of fields
|
if (ti == tok.end()) // Wrong number of fields
|
||||||
return *current_request ;
|
return *current_request ;
|
||||||
|
const Mobile &mobile = Stock::find_create_mobile(*ti) ;
|
||||||
// If the mobile did not exist, we create it
|
current_request->set_mobile(&mobile) ;
|
||||||
try
|
|
||||||
{
|
|
||||||
Stock::get_mobile(*ti) ;
|
|
||||||
}
|
|
||||||
catch (element_not_found e)
|
|
||||||
{
|
|
||||||
Stock::getw_mobile(*ti).set_mac_addr(*ti) ;
|
|
||||||
}
|
|
||||||
current_request->set_mobile(&Stock::get_mobile(*ti)) ;
|
|
||||||
|
|
||||||
// Read Timestamp field
|
// Read Timestamp field
|
||||||
if (++ti == tok.end())
|
if (++ti == tok.end())
|
||||||
|
@ -213,19 +204,8 @@ const Request& InputCSV::get_next_request()
|
||||||
current_request->clear() ; // Blank current request
|
current_request->clear() ; // Blank current request
|
||||||
return *current_request ;
|
return *current_request ;
|
||||||
}
|
}
|
||||||
|
const AccessPoint &ap = Stock::find_create_ap(mac_ap) ;
|
||||||
// If the AP did not exist, we create it
|
measurements[mac_ap].set_ap(&ap) ;
|
||||||
try
|
|
||||||
{
|
|
||||||
Stock::get_ap(mac_ap) ;
|
|
||||||
}
|
|
||||||
catch (element_not_found e)
|
|
||||||
{
|
|
||||||
Stock::getw_ap(mac_ap).set_mac_addr(mac_ap) ;
|
|
||||||
}
|
|
||||||
measurements[mac_ap].set_ap(&Stock::get_ap(mac_ap)) ;
|
|
||||||
|
|
||||||
// Adding value
|
|
||||||
measurements[mac_ap].add_ss(ss) ;
|
measurements[mac_ap].add_ss(ss) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,21 @@ const Mobile& Stock::get_mobile(const string &mac)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MAC address of the Mobile is initialised.
|
||||||
|
*/
|
||||||
|
const Mobile& Stock::find_create_mobile(const string &mac)
|
||||||
|
{
|
||||||
|
unordered_map<string, Mobile>::const_iterator i = mobiles.find(mac) ;
|
||||||
|
if (i != mobiles.end())
|
||||||
|
return i->second ;
|
||||||
|
|
||||||
|
Mobile &mobile = mobiles[mac] ;
|
||||||
|
mobile.set_mac_addr(mac) ;
|
||||||
|
return mobile ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mac The MAC address of the AccessPoint to search for.
|
* @param mac The MAC address of the AccessPoint to search for.
|
||||||
* It must be a valid MAC address, as no check is performed.
|
* It must be a valid MAC address, as no check is performed.
|
||||||
|
@ -61,6 +76,21 @@ const AccessPoint& Stock::get_ap(const string &mac)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MAC address of the AccessPoint is initialised.
|
||||||
|
*/
|
||||||
|
const AccessPoint& Stock::find_create_ap(const string &mac)
|
||||||
|
{
|
||||||
|
unordered_map<string, AccessPoint>::const_iterator i = aps.find(mac) ;
|
||||||
|
if (i != aps.end())
|
||||||
|
return i->second ;
|
||||||
|
|
||||||
|
AccessPoint &ap = aps[mac] ;
|
||||||
|
ap.set_mac_addr(mac) ;
|
||||||
|
return ap ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const ReferencePoint& Stock::
|
const ReferencePoint& Stock::
|
||||||
find_create_reference_point(const ReferencePoint &point)
|
find_create_reference_point(const ReferencePoint &point)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,11 +28,15 @@ private:
|
||||||
public:
|
public:
|
||||||
/// Read the Mobile corresponding to a given MAC address
|
/// Read the Mobile corresponding to a given MAC address
|
||||||
static const Mobile& get_mobile(const std::string &mac) ;
|
static const Mobile& get_mobile(const std::string &mac) ;
|
||||||
|
/// Look for a Mobile and create it if it does not exist
|
||||||
|
static const Mobile& find_create_mobile(const std::string &mac) ;
|
||||||
/// Get a reference to the Mobile corresponding to a given MAC address
|
/// Get a reference to the Mobile corresponding to a given MAC address
|
||||||
static Mobile& getw_mobile(const std::string &mac) ;
|
static Mobile& getw_mobile(const std::string &mac) ;
|
||||||
|
|
||||||
/// Read the AccessPoint corresponding to a given MAC address
|
/// Read the AccessPoint corresponding to a given MAC address
|
||||||
static const AccessPoint& get_ap(const std::string &mac) ;
|
static const AccessPoint& get_ap(const std::string &mac) ;
|
||||||
|
/// Look for an AccessPoint and create it if it does not exist
|
||||||
|
static const AccessPoint& find_create_ap(const std::string &mac) ;
|
||||||
/// Get a reference to the AccessPoint corresponding to a given MAC address
|
/// Get a reference to the AccessPoint corresponding to a given MAC address
|
||||||
static AccessPoint& getw_ap(const std::string &mac) ;
|
static AccessPoint& getw_ap(const std::string &mac) ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue