AuroraRuntime/Include/Aurora/IO/Buffered/ViewWriter.hpp
Jamie Reece Wilson 38bf52e852 [+] Aurora::IO::FS::IMemoryMappedFile
[+] Aurora::IO::Adapters::NewMemoryViewWriteSeekableAdapter
[*] ViewSeekableReadable -> ViewSeekableReader
[+] Aurora::IO::FS::OpenMap
[+] Aurora::IO::FS::OpenMapFromSharedHandle
2024-03-07 06:49:23 +00:00

88 lines
2.2 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ViewWriter.hpp
Date: 2022-12-11
Author: Reece
***/
#pragma once
namespace Aurora::IO::Buffered
{
struct ViewWriter : IStreamWriter
{
AU_NO_COPY(ViewWriter)
AU_MOVE(ViewWriter)
inline ViewWriter(const AuSPtr<Memory::MemoryViewWrite> &pView) : view_(pView ? *pView.get() : Memory::MemoryViewWrite {}), pHold(pView)
{ }
inline ViewWriter(const Memory::MemoryViewWrite &view, AuSPtr<void> pBlock) : view_(view), pHold(pBlock)
{ }
inline ViewWriter()
{ }
inline ~ViewWriter()
{ }
inline virtual EStreamError IsOpen() override
{
if (!this->view_)
{
return EStreamError::eErrorStreamNotOpen;
}
if (!this->pHold)
{
return EStreamError::eErrorStreamNotOpen;
}
return EStreamError::eErrorNone;
}
inline virtual EStreamError Write(const Memory::MemoryViewStreamRead &parameters) override
{
if (!this->view_)
{
return EStreamError::eErrorStreamNotOpen;
}
if (!this->pHold)
{
return EStreamError::eErrorStreamNotOpen;
}
auto uToRead = AuMin(this->view_.length - this->uOffset_, parameters.length);
parameters.outVariable = uToRead;
AuMemcpy(this->view_.Begin<AuUInt8>() + this->uOffset_, parameters.ptr, uToRead);
this->uOffset_ += uToRead;
return parameters.outVariable == 0 ? EStreamError::eErrorEndOfStream : EStreamError::eErrorNone;
}
inline virtual void Close() override
{
AuResetMember(this->pHold);
AuResetMember(this->view_);
}
inline virtual void Flush() override
{
}
inline AuUInt &GetOffset()
{
return this->uOffset_;
}
inline const AuUInt &GetOffset() const
{
return this->uOffset_;
}
private:
Memory::MemoryViewWrite view_;
AuSPtr<void> pHold;
AuUInt uOffset_ {};
};
}