84 lines
1.9 KiB
C++
84 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <Core/Common/NonNullPtr.h>
|
|
#include <Core/Memory/MemoryArena.h>
|
|
#include <vector>
|
|
#include <WinSock2.h>
|
|
|
|
namespace Juliet
|
|
{
|
|
template <typename Type>
|
|
struct VectorArena
|
|
{
|
|
public:
|
|
VectorArena()
|
|
: First(nullptr)
|
|
, Count(0)
|
|
, Stride(sizeof(Type))
|
|
{
|
|
Arena = ArenaAllocate();
|
|
}
|
|
|
|
~VectorArena() { ArenaRelease(Arena); }
|
|
|
|
void PushBack(Type&& value)
|
|
{
|
|
Type* entry = ArenaPushStruct<Type>(Arena);
|
|
*entry = std::move(value);
|
|
|
|
if (Count == 0)
|
|
{
|
|
First = entry;
|
|
}
|
|
Last = entry;
|
|
|
|
++Count;
|
|
}
|
|
|
|
void RemoveAtFast(index_t index)
|
|
{
|
|
Assert(index < Count);
|
|
Assert(Count > 0);
|
|
|
|
Type* elementAdr = First + index;
|
|
|
|
// Swap Last and element
|
|
Swap(Last, elementAdr);
|
|
--Last;
|
|
--Count;
|
|
ArenaPop(Arena, Stride);
|
|
}
|
|
|
|
void Clear()
|
|
{
|
|
ArenaClear(Arena);
|
|
Count = 0;
|
|
}
|
|
|
|
// C++ Accessors for loop supports and Index based access
|
|
Type& operator[](size_t index) { return First[index]; }
|
|
const Type& operator[](size_t index) const { return First[index]; }
|
|
|
|
Type* begin() { return First; }
|
|
Type* end() { return First + Count; }
|
|
|
|
const Type* begin() const { return First; }
|
|
const Type* end() const { return First + Count; }
|
|
|
|
size_t Size() const { return Count; }
|
|
|
|
private:
|
|
Arena* Arena;
|
|
Type* First;
|
|
Type* Last;
|
|
size_t Count;
|
|
size_t Stride;
|
|
};
|
|
|
|
// TODO : Create my own Vector class based on https://github.com/niklas-ourmachinery/bitsquid-foundation/blob/master/collection_types.h
|
|
template <typename T>
|
|
class Vector : public std::vector<T>
|
|
{
|
|
};
|
|
} // namespace Juliet
|