2012-02-06 16:44:09 +01:00
|
|
|
/*
|
2013-05-29 18:43:35 +02:00
|
|
|
* This file is part of the Owl Positioning System (OwlPS) project.
|
|
|
|
* It is subject to the copyright notice and license terms in the
|
|
|
|
* COPYRIGHT.t2t file found in the top-level directory of this
|
|
|
|
* distribution and at
|
|
|
|
* http://code.lm7.fr/p/owlps/source/tree/master/COPYRIGHT.t2t
|
|
|
|
* No part of the OwlPS Project, including this file, may be copied,
|
|
|
|
* modified, propagated, or distributed except according to the terms
|
|
|
|
* contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
|
|
|
|
* distributed along with this file, either separately or by replacing
|
2013-06-22 23:30:17 +02:00
|
|
|
* this notice by the COPYRIGHT.t2t file's contents.
|
2012-02-06 16:44:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-02-18 12:23:05 +01:00
|
|
|
#include "direction.hh"
|
|
|
|
#include "posexcept.hh"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Constructors *** */
|
|
|
|
|
|
|
|
|
2013-06-17 21:24:56 +02:00
|
|
|
Direction::Direction(const uint_fast8_t source):
|
2010-03-05 17:24:18 +01:00
|
|
|
direction(source)
|
2010-02-18 12:23:05 +01:00
|
|
|
{
|
|
|
|
assert_valid() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Operations *** */
|
|
|
|
|
|
|
|
|
|
|
|
inline void Direction::assert_valid() const
|
|
|
|
{
|
2011-06-24 14:44:33 +02:00
|
|
|
if (! (is_valid() || direction == 0))
|
2010-02-18 12:23:05 +01:00
|
|
|
throw bad_direction(direction) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline bool Direction::is_valid() const
|
|
|
|
{
|
|
|
|
return direction > 0 && direction <= 4 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Operators *** */
|
|
|
|
|
|
|
|
|
2011-07-30 20:38:42 +02:00
|
|
|
Direction& Direction::operator=(const Direction &source)
|
2010-02-18 12:23:05 +01:00
|
|
|
{
|
|
|
|
direction = source.direction ;
|
|
|
|
return *this ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-17 21:24:56 +02:00
|
|
|
Direction& Direction::operator=(const uint_fast8_t source)
|
2010-02-18 12:23:05 +01:00
|
|
|
{
|
|
|
|
direction = source ;
|
|
|
|
assert_valid() ;
|
|
|
|
return *this ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-17 19:34:56 +02:00
|
|
|
Direction::operator bool() const
|
|
|
|
{
|
|
|
|
return is_valid() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-18 12:23:05 +01:00
|
|
|
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!" ;
|
|
|
|
}
|