AuroraRuntime/Source/IO/AuByteBufferStreamPair.cpp
Reece 4e6f116925 [*] Refactor
[+] IProcessSectionView::GetStart
[+] IProcessSectionView::GetEnd
2022-12-17 20:14:19 +00:00

84 lines
2.2 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuByteBufferStreamPair.cpp
Date: 2022-6-6
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include <Aurora/IO/IOExperimental.hpp>
#include "AuByteBufferStreamPair.hpp"
namespace Aurora::IO
{
ByteBufferStreamPair::ByteBufferStreamPair(const AuSPtr<Memory::ByteBuffer> &pBuffer) :
pBuffer(pBuffer),
reader(pBuffer),
writer(pBuffer),
seeker(pBuffer)
{
}
AuSPtr<IStreamReader> ByteBufferStreamPair::ToStreamReader()
{
return AuSPtr<IStreamReader>(AuSharedFromThis(), AuStaticCast<IStreamReader>(&this->reader));
}
AuSPtr<ISeekingReader> ByteBufferStreamPair::ToSeekingReader()
{
if (this->pBuffer->flagCircular)
{
SysPushErrorIO("ring buffer must not be seekable");
return {};
}
return AuSPtr<ISeekingReader>(AuSharedFromThis(), AuStaticCast<ISeekingReader>(&this->seeker));
}
AuSPtr<IStreamWriter> ByteBufferStreamPair::ToStreamWriter()
{
return AuSPtr<IStreamWriter>(AuSharedFromThis(), AuStaticCast<IStreamWriter>(&this->writer));
}
AuSPtr<Memory::ByteBuffer> ByteBufferStreamPair::ToByteBuffer()
{
return this->pBuffer;
}
AUKN_SYM AuSPtr<IByteBufferStreamPair> NewByteBufferPair()
{
auto scalable = AuMakeShared<AuByteBuffer>();
if (!scalable)
{
SysPushErrorMem();
return {};
}
return AuMakeShared<ByteBufferStreamPair>(scalable);
}
AUKN_SYM AuSPtr<IByteBufferStreamPair> NewByteBufferPairEx(AuUInt uLength, bool bPermitResize)
{
auto buffer = AuMakeShared<AuByteBuffer>(uLength, false, bPermitResize);
if (!buffer)
{
SysPushErrorMem();
return {};
}
return AuMakeShared<ByteBufferStreamPair>(buffer);
}
AUKN_SYM AuSPtr<IByteBufferStreamPair> NewRingByteBuffer(AuUInt uLength)
{
auto buffer = AuMakeShared<AuByteBuffer>(uLength, false, false);
if (!buffer)
{
SysPushErrorMem();
return {};
}
return AuMakeShared<ByteBufferStreamPair>(buffer);
}
}