[+] New stream adapters

[+] IRandomDevice::ToStreamReader
[+] AuIO::Adapters::NewRandomAdapter
[+] AuIO::Adapters::NewNOPsReadAdapter
[+] AuIO::Adapters::NewNOPsSeekingAdapter
[+] AuIO::Adapters::NewNOPsWriteAdapter
[+] AuIO::Adapters::NewZerosReadAdapter
[+] AuIO::Adapters::NewZerosSeekingAdapter
This commit is contained in:
Reece Wilson 2024-01-03 23:52:57 +00:00
parent aa811f93aa
commit 72a3513a04
13 changed files with 368 additions and 3 deletions

View File

@ -0,0 +1,15 @@
/***
Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IOAdapterNOPs.hpp
Date: 2024-1-3
Author: Reece
***/
#pragma once
namespace Aurora::IO::Adapters
{
AUKN_SYM AuSPtr<IStreamReader> NewNOPsReadAdapter();
AUKN_SYM AuSPtr<ISeekingReader> NewNOPsSeekingAdapter();
AUKN_SYM AuSPtr<IStreamWriter> NewNOPsWriteAdapter();
}

View File

@ -0,0 +1,18 @@
/***
Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IOAdapterRandom.hpp
Date: 2024-1-3
Author: Reece
***/
#pragma once
namespace Aurora::RNG
{
struct IRandomDevice;
}
namespace Aurora::IO::Adapters
{
AUKN_SYM AuSPtr<IStreamReader> NewRandomAdapter(const AuSPtr<RNG::IRandomDevice> &pRandomDevice);
}

View File

@ -0,0 +1,14 @@
/***
Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IOAdapterZeros.hpp
Date: 2024-1-3
Author: Reece
***/
#pragma once
namespace Aurora::IO::Adapters
{
AUKN_SYM AuSPtr<IStreamReader> NewZerosReadAdapter();
AUKN_SYM AuSPtr<ISeekingReader> NewZerosSeekingAdapter();
}

View File

@ -51,6 +51,9 @@
#include "Adapters/IOAdapterCompression.hpp"
#include "Adapters/IOAdapterSeeking.hpp"
#include "Adapters/IOAdapterMemoryView.hpp"
#include "Adapters/IOAdapterRandom.hpp"
#include "Adapters/IOAdapterNOPs.hpp"
#include "Adapters/IOAdapterZeros.hpp"
#include "IIOWaitableTickLimiter.hpp"
#include "IIOWaitableIOTimer.hpp"

View File

@ -36,6 +36,7 @@ namespace Aurora::RNG
virtual AuList<double> NextArrayDecimals(AuUInt32 uCount) = 0;
virtual AuList<uuids::uuid> NextArrayUUIDs(AuUInt32 uCount) = 0;
virtual IO::IStreamReader *ToStreamReader() = 0;
virtual Memory::MemoryViewRead ToSeed() = 0;
template<typename T, int N>

View File

@ -0,0 +1,97 @@
/***
Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuIOAdapterNOPs.cpp
Date: 2024-1-3
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuIOAdapterNOPs.hpp"
namespace Aurora::IO::Adapters
{
EStreamError NOPsStreamReader::IsOpen()
{
return EStreamError::eErrorNone;
}
EStreamError NOPsStreamReader::Read(const Memory::MemoryViewStreamWrite &parameters)
{
parameters.outVariable = 0;
if (!parameters)
{
return EStreamError::eErrorOutOfBounds;
}
return EStreamError::eErrorNone;
}
void NOPsStreamReader::Close()
{
}
EStreamError NOPsStreamSeekingReader::IsOpen()
{
return EStreamError::eErrorNone;
}
EStreamError NOPsStreamSeekingReader::ArbitraryRead(AuUInt uOffset, const Memory::MemoryViewStreamWrite &parameters)
{
parameters.outVariable = 0;
if (!parameters)
{
return EStreamError::eErrorOutOfBounds;
}
return EStreamError::eErrorNone;
}
void NOPsStreamSeekingReader::Close()
{
}
EStreamError NOPsStreamWriter::IsOpen()
{
return EStreamError::eErrorNone;
}
EStreamError NOPsStreamWriter::Write(const Memory::MemoryViewStreamRead &parameters)
{
if (!parameters)
{
return EStreamError::eErrorOutOfBounds;
}
parameters.outVariable = parameters.length;
return EStreamError::eErrorNone;
}
void NOPsStreamWriter::Close()
{
}
void NOPsStreamWriter::Flush()
{
}
AUKN_SYM AuSPtr<IStreamReader> NewNOPsReadAdapter()
{
SysCheckRetExpNotNullMemory(AuMakeShared<NOPsStreamReader>(), {});
}
AUKN_SYM AuSPtr<ISeekingReader> NewNOPsSeekingAdapter()
{
SysCheckRetExpNotNullMemory(AuMakeShared<NOPsStreamSeekingReader>(), {});
}
AUKN_SYM AuSPtr<IStreamWriter> NewNOPsWriteAdapter()
{
SysCheckRetExpNotNullMemory(AuMakeShared<NOPsStreamWriter>(), {});
}
}

View File

@ -0,0 +1,33 @@
/***
Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuIOAdapterNOPs.hpp
Date: 2024-1-3
Author: Reece
***/
#pragma once
namespace Aurora::IO::Adapters
{
struct NOPsStreamReader : IStreamReader
{
EStreamError IsOpen() override;
EStreamError Read(const Memory::MemoryViewStreamWrite &parameters) override;
void Close() override;
};
struct NOPsStreamSeekingReader : ISeekingReader
{
EStreamError IsOpen() override;
EStreamError ArbitraryRead(AuUInt uOffset, const Memory::MemoryViewStreamWrite &parameters) override;
void Close() override;
};
struct NOPsStreamWriter : IStreamWriter
{
EStreamError IsOpen() override;
EStreamError Write(const Memory::MemoryViewStreamRead &parameters) override;
void Close() override;
void Flush() override;
};
}

