owlps/owlps-positioning/src/direction.cc

83 lines
1.2 KiB
C++

/*
* This file is part of the Owl Positioning System (OwlPS).
* OwlPS is a project of the University of Franche-Comté
* (Université de Franche-Comté), France.
*/
#include "direction.hh"
#include "posexcept.hh"
#include <boost/functional/hash.hpp>
/* *** Constructors *** */
Direction::Direction(const char source):
direction(source)
{
assert_valid() ;
}
/* *** Operations *** */
inline void Direction::assert_valid() const
{
if (! (is_valid() || direction == 0))
throw bad_direction(direction) ;
}
inline bool Direction::is_valid() const
{
return direction > 0 && direction <= 4 ;
}
/* *** Operators *** */
Direction& Direction::operator=(const Direction &source)
{
direction = source.direction ;
return *this ;
}
Direction& Direction::operator=(const char source)
{
direction = source ;
assert_valid() ;
return *this ;
}
Direction::operator std::string() const
{
switch (direction)
{
case north:
return "north" ;
case east:
return "east" ;
case south:
return "south" ;
case west:
return "west" ;
}
return "Bad direction!" ;
}
size_t hash_value(const Direction &source)
{
return boost::hash_value(source.direction) ;
}