2022-01-26 15:52:31 +01:00
|
|
|
[](https://gitlab.com/manzerbredes/pgnp/-/commits/master)
|
2022-01-26 15:46:59 +01:00
|
|
|
[](https://www.gnu.org/licenses/lgpl-3.0)
|
2022-01-26 15:38:54 +01:00
|
|
|
|
2022-01-23 20:57:28 +01:00
|
|
|
## PGNP: PGN Parser
|
|
|
|
|
|
|
|
PGNP is a Portable Game Notation (PGN) parser. More details about the
|
|
|
|
PGN specification can be found [here](https://www.chessclub.com/help/PGN-spec).
|
|
|
|
|
2022-01-25 16:51:37 +01:00
|
|
|
# Features
|
2022-01-26 12:03:24 +01:00
|
|
|
- Basic PGN parsing (tags, move, comments, variations, NAG, etc.)
|
2022-01-25 16:51:37 +01:00
|
|
|
- Merged PGN files parsing (several games in one file)
|
2022-01-26 12:03:24 +01:00
|
|
|
- Handle very large file (severals GB)
|
|
|
|
- Very efficient
|
2022-01-25 16:51:37 +01:00
|
|
|
|
2022-01-23 20:57:28 +01:00
|
|
|
# How to use it ?
|
|
|
|
PGNP can be used as a shared library in your project.
|
2022-01-25 11:10:34 +01:00
|
|
|
You only need to include `pgnp.hpp` and linking the .so file to your
|
2022-01-23 20:57:28 +01:00
|
|
|
executable.
|
|
|
|
|
|
|
|
# Example
|
2022-01-25 11:10:34 +01:00
|
|
|
Somewhere at the beginning of the file:
|
|
|
|
|
|
|
|
#include "pgnp.hpp"
|
2022-01-23 20:57:28 +01:00
|
|
|
Load PGN from file:
|
|
|
|
|
|
|
|
pgnp::PGN pgn;
|
|
|
|
try {
|
|
|
|
pgn.FromFile("pgn.txt");
|
2022-01-25 16:51:37 +01:00
|
|
|
pgn.ParseNextGame();
|
2022-01-23 20:57:28 +01:00
|
|
|
}
|
|
|
|
catch(...){
|
|
|
|
// Handle exceptions
|
|
|
|
}
|
|
|
|
Load PGN from string:
|
|
|
|
|
|
|
|
pgnp::PGN pgn;
|
2022-01-25 16:51:37 +01:00
|
|
|
pgn.FromString("YOUR PGN CONTENT HERE");
|
2022-01-23 20:57:28 +01:00
|
|
|
try {
|
2022-01-25 16:51:37 +01:00
|
|
|
pgn.ParseNextGame();
|
2022-01-23 20:57:28 +01:00
|
|
|
}
|
|
|
|
catch(...){
|
|
|
|
// Handle exceptions
|
|
|
|
}
|
2022-01-24 16:52:26 +01:00
|
|
|
Various API calls:
|
|
|
|
|
2022-01-25 11:10:34 +01:00
|
|
|
bool hasRound=pgn.HasTag("Round"); // Check if tag exists
|
2022-01-24 16:53:11 +01:00
|
|
|
try {
|
|
|
|
pgn.STRCheck(); // Perform a Seven Tag Roster check
|
|
|
|
}
|
|
|
|
catch(...){
|
|
|
|
// Handle exceptions
|
|
|
|
}
|
|
|
|
std::vector<std::string> tags=pgn.GetTagList(); // Get a list of tags
|
|
|
|
std::string tagValue=GetTagValue("Date"); // Get the value of a tag
|
2022-01-24 16:52:26 +01:00
|
|
|
Access to moves:
|
|
|
|
|
2022-01-25 11:10:34 +01:00
|
|
|
pgnp::HalfMove *moves=new pgnp::HalfMove();
|
|
|
|
pgn.GetMoves(moves); // Get the tree of half moves (do not forget to call "delete move" later on)
|
|
|
|
int length=moves->GetLength(); // Get the number of half moves in the move MainLine
|
2022-01-24 16:53:11 +01:00
|
|
|
// Public members:
|
2022-01-25 11:10:34 +01:00
|
|
|
// moves->variations contains variations of the current move
|
|
|
|
// moves->isBlack boolean that says if current half move is for the black side
|
|
|
|
// Check pgnp.hpp for more infos for the other fields (comments, count, etc.)
|
|
|
|
|
|
|
|
# CMake Integration
|
|
|
|
By using the `add_subdirectory()` on this repository you will be able to use the following cmake calls in you project:
|
|
|
|
|
|
|
|
include_directories(${PGNP_INCLUDE_DIR})
|
|
|
|
target_link_libraries(<YOUR_TARGET> pgnp)
|
|
|
|
|
2022-01-23 20:57:28 +01:00
|
|
|
|