102 lines
3.0 KiB
C++
102 lines
3.0 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: IRandomDevice.hpp
|
|
Date: 2021-9-3
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
namespace Aurora::RNG
|
|
{
|
|
static const auto kSizeRNGDevice = 256;
|
|
|
|
struct IRandomDevice
|
|
{
|
|
virtual void Read(Memory::MemoryViewWrite view) = 0;
|
|
|
|
virtual AuString NextString(AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0;
|
|
virtual void NextString(char *pString, AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0;
|
|
virtual AuUInt8 NextByte() = 0;
|
|
virtual bool NextBoolean() = 0;
|
|
virtual AuUInt32 NextU32() = 0;
|
|
virtual AuUInt32 NextU32(AuUInt32 uMin, AuUInt32 uMax) = 0;
|
|
virtual AuUInt64 NextU64() = 0;
|
|
virtual AuInt32 NextInt(AuInt32 iMin, AuInt32 iMax) = 0;
|
|
virtual double NextDecimal() = 0;
|
|
virtual double NextNumber(double dMin, double dMax) = 0;
|
|
virtual AuUInt32 NextIndex(AuUInt32 uCount /* = max + 1*/) = 0;
|
|
|
|
virtual Memory::MemoryViewRead ToSeed() = 0;
|
|
|
|
template<typename T, int N>
|
|
inline void NextFillArray(T(&array)[N])
|
|
{
|
|
Read(Memory::MemoryViewWrite(array));
|
|
}
|
|
|
|
template<typename T>
|
|
inline void NextFillArray(T *pArray, AuUInt32 uCount)
|
|
{
|
|
Read(Memory::MemoryViewWrite(pArray, uCount * sizeof(T)));
|
|
}
|
|
|
|
template<typename T>
|
|
void NextFillRange(T &container)
|
|
{
|
|
NextFillArray(container.begin(), container.end() - container.begin());
|
|
}
|
|
|
|
inline void NextFillBuffer(Memory::ByteBuffer &buffer)
|
|
{
|
|
auto view = buffer.GetNextLinearWrite();
|
|
NextFillRange(view);
|
|
buffer.writePtr += view.length;
|
|
}
|
|
|
|
/**
|
|
* @brief
|
|
* @deprecated
|
|
*/
|
|
inline void NextFillRange(Memory::ByteBuffer &buffer)
|
|
{
|
|
NextFillBuffer(buffer);
|
|
}
|
|
|
|
template<typename T>
|
|
inline T NextFillTmpl()
|
|
{
|
|
T ret {};
|
|
Read(Memory::MemoryViewWrite(&ret, sizeof(T)));
|
|
return ret;
|
|
}
|
|
|
|
template<typename T>
|
|
inline T &NextIterator(T &begin, T &end)
|
|
{
|
|
return begin + NextIndex(AuUInt(end - begin));
|
|
}
|
|
|
|
template<typename T>
|
|
inline T &NextArray(T *pItems, AuUInt32 uCount)
|
|
{
|
|
return pItems[NextIndex(uCount)];
|
|
}
|
|
|
|
template<typename T>
|
|
inline T &NextVector(AuList<T> &items)
|
|
{
|
|
return NextArray(items.data(), items.size());
|
|
}
|
|
|
|
template<typename T>
|
|
inline T &NextRange(T &items)
|
|
{
|
|
return NextIterator(items.begin(), items.end());
|
|
}
|
|
};
|
|
|
|
AUKN_SHARED_SOO2(Random, IRandomDevice, kSizeRNGDevice,
|
|
((const RandomDef &, def)),
|
|
const RandomDef &def);
|
|
} |