149 lines
3.0 KiB
C++
149 lines
3.0 KiB
C++
#pragma once
|
|
|
|
#include "Log.h"
|
|
#include "Types.h"
|
|
#include "Vector.h"
|
|
#include "SPVE.h"
|
|
|
|
namespace ehs
|
|
{
|
|
template <typename T, typename N = Size>
|
|
class SPV
|
|
{
|
|
private:
|
|
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(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]);
|
|
}
|
|
};
|
|
}
|