AuroraRuntime/Include/Aurora/IO/FS/FileSeekableReader.hpp

65 lines
1.6 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: FileSeekableReader.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::IO::FS
{
struct FileSeekableReader : ISeekingReader
{
AU_NO_COPY_NO_MOVE(FileSeekableReader)
inline FileSeekableReader() {}
inline FileSeekableReader(const AuSPtr<IFileStream> &stream) : stream_(stream) { }
inline ~FileSeekableReader() {}
template<typename... T>
bool OpenFile(T... args)
{
this->stream_ = OpenReadShared(args...);
return bool(this->stream_);
}
virtual EStreamError IsOpen() override
{
return this->stream_ ? EStreamError::eErrorNone : EStreamError::eErrorStreamInterrupted;
}
virtual EStreamError ArbitraryRead(AuUInt offset, const Memory::MemoryViewStreamWrite &paramters) override
{
if (!this->stream_)
{
return EStreamError::eErrorStreamNotOpen;
}
if (!this->stream_->SetOffset(offset))
{
return EStreamError::eErrorEndOfStream;
}
if (!this->stream_->Read(paramters))
{
return EStreamError::eErrorStreamInterrupted;
}
if (paramters.outVariable == 0)
{
return EStreamError::eErrorEndOfStream;
}
return EStreamError::eErrorNone;
}
virtual void Close() override
{
stream_.reset();
}
private:
AuSPtr<IFileStream> stream_{};
};
}