From 949bc4ba27309ab4795659bc9d75e1365ef0fae2 Mon Sep 17 00:00:00 2001 From: jakcron Date: Sun, 15 Apr 2018 14:01:24 +0800 Subject: [PATCH] [fnd] Added read/write methods to IFile that didn't require an offset. --- lib/libfnd/include/fnd/IFile.h | 2 ++ lib/libfnd/include/fnd/SimpleFile.h | 2 ++ lib/libfnd/source/SimpleFile.cpp | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/libfnd/include/fnd/IFile.h b/lib/libfnd/include/fnd/IFile.h index 6a7cc56..3c12bba 100644 --- a/lib/libfnd/include/fnd/IFile.h +++ b/lib/libfnd/include/fnd/IFile.h @@ -8,7 +8,9 @@ namespace fnd public: virtual size_t size() = 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 write(const byte_t* out, size_t len) = 0; virtual void write(const byte_t* out, size_t offset, size_t len) = 0; }; } diff --git a/lib/libfnd/include/fnd/SimpleFile.h b/lib/libfnd/include/fnd/SimpleFile.h index bb25f7d..8499dd9 100644 --- a/lib/libfnd/include/fnd/SimpleFile.h +++ b/lib/libfnd/include/fnd/SimpleFile.h @@ -24,7 +24,9 @@ namespace fnd size_t size(); void seek(size_t offset); size_t pos(); + void read(byte_t* out, 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); private: diff --git a/lib/libfnd/source/SimpleFile.cpp b/lib/libfnd/source/SimpleFile.cpp index bb907d3..b12156a 100644 --- a/lib/libfnd/source/SimpleFile.cpp +++ b/lib/libfnd/source/SimpleFile.cpp @@ -60,16 +60,26 @@ size_t SimpleFile::pos() 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) { 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) { seek(offset); - fwrite(out, len, 1, mFp); + write(out, len); } const char* SimpleFile::getOpenModeStr(OpenMode mode)