owlps/owlps-positioning/waypoint.hh

125 lines
3.0 KiB
C++

#ifndef _OWLPS_POSITIONING_WAYPOINT_HH_
#define _OWLPS_POSITIONING_WAYPOINT_HH_
class Building ;
#include "point3d.hh"
#include <ostream>
#include <vector>
#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
/** Note that \em buildings is a \em pointer list: only pointers
are stored, not values. */
std::vector<Building*> buildings ;
public:
/// Constructs a Waypoint from a Building pointer and a Point3D
Waypoint(const Building *_b, const Point3D &p) ;
/// \brief Constructs a Waypoint from a Building pointer and a
/// 3-float defined point (or default constructor)
Waypoint(const Building *_b = NULL, const float &_x = 0,
const float &_y = 0, const float &_z = 0) ;
/// Constructs a Waypoint from a Point3D
Waypoint(const Point3D &p): Point3D(p) {}
/// Copy constructor
Waypoint(const Waypoint &wp): Point3D(wp), buildings(wp.buildings) {}
~Waypoint(void) ; ///< Destructor
/** @name Read accessors */
//@{
/// #buildings's first element read accessor
Building* get_1st_building(void) const ;
/// #buildings read accessor
const std::vector<Building*>& get_buildings(void) const ;
//@}
/** @name Write accessors */
//@{
/// Adds a Building to the \link #buildings building list\endlink
void add_building(const Building *_b) ;
//@}
/** @name Operators */
//@{
const Waypoint& operator=(const Waypoint &wp) ;
bool operator==(const Waypoint &wp) const ;
bool operator!=(const Waypoint &wp) 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
{
try
{
return buildings.at(0) ;
}
catch (std::out_of_range &e)
{
return NULL ;
}
}
inline const std::vector<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.push_back((Building *) _b) ;
}
/* *** Operators *** */
inline bool Waypoint::operator!=(const Waypoint &wp) const
{
return !(*this == wp) ;
}
#endif // _OWLPS_POSITIONING_WAYPOINT_HH_