[Positioning] Add Stock::in_which_area_is()

This commit is contained in:
Matteo Cypriani 2011-07-24 13:22:46 +02:00
parent 9f5305b496
commit a951717433
2 changed files with 23 additions and 0 deletions

View File

@ -1,6 +1,7 @@
#include "stock.hh"
#include "configuration.hh"
#include "posexcept.hh"
#include "area.hh"
using namespace std ;
using std::tr1::unordered_map ;
@ -80,6 +81,26 @@ const Building& Stock::get_building(const string &name)
}
/**
* @returns A pointer to the first Area in which \em point was found.
* @returns NULL if \em point does not belong to any Area.
*/
const Area* Stock::in_which_area_is(const Point3D point)
{
for (unordered_map<string, Building>::const_iterator
b = buildings.begin() ; b != buildings.end() ; ++b)
{
const unordered_map<string, Area*> &areas = b->second.get_areas() ;
for (unordered_map<string, Area*>::const_iterator
a = areas.begin() ; a != areas.end() ; ++a)
if (a->second->contains_point(point))
return a->second ;
}
return NULL ;
}
/* *** Waypoint operations *** */

View File

@ -50,6 +50,8 @@ public:
static const Building& get_building(const std::string &name) ;
/// Searches for a Building and creates it if it does not exist
static const Building& find_create_building(const std::string &name) ;
/// Searches the Area in which \em point is
static const Area* in_which_area_is(const Point3D point) ;
//@}
/** @name Waypoint operations */