1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

GetSafeRef

This commit is contained in:
Brian Fiete 2021-05-12 07:08:41 -04:00
parent 6247699298
commit ad7c628715

View file

@ -744,6 +744,14 @@ public:
SetBufferSize(this->mAllocSize + this->mAllocSize / 2 + 1);
new (&this->mVals[this->mSize++]) T(val);
}
T& GetSafeRef(int idx)
{
BF_ASSERT(idx >= 0);
while (idx >= this->mSize)
this->Add(T());
return this->mVals[idx];
}
};
// POD
@ -1055,6 +1063,14 @@ public:
this->mVals[this->mSize++] = val;
}
T& GetSafeRef(int idx)
{
BF_ASSERT(idx >= 0);
while (idx >= this->mSize)
this->Add(T());
return this->mVals[idx];
}
T* GrowUninitialized(int addSize)
{
if (this->mSize + addSize > this->mAllocSize)
@ -1107,6 +1123,46 @@ public:
}
};
template <typename T>
class OwnedArray : public Array<T*>
{
public:
typedef Array<T*> _Base;
~OwnedArray()
{
for (auto item : *this)
delete item;
}
void Clear()
{
for (auto item : *this)
delete item;
_Base::Clear();
}
void ClearWithoutDeleting()
{
_Base::Clear();
}
T* Alloc()
{
T* item = new T();
_Base::push_back(item);
return item;
}
template <typename T2>
T2* Alloc()
{
T2* item = new T2();
_Base::push_back(item);
return item;
}
};
NS_BF_END;
namespace std