[Positioning] ReferencePoint::delete_generated_requests()

This commit is contained in:
Matteo Cypriani 2011-07-21 21:39:54 +02:00
parent 6c48bc7e29
commit 232551c150
2 changed files with 45 additions and 3 deletions

View File

@ -117,9 +117,9 @@ void ReferencePoint::delete_requests()
int stock_nb_requests = Stock::nb_calibration_requests() ;
#endif // NDEBUG
for (vector<CalibrationRequest*>::iterator i = requests.begin() ;
i != requests.end() ; ++i)
Stock::delete_calibration_request(**i) ;
for (vector<CalibrationRequest*>::iterator r = requests.begin() ;
r != requests.end() ; ++r)
Stock::delete_calibration_request(**r) ;
assert(Stock::nb_calibration_requests() ==
stock_nb_requests - requests.size()) ;
@ -128,6 +128,46 @@ void ReferencePoint::delete_requests()
}
/**
* Note that the requests pointed by the elements of #requests are
* actually deleted from the Stock.
* @returns \em true if at least one request was deleted.
* @returns \em false if the ReferencePoint was left untouched.
*/
bool ReferencePoint::delete_generated_requests(void)
{
bool modified = false ;
for (vector<CalibrationRequest*>::iterator r = requests.begin() ;
r != requests.end() ; ++r)
{
assert(*r) ;
if ((*r)->get_mobile() == NULL)
{
requests.erase(r) ;
modified = true ;
continue ;
}
unordered_map<std::string, AccessPoint>::const_iterator ap ;
for (ap = Stock::get_aps().begin() ; ap != Stock::get_aps().end() ;
++ap)
if ((*r)->get_mobile()->get_mac_addr() ==
ap->second.get_mac_addr())
break ;
if (ap == Stock::get_aps().end()) // r is not associated with an AP
{
Stock::delete_calibration_request(**r) ;
requests.erase(r) ;
modified = true ;
}
}
return modified ;
}
/* *** Operations *** */

View File

@ -57,6 +57,8 @@ public:
void add_request(const CalibrationRequest *cm) ;
/// Deletes all the requests contained in #requests
void delete_requests(void) ;
/// Deletes the requests that are not sent by an AP
bool delete_generated_requests(void) ;
//@}
/** @name Operations */