owlps/owlps-positioning/src/waypoint.hh

134 lines
3.1 KiB
C++
Raw Normal View History

#ifndef _OWLPS_POSITIONING_WAYPOINT_HH_
#define _OWLPS_POSITIONING_WAYPOINT_HH_
class Building ;
#include "point3d.hh"
#include <boost/tr1/unordered_set.hpp>
#include <ostream>
#include <stdexcept>
/// Represents a junction point between several rooms (i.e. Area)
/**
* A Waypoint is defined by its coordinates and linked to the buildings
* it belongs to. You \em should always construct a Waypoint with at least
* one associated Building, but you \em can not do so, for instance in an
* automatic construction (container).
*/
class Waypoint: public Point3D
{
protected:
/// List of Building associated with the Waypoint
std::tr1::unordered_set<Building*> buildings ;
public:
Waypoint(const Building *_b = NULL, const float &_x = 0,
const float &_y = 0, const float &_z = 0) ;
Waypoint(const Building *_b, const Point3D &p) ;
Waypoint(const Point3D &p): Point3D(p) {}
Waypoint(const Waypoint &wp): Point3D(wp), buildings(wp.buildings) {}
~Waypoint(void) ;
/** @name Read accessors */
//@{
/// #buildings's first element read accessor
Building* get_1st_building(void) const ;
const std::tr1::unordered_set<Building*>& get_buildings(void) const ;
//@}
/** @name Write accessors */
//@{
/// Adds a Building to the \link #buildings building list\endlink
void add_building(const Building *_b) ;
/// Adds the Building list of \em source to #buildings
void add_buildings(const Waypoint &source) ;
/// Removes a Building from #buildings
void remove_building(const Building *_b) ;
//@}
/** @name Operators */
//@{
Waypoint& operator=(const Waypoint &wp) ;
bool operator==(const Waypoint &wp) const ;
bool operator!=(const Waypoint &wp) const ;
operator std::string(void) const ;
//@}
/// Displays a Waypoint
friend std::ostream& operator<<(std::ostream &os, const Waypoint &wp) ;
} ;
/* *** Read accessors *** */
/**
* @return A pointer to the first Building associated with the Waypoint
* (i.e. the first element of #buildings). If #buildings is empty, NULL
* is returned.
*/
inline Building* Waypoint::get_1st_building() const
{
if (buildings.empty())
return NULL ;
return *buildings.begin() ;
}
inline const std::tr1::unordered_set<Building*>&
Waypoint::get_buildings() const
{
return buildings ;
}
/* *** Write accessors *** */
/**
* @param _b A pointer to the Building to add. If it is
* NULL, nothing will be done.
* The memory pointed by this pointer must not be deallocated before
* the Waypoint destruction (do \em not pass a pointer to a local
* variable!).
*/
inline void Waypoint::add_building(const Building *_b)
{
if (_b != NULL)
buildings.insert(const_cast<Building*>(_b)) ;
}
inline void Waypoint::remove_building(const Building *_b)
{
if (_b != NULL)
buildings.erase(const_cast<Building*>(_b)) ;
}
inline void Waypoint::add_buildings(const Waypoint &source)
{
buildings.insert(source.buildings.begin(), source.buildings.end()) ;
}
/* *** Operators *** */
inline bool Waypoint::operator!=(const Waypoint &wp) const
{
return !(*this == wp) ;
}
#endif // _OWLPS_POSITIONING_WAYPOINT_HH_