blob: 72c1297a5ab3dba5f6fb01ea72953d15976fe75a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|

## 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).
# Features
- Basic PGN parsing (tags, move, comments, variations, NAG, etc.)
- Merged PGN files parsing (several games in one file)
- Handle very large file (severals GB)
- Very efficient
# How to use it ?
PGNP can be used as a shared library in your project.
You only need to include `pgnp.hpp` and linking the .so file to your
executable.
# Example
Somewhere at the beginning of the file:
#include "pgnp.hpp"
Load PGN from file:
pgnp::PGN pgn;
try {
pgn.FromFile("pgn.txt");
pgn.ParseNextGame();
}
catch(...){
// Handle exceptions
}
Load PGN from string:
pgnp::PGN pgn;
pgn.FromString("YOUR PGN CONTENT HERE");
try {
pgn.ParseNextGame();
}
catch(...){
// Handle exceptions
}
Various API calls:
bool hasRound=pgn.HasTag("Round"); // Check if tag exists
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
Access to moves:
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
// Public members:
// 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)
|