[fnd] Added read/write methods to IFile that didn't require an offset.

This commit is contained in:
jakcron 2018-04-15 14:01:24 +08:00
parent 45954d837d
commit 949bc4ba27
3 changed files with 16 additions and 2 deletions

View file

@ -8,7 +8,9 @@ namespace fnd
public: public:
virtual size_t size() = 0; virtual size_t size() = 0;
virtual void seek(size_t offset) = 0; virtual void seek(size_t offset) = 0;
virtual void read(byte_t* out, size_t len) = 0;
virtual void read(byte_t* out, size_t offset, size_t len) = 0; virtual void read(byte_t* out, size_t offset, size_t len) = 0;
virtual void write(const byte_t* out, size_t len) = 0;
virtual void write(const byte_t* out, size_t offset, size_t len) = 0; virtual void write(const byte_t* out, size_t offset, size_t len) = 0;
}; };
} }

View file

@ -24,7 +24,9 @@ namespace fnd
size_t size(); size_t size();
void seek(size_t offset); void seek(size_t offset);
size_t pos(); size_t pos();
void read(byte_t* out, size_t len);
void read(byte_t* out, size_t offset, size_t len); void read(byte_t* out, size_t offset, size_t len);
void write(const byte_t* out, size_t len);
void write(const byte_t* out, size_t offset, size_t len); void write(const byte_t* out, size_t offset, size_t len);
private: private:

View file

@ -60,16 +60,26 @@ size_t SimpleFile::pos()
return ftell(mFp); return ftell(mFp);
} }
void SimpleFile::read(byte_t* out, size_t len)
{
fread(out, len, 1, mFp);
}
void SimpleFile::read(byte_t* out, size_t offset, size_t len) void SimpleFile::read(byte_t* out, size_t offset, size_t len)
{ {
seek(offset); seek(offset);
fread(out, len, 1, mFp); read(out, len);
}
void SimpleFile::write(const byte_t* out, size_t len)
{
fwrite(out, len, 1, mFp);
} }
void SimpleFile::write(const byte_t* out, size_t offset, size_t len) void SimpleFile::write(const byte_t* out, size_t offset, size_t len)
{ {
seek(offset); seek(offset);
fwrite(out, len, 1, mFp); write(out, len);
} }
const char* SimpleFile::getOpenModeStr(OpenMode mode) const char* SimpleFile::getOpenModeStr(OpenMode mode)