[+] 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:
parent
aa811f93aa
commit
72a3513a04
15
Include/Aurora/IO/Adapters/IOAdapterNOPs.hpp
Normal file
15
Include/Aurora/IO/Adapters/IOAdapterNOPs.hpp
Normal 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();
|
||||
}
|
18
Include/Aurora/IO/Adapters/IOAdapterRandom.hpp
Normal file
18
Include/Aurora/IO/Adapters/IOAdapterRandom.hpp
Normal 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);
|
||||
}
|
14
Include/Aurora/IO/Adapters/IOAdapterZeros.hpp
Normal file
14
Include/Aurora/IO/Adapters/IOAdapterZeros.hpp
Normal 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();
|
||||
}
|
@ -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"
|
||||
|
@ -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>
|
||||
|
97
Source/IO/Adapters/AuIOAdapterNOPs.cpp
Normal file
97
Source/IO/Adapters/AuIOAdapterNOPs.cpp
Normal 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 ¶meters)
|
||||
{
|
||||
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 ¶meters)
|
||||
{
|
||||
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 ¶meters)
|
||||
{
|
||||
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>(), {});
|
||||
}
|
||||
}
|
33
Source/IO/Adapters/AuIOAdapterNOPs.hpp
Normal file
33
Source/IO/Adapters/AuIOAdapterNOPs.hpp
Normal 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 ¶meters) override;
|
||||
void Close() override;
|
||||
};
|
||||
|
||||
struct NOPsStreamSeekingReader : ISeekingReader
|
||||
{
|
||||
EStreamError IsOpen() override;
|
||||
EStreamError ArbitraryRead(AuUInt uOffset, const Memory::MemoryViewStreamWrite ¶meters) override;
|
||||
void Close() override;
|
||||
};
|
||||
|
||||
struct NOPsStreamWriter : IStreamWriter
|
||||
{
|
||||
EStreamError IsOpen() override;
|
||||
EStreamError Write(const Memory::MemoryViewStreamRead ¶meters) override;
|
||||
void Close() override;
|
||||
void Flush() override;
|
||||
};
|
||||
}
|
57
Source/IO/Adapters/AuIOAdapterRandom.cpp
Normal file
57
Source/IO/Adapters/AuIOAdapterRandom.cpp
Normal 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 ¶meters)
|
||||
{
|
||||
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), {});
|
||||
}
|
||||
}
|
23
Source/IO/Adapters/AuIOAdapterRandom.hpp
Normal file
23
Source/IO/Adapters/AuIOAdapterRandom.hpp
Normal 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 ¶meters) override;
|
||||
void Close() override;
|
||||
|
||||
private:
|
||||
AuSPtr<RNG::IRandomDevice> pRandomDevice;
|
||||
};
|
||||
}
|
68
Source/IO/Adapters/AuIOAdapterZeros.cpp
Normal file
68
Source/IO/Adapters/AuIOAdapterZeros.cpp
Normal 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 ¶meters)
|
||||
{
|
||||
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 ¶meters)
|
||||
{
|
||||
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>(), {});
|
||||
}
|
||||
}
|
25
Source/IO/Adapters/AuIOAdapterZeros.hpp
Normal file
25
Source/IO/Adapters/AuIOAdapterZeros.hpp
Normal 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 ¶meters) override;
|
||||
void Close() override;
|
||||
};
|
||||
|
||||
struct ZerosStreamSeekingReader : ISeekingReader
|
||||
{
|
||||
EStreamError IsOpen() override;
|
||||
EStreamError ArbitraryRead(AuUInt uOffset, const Memory::MemoryViewStreamWrite ¶meters) override;
|
||||
void Close() override;
|
||||
};
|
||||
}
|
@ -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();
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user