AuroraRuntime/Include/Aurora/RNG/IRandomDevice.hpp

98 lines
2.8 KiB
C++
Raw Normal View History

/***
2021-09-06 10:58:08 +00:00
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
{
struct IRandomDevice
2021-09-06 10:58:08 +00:00
{
virtual void Read(Memory::MemoryViewWrite view) = 0;
2021-09-06 10:58:08 +00:00
2022-11-17 07:46:07 +00:00
virtual AuString NextString(AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0;
virtual void NextString(char *pString, AuUInt32 uLength, ERngStringCharacters type = ERngStringCharacters::eAlphaCharacters) = 0;
2021-09-06 10:58:08 +00:00
virtual AuUInt8 NextByte() = 0;
virtual bool NextBoolean() = 0;
virtual AuUInt32 NextU32() = 0;
2022-11-17 07:46:07 +00:00
virtual AuUInt32 NextU32(AuUInt32 uMin, AuUInt32 uMax) = 0;
2021-09-06 10:58:08 +00:00
virtual AuUInt64 NextU64() = 0;
2022-11-17 07:46:07 +00:00
virtual AuInt32 NextInt(AuInt32 uMin, AuInt32 uMax) = 0;
2021-09-06 10:58:08 +00:00
virtual double NextDecimal() = 0;
virtual float NextNumber(float min, float max) = 0;
2022-11-17 07:46:07 +00:00
virtual AuUInt32 NextIndex(AuUInt32 uCount /* = max + 1*/) = 0;
2022-12-28 20:07:41 +00:00
virtual Memory::MemoryViewRead ToSeed() = 0;
2021-09-06 10:58:08 +00:00
template<typename T, int N>
inline void NextFillArray(T(&array)[N])
2021-09-06 10:58:08 +00:00
{
Read(Memory::MemoryViewWrite(array));
2021-09-06 10:58:08 +00:00
}
template<typename T>
inline void NextFillArray(T *pArray, AuUInt32 uCount)
{
Read(Memory::MemoryViewWrite(pArray, uCount * sizeof(T)));
}
2021-09-06 10:58:08 +00:00
template<typename T>
2023-04-19 02:17:45 +00:00
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)
2021-09-06 10:58:08 +00:00
{
NextFillBuffer(buffer);
2021-09-06 10:58:08 +00:00
}
template<typename T>
inline T NextFillTmpl()
2021-09-06 10:58:08 +00:00
{
T ret {};
Read(Memory::MemoryViewWrite(&ret, sizeof(T)));
2021-09-06 10:58:08 +00:00
return ret;
}
template<typename T>
inline T &NextIterator(T &begin, T &end)
{
return begin + NextIndex(AuUInt(end - begin));
}
2021-09-06 10:58:08 +00:00
template<typename T>
inline T &NextArray(T *pItems, AuUInt32 uCount)
2021-09-06 10:58:08 +00:00
{
return pItems[NextIndex(uCount)];
2021-09-06 10:58:08 +00:00
}
template<typename T>
2023-04-19 02:17:45 +00:00
inline T &NextVector(AuList<T> &items)
2021-09-06 10:58:08 +00:00
{
return NextArray(items.data(), items.size());
}
2022-02-20 20:25:39 +00:00
template<typename T>
2023-04-19 02:17:45 +00:00
inline T &NextRange(T &items)
2022-02-20 20:25:39 +00:00
{
return NextIterator(items.begin(), items.end());
2022-02-20 20:25:39 +00:00
}
2021-09-06 10:58:08 +00:00
};
AUKN_SHARED_API(Random, IRandomDevice, const RandomDef &def);
}