View File

@ -0,0 +1,57 @@
/***
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), {});
}
}

View File

@ -0,0 +1,23 @@
/***
Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuIOAdapterRandom.hpp
Date: 2024-1-3
Author: Reece
***/
#pragma once
namespace Aurora::IO::Adapters
{
struct RandomStreamReader : IStreamReader
{
RandomStreamReader(AuSPtr<RNG::IRandomDevice> pRandomDevice);
EStreamError IsOpen() override;
EStreamError Read(const Memory::MemoryViewStreamWrite &parameters) override;
void Close() override;
private:
AuSPtr<RNG::IRandomDevice> pRandomDevice;
};
}

View File

@ -0,0 +1,68 @@
/***
Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuIOAdapterZeros.cpp
Date: 2024-1-3
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuIOAdapterZeros.hpp"
namespace Aurora::IO::Adapters
{
EStreamError ZerosStreamReader::IsOpen()
{
return EStreamError::eErrorNone;
}
EStreamError ZerosStreamReader::Read(const Memory::MemoryViewStreamWrite &parameters)
{
if (!parameters)
{
parameters.outVariable = 0;
return EStreamError::eErrorOutOfBounds;
}
AuMemset(parameters.ptr, 0, parameters.length);
parameters.outVariable = parameters.length;
return EStreamError::eErrorNone;
}
void ZerosStreamReader::Close()
{
}
EStreamError ZerosStreamSeekingReader::IsOpen()
{
return EStreamError::eErrorNone;
}
EStreamError ZerosStreamSeekingReader::ArbitraryRead(AuUInt uOffset, const Memory::MemoryViewStreamWrite &parameters)
{
if (!parameters)
{
parameters.outVariable = 0;
return EStreamError::eErrorOutOfBounds;
}
AuMemset(parameters.ptr, 0, parameters.length);
parameters.outVariable = parameters.length;
return EStreamError::eErrorNone;
}
void ZerosStreamSeekingReader::Close()
{
}
AUKN_SYM AuSPtr<IStreamReader> NewZerosReadAdapter()
{
SysCheckRetExpNotNullMemory(AuMakeShared<ZerosStreamReader>(), {});
}
AUKN_SYM AuSPtr<ISeekingReader> NewZerosSeekingAdapter()
{
SysCheckRetExpNotNullMemory(AuMakeShared<ZerosStreamSeekingReader>(), {});
}
}

View File

@ -0,0 +1,25 @@
/***
Copyright (C) 2024 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuIOAdapterZeros.hpp
Date: 2024-1-3
Author: Reece
***/
#pragma once
namespace Aurora::IO::Adapters
{
struct ZerosStreamReader : IStreamReader
{
EStreamError IsOpen() override;
EStreamError Read(const Memory::MemoryViewStreamWrite &parameters) override;
void Close() override;
};
struct ZerosStreamSeekingReader : ISeekingReader
{
EStreamError IsOpen() override;
EStreamError ArbitraryRead(AuUInt uOffset, const Memory::MemoryViewStreamWrite &parameters) override;
void Close() override;
};
}

View File

@ -12,12 +12,14 @@ namespace Aurora::RNG
{
static const double kDblEpsilon = 2.2204460492503131e-16;
RandomDevice::RandomDevice()
RandomDevice::RandomDevice() :
IO::Adapters::RandomStreamReader(AuUnsafeRaiiToShared(this))
{
}
RandomDevice::RandomDevice(const RandomDef &def)
RandomDevice::RandomDevice(const RandomDef &def) :
IO::Adapters::RandomStreamReader(AuUnsafeRaiiToShared(this))
{
this->Init(def);
}
@ -518,6 +520,11 @@ namespace Aurora::RNG
return this->fast_.state;
}
IO::IStreamReader *RandomDevice::ToStreamReader()
{
return this;
}
AUKN_SYM IRandomDevice *RandomNew(const Aurora::RNG::RandomDef &def)
{
auto pDevice = _new RandomDevice();

View File

@ -8,10 +8,13 @@
#pragma once
#include "AuWELL.hpp"
#include <Source/IO/Adapters/AuIOAdapterRandom.hpp>
namespace Aurora::RNG
{
struct RandomDevice : IRandomDevice
struct RandomDevice :
IRandomDevice,
IO::Adapters::RandomStreamReader
{
RandomDevice();
RandomDevice(const RandomDef & def);
@ -39,6 +42,7 @@ namespace Aurora::RNG
double NextNumber(double dMin, double dMax) override;
AuUInt32 NextIndex(AuUInt32 uCount /* = max + 1*/) override;
uuids::uuid NextUUID() override;
IO::IStreamReader *ToStreamReader() override;
AuMemoryViewRead ToSeed() override;
void Init(const RandomDef &def);