AuroraRuntime/Source/IO/Adapters/AuIOAdapterRandom.cpp

57 lines
1.5 KiB
C++
Raw Normal View History

/***
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), {});
}
}