From ce556ba0ccd2841836dbdacd4a02db758480c95a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <3397065-ZehMatt@users.noreply.gitlab.com> Date: Mon, 18 Jul 2022 16:38:28 +0300 Subject: [PATCH] Remove obsolete LowLevelFile --- components/CMakeLists.txt | 2 +- components/files/constrainedfilestreambuf.cpp | 20 +++---- components/files/constrainedfilestreambuf.hpp | 6 +-- components/files/lowlevelfile.cpp | 53 ------------------- components/files/lowlevelfile.hpp | 28 ---------- 5 files changed, 15 insertions(+), 94 deletions(-) delete mode 100644 components/files/lowlevelfile.cpp delete mode 100644 components/files/lowlevelfile.hpp diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index e67ae36a32..8a04f91154 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -214,7 +214,7 @@ IF(NOT WIN32 AND NOT APPLE) ENDIF() add_component_dir (files linuxpath androidpath windowspath macospath fixedpath multidircollection collections configurationmanager - lowlevelfile constrainedfilestream memorystream hash configfileparser openfile constrainedfilestreambuf + constrainedfilestream memorystream hash configfileparser openfile constrainedfilestreambuf ) add_component_dir (compiler diff --git a/components/files/constrainedfilestreambuf.cpp b/components/files/constrainedfilestreambuf.cpp index 1263523ebe..5939207193 100644 --- a/components/files/constrainedfilestreambuf.cpp +++ b/components/files/constrainedfilestreambuf.cpp @@ -5,14 +5,16 @@ namespace Files { + namespace File = Platform::File; + ConstrainedFileStreamBuf::ConstrainedFileStreamBuf(const std::string& fname, std::size_t start, std::size_t length) : mOrigin(start) { - mFile.open(fname.c_str()); - mSize = length != std::numeric_limits::max() ? length : mFile.size () - start; + mFile = File::open(fname.c_str()); + mSize = length != std::numeric_limits::max() ? length : File::size(mFile) - start; if (start != 0) - mFile.seek(start); + File::seek(mFile, start); setg(nullptr, nullptr, nullptr); } @@ -21,10 +23,10 @@ namespace Files { if (gptr() == egptr()) { - const std::size_t toRead = std::min((mOrigin + mSize) - (mFile.tell()), sizeof(mBuffer)); + const std::size_t toRead = std::min((mOrigin + mSize) - (File::tell(mFile)), sizeof(mBuffer)); // Read in the next chunk of data, and set the read pointers on success - // Failure will throw exception in LowLevelFile - const std::size_t got = mFile.read(mBuffer, toRead); + // Failure will throw exception. + const std::size_t got = File::read(mFile, mBuffer, toRead); setg(&mBuffer[0], &mBuffer[0], &mBuffer[0] + got); } if (gptr() == egptr()) @@ -46,7 +48,7 @@ namespace Files newPos = offset; break; case std::ios_base::cur: - newPos = (mFile.tell() - mOrigin - (egptr() - gptr())) + offset; + newPos = (File::tell(mFile) - mOrigin - (egptr() - gptr())) + offset; break; case std::ios_base::end: newPos = mSize + offset; @@ -58,7 +60,7 @@ namespace Files if (newPos > mSize) return traits_type::eof(); - mFile.seek(mOrigin + newPos); + File::seek(mFile, mOrigin + newPos); // Clear read pointers so underflow() gets called on the next read attempt. setg(nullptr, nullptr, nullptr); @@ -74,7 +76,7 @@ namespace Files if (static_cast(pos) > mSize) return traits_type::eof(); - mFile.seek(mOrigin + pos); + File::seek(mFile, mOrigin + pos); // Clear read pointers so underflow() gets called on the next read attempt. setg(nullptr, nullptr, nullptr); diff --git a/components/files/constrainedfilestreambuf.hpp b/components/files/constrainedfilestreambuf.hpp index 46be98c905..0808ba6a9c 100644 --- a/components/files/constrainedfilestreambuf.hpp +++ b/components/files/constrainedfilestreambuf.hpp @@ -1,7 +1,7 @@ #ifndef OPENMW_CONSTRAINEDFILESTREAMBUF_H #define OPENMW_CONSTRAINEDFILESTREAMBUF_H -#include "lowlevelfile.hpp" +#include #include @@ -22,8 +22,8 @@ namespace Files private: std::size_t mOrigin; std::size_t mSize; - LowLevelFile mFile; - char mBuffer[8192]{0}; + Platform::File::Handle mFile{ Platform::File::Handle::Invalid }; + char mBuffer[8192]{ 0 }; }; } diff --git a/components/files/lowlevelfile.cpp b/components/files/lowlevelfile.cpp deleted file mode 100644 index de17d67cc2..0000000000 --- a/components/files/lowlevelfile.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "lowlevelfile.hpp" - -#include -#include -#include - -namespace File = Platform::File; - -LowLevelFile::~LowLevelFile() -{ - if (mHandle != File::Handle::Invalid) - File::close(mHandle); -} - -void LowLevelFile::open(char const* filename) -{ - mHandle = File::open(filename); -} - -void LowLevelFile::close() -{ - if (mHandle != File::Handle::Invalid) - File::close(mHandle); - mHandle = File::Handle::Invalid; -} - -size_t LowLevelFile::size() -{ - assert(mHandle != File::Handle::Invalid); - - return File::size(mHandle); -} - -void LowLevelFile::seek(size_t position) -{ - assert(mHandle != File::Handle::Invalid); - - return File::seek(mHandle, position); -} - -size_t LowLevelFile::tell() -{ - assert(mHandle != File::Handle::Invalid); - - return File::tell(mHandle); -} - -size_t LowLevelFile::read(void* data, size_t size) -{ - assert(mHandle != File::Handle::Invalid); - - return File::read(mHandle, data, size); -} diff --git a/components/files/lowlevelfile.hpp b/components/files/lowlevelfile.hpp deleted file mode 100644 index 1bd182d0e4..0000000000 --- a/components/files/lowlevelfile.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef COMPONENTS_FILES_LOWLEVELFILE_HPP -#define COMPONENTS_FILES_LOWLEVELFILE_HPP - -#include -#include - -#include - -class LowLevelFile -{ -public: - ~LowLevelFile(); - - void open(char const* filename); - void close(); - - size_t size(); - - void seek(size_t Position); - size_t tell(); - - size_t read(void* data, size_t size); - -private: - Platform::File::Handle mHandle{ Platform::File::Handle::Invalid }; -}; - -#endif