EHS/src/PtrData.cpp
Karutoh bcd71cf2b5
All checks were successful
Build & Release / Windows-AMD64-Build (push) Successful in 1m8s
Build & Release / Linux-AMD64-Build (push) Successful in 1m30s
Build & Release / Linux-AARCH64-Build (push) Successful in 3m21s
Adjusted workflow.
2024-02-05 22:25:30 -08:00

64 lines
867 B
C++

#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;
}
}