From 8c77f7a054eb15d3e73649bce5447f172a99969c Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 24 Jan 2022 15:29:22 +0100 Subject: Improve overall parsing --- src/pgnp.hpp | 89 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 30 deletions(-) (limited to 'src/pgnp.hpp') diff --git a/src/pgnp.hpp b/src/pgnp.hpp index 25e74c8..a89de73 100644 --- a/src/pgnp.hpp +++ b/src/pgnp.hpp @@ -1,46 +1,75 @@ -#include -#include +#include +#include #include -#include #include -#include +#include +#include +#include +#include namespace pgnp { +class HalfMove { +private: + /// @brief Recursive dump + void NestedDump(HalfMove *, int); - typedef struct HalfMove { - - } HalfMove; +public: + int count; + bool isBlack; + std::string move; + std::string comment; + HalfMove *MainLine; + std::vector variations; + HalfMove(); + ~HalfMove(); + int GetLength(); + /// @brief Dump move and all its variations + void Dump(); +}; - class PGN { - private: - std::unordered_map tags; - HalfMove moves; - std::string pgn_content; +class PGN { +private: + std::unordered_map tags; + std::vector tagkeys; - public: - void FromFile(std::string); - void FromString(std::string); + 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 GetTagList(); + std::string GetTagValue(std::string); + HalfMove *GetMoves(); - private: +private: + /// @brief Populate @a tags with by parsing the one starting at location in + /// argument + int ParseNextTag(int); - /// @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); - }; + /// @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 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 -- cgit v1.2.3