From fd78f92863361a3b25808f2ca988f820f2d35618 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 23 Jan 2022 20:57:28 +0100 Subject: Create project --- src/pgnp.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pgnp.hpp | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 src/pgnp.cpp create mode 100644 src/pgnp.hpp (limited to 'src') diff --git a/src/pgnp.cpp b/src/pgnp.cpp new file mode 100644 index 0000000..391e6ee --- /dev/null +++ b/src/pgnp.cpp @@ -0,0 +1,81 @@ + +#include "pgnp.hpp" +#include + +#define IS_BLANK(c) (c==' ' || c=='\n' || c=='\t') +#define IS_EOF(loc) (loc>=pgn_content.size()) +#define EOF_CHECK(loc) {if(IS_EOF(loc)) throw UnexpectedEOF();} + +namespace pgnp { + + void PGN::FromFile(std::string filepath){ + std::ifstream file(filepath); + + std::string content((std::istreambuf_iterator(file)), + std::istreambuf_iterator()); + FromString(content); + } + + + void PGN::FromString(std::string pgn_content){ + this->pgn_content=pgn_content; + int loc=0; + while(!IS_EOF(loc)) { + char c=pgn_content[loc]; + if(!IS_BLANK(c)){ + switch (c) { + case '[': + loc=ParseNextTag(loc); + break; + } + } + loc++; + } + + /*for (auto const& [key, val] : tags){ + std::cout << key <<"="< +#include +#include +#include +#include +#include + +namespace pgnp { + + + typedef struct HalfMove { + + } HalfMove; + + + class PGN { + private: + std::unordered_map tags; + HalfMove moves; + std::string pgn_content; + + public: + void FromFile(std::string); + void FromString(std::string); + + + 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); + }; + + + + struct UnexpectedEOF : public std::exception + { + const char * what () const throw () + { + return "Unexpected end of pgn file"; + } + }; + +} -- cgit v1.2.3