mirror of
https://gitlab.com/manzerbredes/chess-move-interface.git
synced 2025-05-01 09:27:44 +00:00
Improve PGNP API
This commit is contained in:
parent
bdd879586e
commit
e817ac6bed
4 changed files with 36 additions and 8 deletions
24
src/pgnp.cpp
24
src/pgnp.cpp
|
@ -16,7 +16,7 @@
|
|||
|
||||
namespace pgnp {
|
||||
|
||||
HalfMove::HalfMove() : isBlack(false), MainLine(NULL) {}
|
||||
HalfMove::HalfMove() : count(-1), isBlack(false), MainLine(NULL) {}
|
||||
|
||||
HalfMove::~HalfMove() {
|
||||
for (auto *move : variations) {
|
||||
|
@ -55,6 +55,26 @@ int HalfMove::GetLength() {
|
|||
return length;
|
||||
}
|
||||
|
||||
void HalfMove::Copy(HalfMove* copy){
|
||||
copy->count=count;
|
||||
copy->isBlack=isBlack;
|
||||
copy->move=move;
|
||||
copy->comment=comment;
|
||||
|
||||
// Copy MainLine
|
||||
if(MainLine!=NULL){
|
||||
copy->MainLine=new HalfMove();
|
||||
MainLine->Copy(copy->MainLine);
|
||||
}
|
||||
|
||||
// Copy variation
|
||||
for(HalfMove *var:variations){
|
||||
HalfMove *new_var=new HalfMove();
|
||||
copy->variations.push_back(new_var);
|
||||
var->Copy(new_var);
|
||||
}
|
||||
}
|
||||
|
||||
PGN::~PGN() {
|
||||
if (moves != NULL)
|
||||
delete moves;
|
||||
|
@ -265,7 +285,7 @@ int PGN::ParseNextTag(int start_loc) {
|
|||
return (valueloc + 1); // +1 For the last char of the tag which is ']'
|
||||
}
|
||||
|
||||
HalfMove *PGN::GetMoves() { return (moves); }
|
||||
void PGN::GetMoves(HalfMove* copy) { moves->Copy(copy); }
|
||||
|
||||
std::vector<std::string> PGN::GetTagList() { return tagkeys; }
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
int GetLength();
|
||||
/// @brief Dump move and all its variations
|
||||
void Dump();
|
||||
void Copy(HalfMove* copy);
|
||||
};
|
||||
|
||||
class PGN {
|
||||
|
@ -52,7 +53,7 @@ public:
|
|||
std::vector<std::string> GetTagList();
|
||||
std::string GetTagValue(std::string);
|
||||
std::string GetResult();
|
||||
HalfMove *GetMoves();
|
||||
void GetMoves(HalfMove*);
|
||||
|
||||
private:
|
||||
/// @brief Populate @a tags with by parsing the one starting at location in
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue