This commit is contained in:
Arron David Nelson 2025-01-11 14:02:13 -08:00
parent 32f91ead4e
commit 504df18274
2 changed files with 163 additions and 15 deletions

View File

@ -1,24 +1,146 @@
#pragma once
#include "Log.h"
#include "Types.h"
#include "Vector.h"
#include "SPVE.h"
namespace ehs
{
template <typename T>
class SPVE;
template <typename T>
template <typename T, typename N = Size>
class SPV
{
private:
Size size;
Size rawSize;
Size stride;
friend class SPVE<T>;
static Vector<T *> vectors;
static bool HasVector(T *vector)
{
for (Size i = vectors.Size(); i; --i)
{
if (vectors[i] != vector)
continue;
EHS_LOG_SUCCESS();
return true;
}
EHS_LOG_SUCCESS();
return false;
}
static bool AddVector(T *vector)
{
if (HasVector(vector))
{
EHS_LOG_INT(LogType::ERR, 0, "SPV already exists, and is a critical error!");
return false;
}
vectors.PushBack(vector);
EHS_LOG_SUCCESS();
return true;
}
static bool UpdateVector(T *oldVect, T *newVect)
{
for (Size i = vectors.Size(); i; --i)
{
if (vectors[i] != oldVect)
continue;
vectors[i] = newVect;
EHS_LOG_SUCCESS();
return true;
}
EHS_LOG_INT(LogType::ERR, 0, "Attempted to update SPV but doesn't exist and is a critical error!");
return false;
}
static bool RemoveVector(T *vector)
{
for (Size i = 0; i < vectors.Size(); ++i)
{
if (vectors[i] != vector)
continue;
EHS_LOG_SUCCESS();
return true;
}
EHS_LOG_SUCCESS();
return false;
}
N size;
N stride;
N rawSize;
T *data;
public:
SPV();
SPV()
{
}
SPVE<T> operator[](Size index)
SPV(N size)
: size(size), stride(5), rawSize(size + stride), data(new T[rawSize])
{
AddVector(data);
}
SPV(N size, N stride)
: size(size), stride(stride), rawSize(size + stride), data(new T[rawSize])
{
AddVector(data);
}
SPV(SPV &&spv) noexcept
: size(spv.size), stride(spv.stride), rawSize(spv.rawSize), data(spv.data)
{
spv.size = 0;
spv.stride = 0;
spv.rawSize = 0;
spv.data = nullptr;
}
SPV(const SPV &spv)
: size(spv.size), stride(spv.stride), rawSize(spv.rawSize), data(new T[rawSize])
{
for (N i = 0; i < size; ++i)
data[i] = spv.data[i];
AddVector(data);
}
SPV &operator=(SPV &&spv) noexcept
{
if (this == &spv)
return *this;
return *this;
}
SPV &operator=(const SPV &spv)
{
if (this == &spv)
return *this;
return *this;
}
SPVE<T> operator[](N index)
{
return SPVE<T>(data[index]);
}

View File

@ -1,5 +1,7 @@
#pragma once
#include "SPV.h"
namespace ehs
{
template <typename T>
@ -10,16 +12,40 @@ namespace ehs
T *value;
public:
SPVE();
SPVE()
{
}
SPVE(T *value);
SPVE(T *value)
{
}
SPVE(SPVE &&spve) noexcept;
SPVE(SPVE &&spve) noexcept
{
}
SPVE(const SPVE &spve);
SPVE(const SPVE &spve)
{
}
SPVE &operator=(SPVE &&spve) noexcept;
SPVE &operator=(SPVE &&spve) noexcept
{
return *this;
}
SPVE &operator=(const SPVE &spve);
SPVE &operator=(const SPVE &spve)
{
return *this;
}
SPV *GetOwner() const
{
return owner;
}
T *GetValue() const
{
return value;
}
};
}