blob: a89de73a963cca6dd78bf53f3ea0dbd716d3fb4b (
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
71
72
73
74
75
|
#include <algorithm>
#include <exception>
#include <fstream>
#include <iostream>
#include <streambuf>
#include <string>
#include <unordered_map>
#include <vector>
namespace pgnp {
class HalfMove {
private:
/// @brief Recursive dump
void NestedDump(HalfMove *, int);
public:
int count;
bool isBlack;
std::string move;
std::string comment;
HalfMove *MainLine;
std::vector<HalfMove *> variations;
HalfMove();
~HalfMove();
int GetLength();
/// @brief Dump move and all its variations
void Dump();
};
class PGN {
private:
std::unordered_map<std::string, std::string> tags;
std::vector<std::string> tagkeys;
HalfMove *moves;
std::string pgn_content;
public:
~PGN();
void FromFile(std::string);
void FromString(std::string);
bool HasTag(std::string);
/// @brief Perform a Seven Tag Roster compliance check
void STRCheck();
/// @brief Dump parsed PGN
void Dump();
std::vector<std::string> GetTagList();
std::string GetTagValue(std::string);
HalfMove *GetMoves();
private:
/// @brief Populate @a tags with by parsing the one starting at location in
/// argument
int ParseNextTag(int);
/// @brief Get the next non-blank char location starting from location in
/// argument
int NextNonBlank(int);
int ParseLine(int, HalfMove *);
};
struct UnexpectedEOF : public std::exception {
const char *what() const throw() { return "Unexpected end of pgn file"; }
};
struct STRCheckFailed : public std::exception {
const char *what() const throw() {
return "Seven Tag Roster compliance check failed";
}
};
} // namespace pgnp
|