[Positioner] Make Building::areas const

This commit is contained in:
Matteo Cypriani 2013-10-02 17:14:41 -04:00
parent ea01f09b5e
commit 5520541217
5 changed files with 9 additions and 7 deletions

View File

@ -75,7 +75,7 @@ void Building::add_area(Area *&area)
return ;
}
areas[area_name] = const_cast<Area*>(area) ;
areas[area_name] = area ;
}

View File

@ -29,7 +29,7 @@ class Building
protected:
std::string name ;
/// List of Area contained in the Building
std::unordered_map<std::string, Area*> areas ;
std::unordered_map<std::string, const Area*> areas ;
/// List of Waypoint in the Building
std::unordered_set<Waypoint*> waypoints ;
@ -46,7 +46,8 @@ public:
/** @name Read accessors */
//@{
const std::string& get_name(void) const ;
const std::unordered_map<std::string, Area*>& get_areas(void) const ;
const std::unordered_map<std::string, const Area*>&
get_areas(void) const ;
const std::unordered_set<Waypoint*>& get_waypoints(void) const ;
//@}
@ -81,7 +82,7 @@ inline const std::string& Building::get_name() const
}
inline const std::unordered_map<std::string, Area*>&
inline const std::unordered_map<std::string, const Area*>&
Building::get_areas() const
{
return areas ;

View File

@ -100,7 +100,8 @@ const Area* Stock::in_which_area_is(const Point3D &point)
{
for (auto b = buildings.begin() ; b != buildings.end() ; ++b)
{
const unordered_map<string, Area*> &areas = b->second.get_areas() ;
const unordered_map<string, const Area*> &areas =
b->second.get_areas() ;
for (auto a = areas.begin() ; a != areas.end() ; ++a)
if (a->second->contains_point(point))
return a->second ;

View File

@ -41,7 +41,7 @@ public:
// Simple read accessors
Building b1 ;
TS_ASSERT_EQUALS(b1.get_name(), "Unnamed building") ;
std::unordered_map<std::string, Area*> areas1 ;
std::unordered_map<std::string, const Area*> areas1 ;
TS_ASSERT_EQUALS(b1.get_areas(), areas1) ;
std::unordered_set<Waypoint*> waypoints1 ;
TS_ASSERT_EQUALS(b1.get_waypoints(), waypoints1) ;

View File

@ -84,7 +84,7 @@ public:
TS_ASSERT_EQUALS(building1->get_areas().size(), 2u) ;
Area *area_ptr ;
const Area *area_ptr ;
area_ptr = building1->get_areas().find("My room #1")->second ;
Area area1(building1, "My room #1",
Point3D(1,2,3), Point3D(9,8,7)) ;