First commit.
This commit is contained in:
64
src/PtrData.cpp
Normal file
64
src/PtrData.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user