Merge branch 'remove-lowlevelfile' into 'master'

Remove obsolete LowLevelFile

See merge request OpenMW/openmw!2156
LTO-timing^2
psi29a 2 years ago
commit 5078b6822a

@ -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

@ -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<std::size_t>::max() ? length : mFile.size () - start;
mFile = File::open(fname.c_str());
mSize = length != std::numeric_limits<std::size_t>::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<std::size_t>(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);

@ -1,7 +1,7 @@
#ifndef OPENMW_CONSTRAINEDFILESTREAMBUF_H
#define OPENMW_CONSTRAINEDFILESTREAMBUF_H
#include "lowlevelfile.hpp"
#include <components/platform/file.hpp>
#include <streambuf>
@ -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 };
};
}

@ -1,53 +0,0 @@
#include "lowlevelfile.hpp"
#include <stdexcept>
#include <sstream>
#include <cassert>
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);
}

@ -1,28 +0,0 @@
#ifndef COMPONENTS_FILES_LOWLEVELFILE_HPP
#define COMPONENTS_FILES_LOWLEVELFILE_HPP
#include <cstdlib>
#include <memory>
#include <components/platform/file.hpp>
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
Loading…
Cancel
Save