HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
hoover_chess_utils::pgn_reader::PgnReaderActions Class Reference

Semantic actions for reading a PGN. The caller is expected to inherit this class and override all callbacks of interest. More...

#include <pgnreader.h>

Public Member Functions

virtual void gameStart ()
 Invoked when a new game starts.
 
virtual void pgnTag (std::string_view key, std::string_view value)
 Invoked when a PGN tag has been read.
 
virtual void moveTextSection ()
 Invoked when all PGN tags of the game are read and before any moves are processed.
 
virtual void comment (std::string_view comment)
 PGN comment.
 
virtual void gameTerminated (PgnResult result)
 Invoked after the game termination marker is processed.
 
virtual void setBoardReferences (const ChessBoard &curBoard, const ChessBoard &prevBoard)
 Invoked when the PGN reader is instantiated.
 
virtual void afterMove (Move move)
 Invoked after a move is processed.
 
virtual void nag (std::uint8_t nagNum)
 Invoked after a numeric annotation glyph (NAG) is processed.
 
virtual void variationStart ()
 Invoked after a variation start is processed.
 
virtual void variationEnd ()
 Invoked after a variation end marker is encountered but before the board states have been restored.
 
virtual void endOfPGN ()
 End of PGN.
 
virtual PgnReaderOnErrorAction onError (const PgnError &error, const PgnErrorInfo &additionalInfo)
 Error handler for recoverable errors.
 

Detailed Description

Semantic actions for reading a PGN. The caller is expected to inherit this class and override all callbacks of interest.

Member Function Documentation

◆ afterMove()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::afterMove ( Move  move)
inlinevirtual

Invoked after a move is processed.

Parameters
[in]moveMove

The state of *curBoard is after move. The state of *prevBoard is before move.

Callback is filtered by PgnReaderActionClass::Move.

◆ comment()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::comment ( std::string_view  comment)
inlinevirtual

PGN comment.

Parameters
[in]commentComment text

PGN comments may occur almost anywhere.

Callback is filtered by PgnReaderActionClass::Comment.

◆ endOfPGN()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::endOfPGN ( )
inlinevirtual

End of PGN.

◆ gameStart()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::gameStart ( )
inlinevirtual

Invoked when a new game starts.

Callback is always enabled.

◆ gameTerminated()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::gameTerminated ( PgnResult  result)
inlinevirtual

Invoked after the game termination marker is processed.

Parameters
[in]resultGame result

Callback is always enabled.

◆ moveTextSection()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::moveTextSection ( )
inlinevirtual

Invoked when all PGN tags of the game are read and before any moves are processed.

The state of *curBoard is the game starting position. The state of *prevBoard is the same.

Callback is always enabled.

◆ nag()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::nag ( std::uint8_t  nagNum)
inlinevirtual

Invoked after a numeric annotation glyph (NAG) is processed.

Parameters
[in]nagNumNumeric value of the NAG.

Callback is filtered by PgnReaderActionClass::Move and PgnReaderActionClass::NAG (both required).

◆ onError()

virtual PgnReaderOnErrorAction hoover_chess_utils::pgn_reader::PgnReaderActions::onError ( const PgnError error,
const PgnErrorInfo additionalInfo 
)
inlinevirtual

Error handler for recoverable errors.

Parameters
[in]errorError object
[in]additionalInfoAdditional information on error
Returns
Recovery actions. Default: PgnReaderOnErrorAction::Abort

Caller-provided error handler is invoked on recoverable PGN errors. Those are tokenizer (scanner) errors, parser errors, board setup errors (FEN errors), move replay errors, and other errors related to the correctness of the PGN input. When such an error occurs, this callback function is invoked, which then returns the policy action.

The actions are:

  • PgnReaderOnErrorAction::Abort (default) — Abort processing and re-throw the PGN error exception as is. This is the default policy in case error handler is not overridden.
  • PgnReaderOnErrorAction::ContinueFromNextGame — Abort processing the current game. Skip to the next game and continue from there. Note the following:
    • No further action handlers are invoked for the current game. In particular, there will be no calls to close already started variations, nor there will be a call to gameTerminated() to indicate that the game ended.
    • The exception will not be re-thrown by PgnReader::readFromMemory().

Internally, the procedure to skip to the next game when PgnReaderOnErrorAction::ContinueFromNextGame is returned is straightforward. The tokenizer is invoked until it returns either RESULT (i.e., "1-0", "1/2-1/2", "0-1", "*") or END_OF_FILE tokens. It is possible that more than more error is returned for a single erroneous game.

◆ pgnTag()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::pgnTag ( std::string_view  key,
std::string_view  value 
)
inlinevirtual

Invoked when a PGN tag has been read.

Parameters
[in]keyKey of the PGN tag
[in]valueValue of the PGN tag

Callback is filtered by PgnReaderActionClass::PgnTag.

◆ setBoardReferences()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::setBoardReferences ( const ChessBoard curBoard,
const ChessBoard prevBoard 
)
inlinevirtual

Invoked when the PGN reader is instantiated.

Parameters
[in]curBoardPointer to current board (after move)
[in]prevBoardPointer to previous board (before move)

Callback is filtered by PgnReaderActionClass::Move.

◆ variationEnd()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::variationEnd ( )
inlinevirtual

Invoked after a variation end marker is encountered but before the board states have been restored.

The state of *curBoard the end of variation, after the last move. The state of *prevBoard before the last move.

Callback is filtered by PgnReaderActionClass::Variation.

◆ variationStart()

virtual void hoover_chess_utils::pgn_reader::PgnReaderActions::variationStart ( )
inlinevirtual

Invoked after a variation start is processed.

The state of *curBoard is beginning of variation (before any moves). The state of *prevBoard is the same.

Callback is filtered by PgnReaderActionClass::Variation.


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