49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: FileArbitraryReader.hpp
|
|
Date: 2021-6-10
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
namespace Aurora::IO::FS
|
|
{
|
|
class FileArbitraryReader : public IArbitraryStreamer
|
|
{
|
|
public:
|
|
AU_NO_COPY_NO_MOVE(FileArbitraryReader)
|
|
|
|
FileArbitraryReader() {}
|
|
~FileArbitraryReader() {}
|
|
|
|
template<typename... T>
|
|
bool OpenFile(T... args)
|
|
{
|
|
stream_ = OpenReadUnique(args...);
|
|
return stream_ != nullptr;
|
|
}
|
|
|
|
virtual EStreamError Open() override
|
|
{
|
|
return stream_ ? EStreamError::eErrorNone : EStreamError::eErrorStreamInterrupted;
|
|
}
|
|
|
|
virtual EStreamError ArbitraryRead(AuUInt32 offset, const Memory::MemoryViewStreamWrite ¶mters) override
|
|
{
|
|
if (!stream_) return EStreamError::eErrorStreamNotOpen;
|
|
if (!stream_->SetOffset(offset)) return EStreamError::eErrorEndOfStream;
|
|
if (!stream_->Read(paramters)) return EStreamError::eErrorStreamInterrupted;
|
|
if (paramters.outVariable== 0) return EStreamError::eErrorEndOfStream;
|
|
return EStreamError::eErrorNone;
|
|
}
|
|
|
|
virtual void Close() override
|
|
{
|
|
stream_.reset();
|
|
}
|
|
|
|
private:
|
|
OpenReadUnique_t stream_{};
|
|
};
|
|
} |