ChessNotation.h
Go to the documentation of this file.
1 // cwchessboard -- A C++ chessboard tool set
2 //
3 //! @file ChessNotation.h This file contains the declaration of class ChessNotation.
4 //
5 // Copyright (C) 2008, by
6 //
7 // Carlo Wood, Run on IRC <carlo@alinoe.com>
8 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
9 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 2 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 
24 #ifndef CHESSNOTATION_H
25 #define CHESSNOTATION_H
26 
27 #ifndef USE_PCH
28 #include <iosfwd>
29 #endif
30 
31 #include "ChessPosition.h"
32 #include "Type.h"
33 #include "Piece.h"
34 #include "Index.h"
35 #include "Move.h"
36 
37 namespace cwchess {
38 
39 /** @brief A helper class to write other objects to an ostream.
40 *
41  * This class allows objects of several types to be written to an ostream in a human readable form.
42 *
43  * The constructor always takes the chess_position that the
44  * object refers to as first argument.
45 *
46  * Usage example:
47  * \code
48  * std::cout << ChessNotation(chess_position, move);
49  * \endcode
50 * /
52  private:
53  ChessPosition const& M_chess_position;
54  Type const* M_type;
55  Piece const* M_piece;
56  Index const* M_index;
57  Move const* M_move;
58 
59  public:
60 
61  /** @name Constructors* /
62  //@{
63 
64  ChessNotation(ChessPosition const& chess_position, Piece const& piece) :
65  M_chess_position(chess_position), M_type(NULL), M_piece(&piece), M_index(NULL), M_move(NULL) { }
66  ChessNotation(ChessPosition const& chess_position, Index const& index) :
67  M_chess_position(chess_position), M_type(NULL), M_piece(NULL), M_index(&index), M_move(NULL) { }
68  ChessNotation(ChessPosition const& chess_position, Move const& move) :
69  M_chess_position(chess_position), M_type(NULL), M_piece(NULL), M_index(NULL), M_move(&move) { }
70  ChessNotation(ChessPosition const& chess_position, Type const& type) :
71  M_chess_position(chess_position), M_type(&type), M_piece(NULL), M_index(NULL), M_move(NULL) { }
72 
73  //@}
74 
75  public_notdocumented:
76  void print_on(std::ostream& os, Type const& type) const;
77  void print_on(std::ostream& os, Piece const& piece) const;
78  void print_on(std::ostream& os, Index const& index) const;
79  void print_on(std::ostream& os, Move const& move) const;
80 
81  friend std::ostream& operator<<(std::ostream& os, ChessNotation const& chess_notation);
82 };
83 
84 } // namespace ChessNotation
85 
86 #endif // CHESSNOTATION_H
A namespace for all chess related objects that are not related to the GUI.
Definition: Array.h:39
This file contains the declaration of class Type.
This file contains the declaration of class Index.
A chess move in a particular chess position.
Definition: Move.h:44
A helper class to write other objects to an ostream.
Definition: ChessNotation.h:51
A chess piece type.
Definition: Type.h:87
The index of a chess square.
Definition: Index.h:211
A particular piece on the board.
Definition: Piece.h:45
A chess position.
Definition: ChessPosition.h:50
This file contains the declaration of class ChessPosition.
This file contains the definition of class Move.
This file contains the declaration of class Piece.

Copyright © 2006 - 2010 Carlo Wood.  All rights reserved.