J Reece Wilson
766be57a46
[+] ProcessSectionViewReserved.Unix.cpp [*] Fix missing ::Flush() member on ViewWriter
82 lines
2.0 KiB
C++
82 lines
2.0 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)
|
|
|
|
inline ViewWriter(const AuSPtr<Memory::MemoryViewWrite> &view) : pView_(view)
|
|
{ }
|
|
|
|
inline ViewWriter()
|
|
{ }
|
|
|
|
inline ~ViewWriter()
|
|
{ }
|
|
|
|
inline virtual EStreamError IsOpen() override
|
|
{
|
|
if (!this->pView_)
|
|
{
|
|
return EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
if (!(*this->pView_.get()))
|
|
{
|
|
return EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
return EStreamError::eErrorNone;
|
|
}
|
|
|
|
inline virtual EStreamError Write(const Memory::MemoryViewStreamRead ¶meters) override
|
|
{
|
|
if (!this->pView_)
|
|
{
|
|
return EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
if (!(*this->pView_.get()))
|
|
{
|
|
return EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
auto uToRead = AuMin(this->pView_->length - this->uOffset_, parameters.length);
|
|
parameters.outVariable = uToRead;
|
|
AuMemcpy(this->pView_->Begin<AuUInt8>() + this->uOffset_, parameters.ptr, uToRead);
|
|
this->uOffset_ += uToRead;
|
|
return parameters.outVariable == 0 ? EStreamError::eErrorEndOfStream : EStreamError::eErrorNone;
|
|
}
|
|
|
|
inline virtual void Close() override
|
|
{
|
|
this->pView_.reset();
|
|
}
|
|
|
|
inline virtual void Flush() override
|
|
{
|
|
|
|
}
|
|
|
|
inline AuUInt &GetOffset()
|
|
{
|
|
return this->uOffset_;
|
|
}
|
|
|
|
inline const AuUInt &GetOffset() const
|
|
{
|
|
return this->uOffset_;
|
|
}
|
|
private:
|
|
AuSPtr<Memory::MemoryViewWrite> pView_;
|
|
AuUInt uOffset_ {};
|
|
};
|
|
} |