/*
 * 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
 *   https://code.lm7.fr/mcy/owlps/src/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
 * this notice by the COPYRIGHT.t2t file's contents.
 */


#ifndef _OWLPS_POSITIONING_DIRECTION_HH_
#define _OWLPS_POSITIONING_DIRECTION_HH_

#include <functional> // for std::hash
#include <string>

/// Represents a direction in which a mobile is when it sends a
/// CalibrationRequest
class Direction
{
protected:
  uint_fast8_t direction ;

  void assert_valid(void) const ;
  bool is_valid(void) const ;

public:
  enum {north = 1, east, south, west} ;

  Direction(void): direction(0) {}
  explicit Direction(const uint_fast8_t source);
  Direction(const Direction &source): direction(source.direction) {}

  /** @name Accessors */
  //@{
  void clear(void) ;
  //@}

  /** @name Operators */
  //@{
  Direction& operator=(const Direction &source) ;
  Direction& operator=(const uint_fast8_t source) ;
  bool operator==(const Direction &source) const ;
  bool operator!=(const Direction &source) const ;
  operator bool(void) const ;
  operator int(void) const ;
  operator std::string(void) const ;
  //@}
} ;



/* *** Accessors *** */


inline void Direction::clear()
{
  direction = 0 ;
}



/* *** Operators *** */


inline bool Direction::operator==(const Direction &source) const
{
  return direction == source.direction ;
}


inline bool Direction::operator!=(const Direction &source) const
{
  return !(*this == source) ;
}


inline Direction::operator int() const
{
  return static_cast<int>(direction) ;
}



namespace std
{
template<> struct hash<Direction>
{
public:
  size_t operator()(const Direction &source) const
  {
    hash<int> h ;
    return h(source) ;
  }
} ;
}



#endif // _OWLPS_POSITIONING_DIRECTION_HH_
