Cute Chess 0.1
pgnstream.h
1/*
2 This file is part of Cute Chess.
3 Copyright (C) 2008-2018 Cute Chess authors
4
5 Cute Chess is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Cute Chess is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef PGNSTREAM_H
20#define PGNSTREAM_H
21
22#include <QtGlobal>
23#include <QString>
24class QIODevice;
25namespace Chess { class Board; }
26
27
42class LIB_EXPORT PgnStream
43{
44 public:
46 enum Status
47 {
50 };
51
81
88 explicit PgnStream(const QString& variant = "standard");
90 explicit PgnStream(QIODevice* device,
91 const QString& variant = "standard");
93 explicit PgnStream(const QByteArray* string,
94 const QString& variant = "standard");
95
97 ~PgnStream();
98
103 Chess::Board* board();
104
106 QIODevice* device() const;
108 void setDevice(QIODevice* device);
109
111 const QByteArray* string() const;
113 void setString(const QByteArray* string);
114
116 QString variant() const;
121 bool setVariant(const QString& variant);
122
124 bool isOpen() const;
125
127 qint64 pos() const;
128
130 qint64 lineNumber() const;
131
133 void reset();
134
136 char readChar();
146 void rewindChar();
151 void rewind();
157 bool seek(qint64 pos, qint64 lineNumber = 1);
158
160 Status status() const;
161
171 bool nextGame();
178 TokenType readNext();
179
184 QByteArray tokenString() const;
189 TokenType tokenType() const;
190
192 QByteArray tagName() const;
194 QByteArray tagValue() const;
195 private:
196 enum Phase
197 {
198 OutOfGame,
199 InTags,
200 InGame
201 };
202
203 void parseUntil(const char* chars);
204 void parseTag();
205 void parseComment(char opBracket);
206
207 Chess::Board* m_board;
208 qint64 m_pos;
209 qint64 m_lineNumber;
210 char m_lastChar;
211 QByteArray m_tokenString;
212 QByteArray m_tagName;
213 QByteArray m_tagValue;
214 TokenType m_tokenType;
215 QIODevice* m_device;
216 const QByteArray* m_string;
217 Status m_status;
218 Phase m_phase;
219};
220
221#endif // PGNSTREAM_H
An internal chessboard class.
Definition board.h:58
A class for reading games in PGN format from a text stream.
Definition pgnstream.h:43
Status
Definition pgnstream.h:47
@ ReadPastEnd
The stream has read past the end of the data.
Definition pgnstream.h:49
@ Ok
The stream is operating normally.
Definition pgnstream.h:48
PgnStream(const QString &variant="standard")
Definition pgnstream.cpp:60
TokenType
Definition pgnstream.h:53
@ NoToken
Definition pgnstream.h:55
@ PgnComment
Definition pgnstream.h:71
@ PgnLineComment
Definition pgnstream.h:73
@ PgnTag
Definition pgnstream.h:65
@ PgnResult
Definition pgnstream.h:77
@ PgnMoveNumber
Definition pgnstream.h:59
@ PgnNag
Definition pgnstream.h:75
@ Unknown
Definition pgnstream.h:79
@ PgnMove
Definition pgnstream.h:57