[Positioning] Stock::delete_non_ap_calibration_requests()

Create the function Stock::delete_non_ap_calibration_requests() from
regenerate_reference_points().
This commit is contained in:
Matteo Cypriani 2011-07-30 20:21:51 +02:00
parent c0a179e34e
commit 4c9a3070ac
2 changed files with 36 additions and 25 deletions

View File

@ -441,31 +441,7 @@ void Stock::regenerate_reference_points()
assert(! aps.empty()) ;
assert(! reference_points.empty()) ;
/* Delete calibration requests that do not come from the APs */
unordered_set<ReferencePoint>::iterator rp = reference_points.begin() ;
while (rp != reference_points.end())
{
ReferencePoint rp_copy(*rp) ;
if (rp_copy.delete_generated_requests()) // rp_copy was modified
{
rp = reference_points.erase(rp) ;
// Reinsert the modified copy if it still contains at least
// one CalibrationRequest:
if (! rp_copy.get_requests().empty())
reference_points.insert(rp_copy) ;
/* __Note on the above insert__
* From the boost::unordered documentation:
* "insert is only allowed to invalidate iterators when the
* insertion causes the load factor to be greater than or
* equal to the maximum load factor."
* In our case, we always remove an element prior to insert,
* so the load factor will never change; therefore insert()
* should be safe here.
*/
}
else // rp_copy was not modified
++rp ;
}
delete_non_ap_calibration_requests() ;
if (reference_points.size() < 3)
{
@ -729,3 +705,32 @@ closest_calibration_request(const Request &request)
return *closest ;
}
void Stock::delete_non_ap_calibration_requests()
{
unordered_set<ReferencePoint>::iterator rp = reference_points.begin() ;
while (rp != reference_points.end())
{
ReferencePoint rp_copy(*rp) ;
if (rp_copy.delete_generated_requests()) // rp_copy was modified
{
rp = reference_points.erase(rp) ;
// Reinsert the modified copy if it still contains at least
// one CalibrationRequest:
if (! rp_copy.get_requests().empty())
reference_points.insert(rp_copy) ;
/* __Note on the above insert__
* From the boost::unordered documentation:
* "insert is only allowed to invalidate iterators when the
* insertion causes the load factor to be greater than or
* equal to the maximum load factor."
* In our case, we always remove an element prior to insert,
* so the load factor will never change; therefore insert()
* should be safe here.
*/
}
else // rp_copy was not modified
++rp ;
}
}

View File

@ -41,6 +41,12 @@ private:
/// List of known CalibrationRequest
static std::tr1::unordered_set<CalibrationRequest> calibration_requests ;
/** @name CalibrationRequest operations */
//@{
/// Delete calibration requests that do not come from the APs
static void delete_non_ap_calibration_requests(void) ;
//@}
public:
/** @name Building operations */
//@{