Add QDataStream functions to PgnGameEntry
[sloppygui.git] / projects / lib / src / pgngameentry.h
blobddbff219475eaba7d42fb23dccc56b85962ce700
1 /*
2 This file is part of Cute Chess.
4 Cute Chess is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 Cute Chess is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef PGNGAMEENTRY_H
19 #define PGNGAMEENTRY_H
21 #include "board/result.h"
22 class PgnStream;
23 class QDataStream;
26 /*!
27 * \brief An entry in a PGN collection.
29 * A PgnGameEntry object contains the tags of a PGN game, and
30 * the position and line number in a PGN stream.
31 * This class was designed for high-performance and low memory
32 * consumption, which is useful for quickly loading large game
33 * collections.
35 * \sa PgnGame, PgnStream
37 class LIB_EXPORT PgnGameEntry
39 public:
40 /*! Creates a new empty PgnGameEntry object. */
41 explicit PgnGameEntry(const QByteArray& variant = "standard");
43 /*! Resets the entry to an empty default. */
44 void clear();
45 /*!
46 * Reads an entry from a PGN stream.
47 * Returns true if successfull.
49 bool read(PgnStream& in);
51 /*!
52 * Reads an entry from data stream.
53 * Returns true if successfull.
55 bool read(QDataStream& in);
57 /*!
58 * Writes an entry to data stream.
60 void write(QDataStream& out) const;
62 /*! Returns the stream position where the game begins. */
63 qint64 pos() const;
64 /*! Returns the line number where the game begins. */
65 qint64 lineNumber() const;
67 /*! Returns the event/tournament name. */
68 QString event() const;
69 /*! Returns the site/location where the game was played. */
70 QString site() const;
71 /*! Returns the round number of a match or tournament. */
72 int round() const;
73 /*! Returns the name of the white player. */
74 QString white() const;
75 /*! Returns the name of the black player. */
76 QString black() const;
77 /*! Returns the game's chess variant. */
78 QString variant() const;
79 /*! Returns the game result. */
80 Chess::Result result() const;
82 private:
83 void addTag(const QByteArray& tagName, const QByteArray& tagValue);
85 int m_round;
86 qint64 m_pos;
87 qint64 m_lineNumber;
88 QByteArray m_event;
89 QByteArray m_site;
90 QByteArray m_white;
91 QByteArray m_black;
92 QByteArray m_variant;
93 Chess::Result m_result;
96 /*! Reads a PGN game entry from a PGN stream. */
97 extern LIB_EXPORT PgnStream& operator>>(PgnStream& in, PgnGameEntry& entry);
99 /*! Reads a PGN game entry from a data stream. */
100 extern LIB_EXPORT QDataStream& operator>>(QDataStream& in, PgnGameEntry& entry);
102 /*! Writes a PGN game entry to a data stream. */
103 extern LIB_EXPORT QDataStream& operator<<(QDataStream& out,
104 const PgnGameEntry& entry);
106 #endif // PGNGAMEENTRY_H