From 5059bd01939fb33f499102536b5b711ddc8f6153 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Wed, 5 Oct 2022 04:01:18 +0200 Subject: [PATCH] lib/file: change File::eof to a function This is just way easier to implement and less messy. --- src/lib/file.cpp | 5 ++++- src/lib/file.hpp | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/file.cpp b/src/lib/file.cpp index 0673acc..0c99d08 100644 --- a/src/lib/file.cpp +++ b/src/lib/file.cpp @@ -29,7 +29,6 @@ File::File(std::string path, char mode, uint64_t cursorPosition): mode(mode), pa this->size = ErrorOr(std::filesystem::file_size(filePath)); this->open(); this->isOpen = true; - this->eof = false; } @@ -57,6 +56,10 @@ void File::close(){ this->isOpen = false; } +bool File::eof() { + return !this->size.isError && this->cursorPosition >= this->size.value; +} + ErrorOr File::readByte(){ uint8_t* nextPointer = new uint8_t; uint8_t nextByte; diff --git a/src/lib/file.hpp b/src/lib/file.hpp index f274d0f..24214af 100644 --- a/src/lib/file.hpp +++ b/src/lib/file.hpp @@ -39,7 +39,6 @@ class File { File(std::string path, char mode, uint64_t cursorPosition); public: bool isOpen; - bool eof; std::string path; uint64_t cursorPosition; // may be error if not a regular file or size cannot be determined @@ -49,6 +48,8 @@ class File { void open(); void close(); + bool eof(); + // only applicable to read and edit modes // moves the cursor to the right of the read section ErrorOr readByte();