Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

Move.hpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file
00003  */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef MOVE_HPP
00007 #define MOVE_HPP
00008 
00009 #include "Hex.hpp"
00010 
00011 _BEGIN_BENZENE_NAMESPACE_
00012 
00013 //----------------------------------------------------------------------------
00014 
00015 /** A (HexColor, HexPoint) pair. */
00016 class Move
00017 {
00018 public:
00019 
00020     /** Creates the move (color, point). */
00021     Move(HexColor color, HexPoint point);
00022     
00023     /** Returns color of move. */
00024     HexColor color() const;
00025 
00026     /** Returns point of move. */
00027     HexPoint point() const;
00028 
00029     /** Outputs a [color, move] string. */
00030     std::string toString() const;
00031 
00032     /** Returns true if point and color are equal. */
00033     bool operator==(const Move& other) const;
00034 
00035     /** Returns true !operator==(other). */
00036     bool operator!=(const Move& other) const;
00037 
00038 private:
00039     HexColor m_color;
00040     HexPoint m_point;
00041 };
00042 
00043 inline Move::Move(HexColor color, HexPoint point)
00044     : m_color(color), m_point(point)
00045 {
00046 }
00047 
00048 inline HexColor Move::color() const
00049 {
00050     return m_color;
00051 }
00052 
00053 inline HexPoint Move::point() const
00054 {
00055     return m_point;
00056 }
00057 
00058 inline std::string Move::toString() const
00059 {
00060     std::ostringstream os;
00061     os << '[' << m_color << ", " << m_point << ']';
00062     return os.str();
00063 }
00064 
00065 inline bool Move::operator==(const Move& other) const
00066 {
00067     return m_color == other.m_color
00068         && m_point == other.m_point;
00069 }
00070 
00071 inline bool Move::operator!=(const Move& other) const
00072 {
00073     return !operator==(other);
00074 }
00075 
00076 //----------------------------------------------------------------------------
00077 
00078 /** Extends standard output operator to Moves. */
00079 inline std::ostream& operator<<(std::ostream& os, const Move& move)
00080 {
00081     return os << move.toString();
00082 }
00083 
00084 //----------------------------------------------------------------------------
00085 
00086 /** Sequence of moves. */
00087 typedef std::vector<Move> MoveSequence;
00088 
00089 /** Extends standard output operator for MoveSequences. */
00090 inline std::ostream& operator<<(std::ostream& os, const MoveSequence& move)
00091 {
00092     for (std::size_t i = 0; i < move.size(); ++i)
00093         os << move[i] << ' ';
00094     return os;
00095 }
00096 
00097 //----------------------------------------------------------------------------
00098 
00099 _END_BENZENE_NAMESPACE_
00100 
00101 #endif // MOVE_HPP


6 Jan 2011 Doxygen 1.6.3