aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--src/LargeFileStream.cpp6
-rw-r--r--src/LargeFileStream.hpp8
-rw-r--r--src/PGN.cpp16
-rw-r--r--src/PGN.hpp14
-rw-r--r--src/Types.hpp2
6 files changed, 25 insertions, 23 deletions
diff --git a/README.md b/README.md
index a7c1f12..2de279d 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ 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 (max is 2^(sizeof(unsigned long long)) bytes)
+- Handle very large file (max is 2^(sizeof(unsigned long long)*8) bytes)
- Efficiency
# How to use it ?
diff --git a/src/LargeFileStream.cpp b/src/LargeFileStream.cpp
index 95e7c1c..9c34274 100644
--- a/src/LargeFileStream.cpp
+++ b/src/LargeFileStream.cpp
@@ -23,7 +23,7 @@ void LargeFileStream::ReadNextChunk() {
last_read_size = file.gcount();
}
-char LargeFileStream::operator[](ull loc) {
+char LargeFileStream::operator[](loctype loc) {
// Perform various checks
if (eof) {
throw ReadToFar();
@@ -42,11 +42,11 @@ char LargeFileStream::operator[](ull loc) {
}
// Goto the right memory chuck
- ull loc_chunk_count = loc / BUFFER_SIZE;
+ loctype loc_chunk_count = loc / BUFFER_SIZE;
while (chuck_count < loc_chunk_count) {
ReadNextChunk();
}
- ull offset = loc - (loc_chunk_count * BUFFER_SIZE);
+ loctype offset = loc - (loc_chunk_count * BUFFER_SIZE);
// Ensure for EOF
if (!file && offset >= last_read_size) {
diff --git a/src/LargeFileStream.hpp b/src/LargeFileStream.hpp
index 64a7600..4900f35 100644
--- a/src/LargeFileStream.hpp
+++ b/src/LargeFileStream.hpp
@@ -16,11 +16,11 @@ class LargeFileStream {
/// @brief In memory buffer
char buffer[BUFFER_SIZE];
/// @brief Number of chuck read minus 1
- ull chuck_count;
+ loctype chuck_count;
/// @brief Number of byte read during the last file access
- ull last_read_size;
+ loctype last_read_size;
/// @brief Keep track of the file offset (to prevent backward read)
- ull last_loc;
+ loctype last_loc;
/// @brief Use a string as file content
std::string content;
/// @brief Use to shortcut some methods
@@ -37,7 +37,7 @@ public:
/// @brief Emulate file access with a string
void FromString(std::string content);
/// @brief Allow array like access to the file
- char operator[](ull loc);
+ char operator[](loctype loc);
/// @brief Check if we reach the EOF
bool IsEOF();
diff --git a/src/PGN.cpp b/src/PGN.cpp
index 2deb78a..b45632c 100644
--- a/src/PGN.cpp
+++ b/src/PGN.cpp
@@ -45,7 +45,7 @@ void PGN::ParseNextGame() {
if (IS_EOF) {
throw NoGameFound();
}
- ull loc = GotoNextToken(LastGameEndLoc);
+ loctype loc = GotoNextToken(LastGameEndLoc);
if (IS_EOF) {
throw NoGameFound();
}
@@ -103,7 +103,7 @@ bool PGN::HasTag(std::string key) {
return (std::find(tags.begin(), tags.end(), key) != tags.end());
}
-ull PGN::ParseComment(ull loc, HalfMove *hm) {
+loctype PGN::ParseComment(loctype loc, HalfMove *hm) {
// Goto next char
loc = GotoNextToken(loc);
EOF_CHECK(loc);
@@ -131,7 +131,7 @@ ull PGN::ParseComment(ull loc, HalfMove *hm) {
return (loc);
}
-ull PGN::ParseHalfMove(ull loc, HalfMove *hm) {
+loctype PGN::ParseHalfMove(loctype loc, HalfMove *hm) {
// Goto next char
loc = GotoNextToken(loc);
EOF_CHECK(loc);
@@ -249,10 +249,10 @@ ull PGN::ParseHalfMove(ull loc, HalfMove *hm) {
return (loc);
}
-ull PGN::ParseNextTag(ull start_loc) {
+loctype PGN::ParseNextTag(loctype start_loc) {
// Parse key
std::string key;
- ull keyloc = start_loc + 1;
+ loctype keyloc = start_loc + 1;
EOF_CHECK(keyloc);
char c = pgn_content[keyloc];
while (!IS_BLANK(c)) {
@@ -264,7 +264,7 @@ ull PGN::ParseNextTag(ull start_loc) {
// Parse value
std::string value;
- ull valueloc = GotoNextToken(keyloc) + 1;
+ loctype valueloc = GotoNextToken(keyloc) + 1;
EOF_CHECK(keyloc);
c = pgn_content[valueloc];
while (c != '"' or IS_EOF) {
@@ -312,7 +312,7 @@ std::string PGN::Dump() {
return (ss.str());
}
-ull PGN::GotoNextToken(ull loc) {
+loctype PGN::GotoNextToken(loctype loc) {
char c = pgn_content[loc];
while (IS_BLANK(c)) {
loc++;
@@ -331,7 +331,7 @@ ull PGN::GotoNextToken(ull loc) {
return (loc);
}
-ull PGN::GotoEOL(ull loc) {
+loctype PGN::GotoEOL(loctype loc) {
char c = pgn_content[loc];
while (true) {
loc++;
diff --git a/src/PGN.hpp b/src/PGN.hpp
index 0e29ae1..15629af 100644
--- a/src/PGN.hpp
+++ b/src/PGN.hpp
@@ -24,7 +24,7 @@ private:
LargeFileStream pgn_content;
/// @brief Contains the location of the end of the last parsed game (1 PGN
/// file may have multiple games)
- ull LastGameEndLoc;
+ loctype LastGameEndLoc;
public:
PGN();
@@ -55,16 +55,16 @@ public:
private:
/// @brief Populate @a tags with by parsing the one starting at location in
/// argument
- ull ParseNextTag(ull);
+ loctype ParseNextTag(loctype);
/// @brief Parse a HalfMove at a specific location into @a pgn_content
- ull ParseHalfMove(ull, HalfMove *);
+ loctype ParseHalfMove(loctype, HalfMove *);
/// @brief Parse a consecutive sequence of comment
- ull ParseComment(ull, HalfMove *);
+ loctype ParseComment(loctype, HalfMove *);
/// @brief Get the next non-blank char location ignoring line comments ('%'
/// and ';')
- ull GotoNextToken(ull);
+ loctype GotoNextToken(loctype);
/// @brief Goto the end of the current line
- ull GotoEOL(ull);
+ loctype GotoEOL(loctype);
};
struct UnexpectedEOF : public std::exception {
@@ -85,7 +85,7 @@ struct NoGameFound : public std::exception {
struct UnexpectedCharacter : public std::exception {
std::string msg;
- UnexpectedCharacter(char actual, char required, ull loc) {
+ UnexpectedCharacter(char actual, char required, loctype loc) {
std::stringstream ss;
ss << "Expected \'" << required << "\' at location " << loc
<< " but read \'" << actual << "\'";
diff --git a/src/Types.hpp b/src/Types.hpp
index 88f17e1..199b0df 100644
--- a/src/Types.hpp
+++ b/src/Types.hpp
@@ -2,4 +2,6 @@
namespace pgnp {
typedef unsigned long long ull;
+typedef unsigned int uint;
+typedef ull loctype; // Choose location pointer type
} \ No newline at end of file