Cute Chess  0.1
Public Types | Public Member Functions | List of all members
PgnStream Class Reference

A class for reading games in PGN format from a text stream. More...

#include <pgnstream.h>

Public Types

enum  Status { Ok, ReadPastEnd }
 
enum  TokenType {
  NoToken, PgnMove, PgnMoveNumber, PgnTag,
  PgnComment, PgnLineComment, PgnNag, PgnResult,
  Unknown
}
 

Public Member Functions

Chess::Boardboard ()
 
QIODevicedevice () const
 
bool isOpen () const
 
qint64 lineNumber () const
 
bool nextGame ()
 
 PgnStream (const QString &variant="standard")
 
 PgnStream (QIODevice *device, const QString &variant="standard")
 
 PgnStream (const QByteArray *string, const QString &variant="standard")
 
qint64 pos () const
 
char readChar ()
 
TokenType readNext ()
 
void reset ()
 
void rewind ()
 
void rewindChar ()
 
bool seek (qint64 pos, qint64 lineNumber=1)
 
void setDevice (QIODevice *device)
 
void setString (const QByteArray *string)
 
bool setVariant (const QString &variant)
 
Status status () const
 
const QByteArraystring () const
 
QByteArray tagName () const
 
QByteArray tagValue () const
 
QByteArray tokenString () const
 
TokenType tokenType () const
 
QString variant () const
 
 ~PgnStream ()
 

Detailed Description

A class for reading games in PGN format from a text stream.

PgnStream is used for reading PGN games from a QIODevice or a string. It has its own input methods, and keeps track of the current line number which can be used to report errors in the games. PgnStream also has its own Chess::Board object, so that the same board can be easily used with all the games in the stream. The chess variant can be changed at any time, so it's possible to read PGN streams that contain games of multiple variants.

See also
PgnGame
OpeningBook

Member Enumeration Documentation

The current status of the PGN stream.

Enumerator
Ok 

The stream is operating normally.

ReadPastEnd 

The stream has read past the end of the data.

The type of a PGN token.

Enumerator
NoToken 

Empty token (ie. nothing was read).

PgnMove 

Move string in Standard Algebraic Notation.

PgnMoveNumber 

Move number before a full move.

PgnTag 

PGN tag.

Note
The token string does NOT contain the opening and closing square brackets.
PgnComment 

PGN comment.

Note
The token string does NOT contain the opening and closing brackets.
PgnLineComment 

One-line PGN comment.

PgnNag 

NAG code (Numeric Annotation Glyph).

PgnResult 

Game result.

Unknown 

Unknown token.

Constructor & Destructor Documentation

PgnStream::PgnStream ( const QString variant = "standard")
explicit

Creates a new PgnStream.

A device or a string must be set before the stream can be used.

PgnStream::PgnStream ( QIODevice device,
const QString variant = "standard" 
)
explicit

Creates a PgnStream that operates on device.

PgnStream::PgnStream ( const QByteArray string,
const QString variant = "standard" 
)
explicit

Creates a PgnStream that operates on string.

PgnStream::~PgnStream ( )

Destructs the PgnStream object.

Member Function Documentation

Chess::Board * PgnStream::board ( )

Returns the Board object which is used to verify the moves and FEN strings in the stream.

QIODevice * PgnStream::device ( ) const

Returns the assigned device, or 0 if no device is in use.

bool PgnStream::isOpen ( ) const

Returns true if the stream is open.

qint64 PgnStream::lineNumber ( ) const

Returns the current line number.

bool PgnStream::nextGame ( )

Seeks to the next game in the stream. Returns true if a game is available; otherwise returns false.

This function must be called once for each new game, or nothing can be parsed.

See also
readNext()
qint64 PgnStream::pos ( ) const

Returns the current position in the stream.

char PgnStream::readChar ( )

Reads one character and returns it.

PgnStream::TokenType PgnStream::readNext ( )

Reads the next token and returns its type.

Returns PgnStream::NoToken if a token is not available.

See also
nextGame(), tokenType(), tokenString()
void PgnStream::reset ( )

Resets the stream to its default state.

void PgnStream::rewind ( )

Rewinds back to the start of input. This is equivalent to calling seek(0).

void PgnStream::rewindChar ( )

Rewinds the stream position by one character, which means that the next time readChar() is called, nothing is read and the buffer character is returned.

Note
Only one character is kept in the buffer, so calling this method multiple times in a row has the same effect as calling it just once.
bool PgnStream::seek ( qint64  pos,
qint64  lineNumber = 1 
)

Seeks to position pos in the device, and sets the current line number to lineNumber. Returns true if successful; otherwise returns false.

void PgnStream::setDevice ( QIODevice device)

Sets the current device to device.

void PgnStream::setString ( const QByteArray string)

Sets the current string to string.

bool PgnStream::setVariant ( const QString variant)

Sets the chess variant to variant. Returns true if successful; otherwise returns false.

PgnStream::Status PgnStream::status ( ) const

Returns the status of the stream.

const QByteArray * PgnStream::string ( ) const

Returns the assigned string, or 0 if no string is in use.

QByteArray PgnStream::tagName ( ) const

Returns the name of the current PGN tag.

QByteArray PgnStream::tagValue ( ) const

Returns the value of the current PGN tag.

QByteArray PgnStream::tokenString ( ) const

Returns the current token as string.

See also
tokenType()
PgnStream::TokenType PgnStream::tokenType ( ) const

Returns the type of the current token.

See also
tokenString()
QString PgnStream::variant ( ) const

Returns the chess variant.


The documentation for this class was generated from the following files: