AuroraRuntime/Source/IO/Adapters/AuIOAdapterRandom.cpp
Jamie Reece Wilson 72a3513a04 [+] New stream adapters
[+] IRandomDevice::ToStreamReader
[+] AuIO::Adapters::NewRandomAdapter
[+] AuIO::Adapters::NewNOPsReadAdapter
[+] AuIO::Adapters::NewNOPsSeekingAdapter
[+] AuIO::Adapters::NewNOPsWriteAdapter
[+] AuIO::Adapters::NewZerosReadAdapter
[+] AuIO::Adapters::NewZerosSeekingAdapter
2024-01-03 23:54:46 +00:00

57 lines
1.5 KiB
C++

/***
Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuIOAdapterRandom.cpp
Date: 2024-1-3
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuIOAdapterRandom.hpp"
namespace Aurora::IO::Adapters
{
RandomStreamReader::RandomStreamReader(AuSPtr<RNG::IRandomDevice> pRandomDevice) :
pRandomDevice(pRandomDevice)
{
}
EStreamError RandomStreamReader::IsOpen()
{
return bool(this->pRandomDevice) ?
EStreamError::eErrorNone :
EStreamError::eErrorStreamNotOpen;
}
EStreamError RandomStreamReader::Read(const Memory::MemoryViewStreamWrite &parameters)
{
parameters.outVariable = 0;
if (!parameters)
{
return EStreamError::eErrorOutOfBounds;
}
if (auto pRandomDevice = this->pRandomDevice)
{
pRandomDevice->Read(parameters);
parameters.outVariable = parameters.length;
return EStreamError::eErrorNone;
}
else
{
return EStreamError::eErrorStreamNotOpen;
}
}
void RandomStreamReader::Close()
{
AuResetMember(this->pRandomDevice);
}
AUKN_SYM AuSPtr<IStreamReader> NewRandomAdapter(const AuSPtr<RNG::IRandomDevice> &pRandomDevice)
{
SysCheckArgNotNull(pRandomDevice, {});
SysCheckRetExpNotNullMemory(AuMakeShared<RandomStreamReader>(pRandomDevice), {});
}
}