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

60 lines
1.5 KiB
C++

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