EHS/src/PtrData.cpp

64 lines
867 B
C++
Raw Normal View History

2024-02-05 22:25:30 -08:00
#include "ehs/PtrData.h"
namespace ehs
{
Vector<PtrData> pointers;
bool HasPtrData(void* data)
{
if (!data)
return false;
for (UInt_64 i = 0; i < pointers.Size(); i++)
if (pointers[i].data == data)
return true;
return false;
}
void AddPtrData(void* data)
{
if (!data)
return;
for (UInt_64 i = 0; i < pointers.Size(); i++)
{
if (pointers[i].data != data)
continue;
pointers[i].references++;
return;
}
pointers.Push({1, data});
}
bool RemovePtrData(void* data)
{
if (!data)
return false;
for (UInt_64 i = 0; i < pointers.Size(); i++)
{
if (pointers[i].data != data)
continue;
if (pointers[i].references == 1)
{
pointers.Swap(i, pointers.End());
pointers.Pop();
return true;
}
else
{
pointers[i].references--;
return false;
}
}
return false;
}
}