lib/file: change File::eof to a function
This is just way easier to implement and less messy.Soda
parent
8bb633f118
commit
5059bd0193
|
@ -29,7 +29,6 @@ File::File(std::string path, char mode, uint64_t cursorPosition): mode(mode), pa
|
||||||
this->size = ErrorOr<uint64_t>(std::filesystem::file_size(filePath));
|
this->size = ErrorOr<uint64_t>(std::filesystem::file_size(filePath));
|
||||||
this->open();
|
this->open();
|
||||||
this->isOpen = true;
|
this->isOpen = true;
|
||||||
this->eof = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,6 +56,10 @@ void File::close(){
|
||||||
this->isOpen = false;
|
this->isOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool File::eof() {
|
||||||
|
return !this->size.isError && this->cursorPosition >= this->size.value;
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<uint8_t> File::readByte(){
|
ErrorOr<uint8_t> File::readByte(){
|
||||||
uint8_t* nextPointer = new uint8_t;
|
uint8_t* nextPointer = new uint8_t;
|
||||||
uint8_t nextByte;
|
uint8_t nextByte;
|
||||||
|
|
|
@ -39,7 +39,6 @@ class File {
|
||||||
File(std::string path, char mode, uint64_t cursorPosition);
|
File(std::string path, char mode, uint64_t cursorPosition);
|
||||||
public:
|
public:
|
||||||
bool isOpen;
|
bool isOpen;
|
||||||
bool eof;
|
|
||||||
std::string path;
|
std::string path;
|
||||||
uint64_t cursorPosition;
|
uint64_t cursorPosition;
|
||||||
// may be error if not a regular file or size cannot be determined
|
// may be error if not a regular file or size cannot be determined
|
||||||
|
@ -49,6 +48,8 @@ class File {
|
||||||
void open();
|
void open();
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
bool eof();
|
||||||
|
|
||||||
// only applicable to read and edit modes
|
// only applicable to read and edit modes
|
||||||
// moves the cursor to the right of the read section
|
// moves the cursor to the right of the read section
|
||||||
ErrorOr<uint8_t> readByte();
|
ErrorOr<uint8_t> readByte();
|
||||||
|
|
Loading…
Reference in New Issue