38 void Reallocate(
TINT a_iNewSize,
TINT a_iElementSize );
39 void Grow(
TINT a_iNumElements,
TINT a_iElementSize );
60 : m_iIndex( 0 ), m_pVector(
TNULL ) {}
62 : m_iIndex( 0 ), m_pVector( a_pVector ) {}
64 : m_iIndex( 0 ), m_pVector( &a_rVector ) {}
66 : m_iIndex( a_iIndex ), m_pVector( a_pVector ) {}
68 : m_iIndex( a_rOther.m_iIndex ), m_pVector( a_rOther.m_pVector ) {}
77 return m_pVector && *
this != m_pVector->End();
84 return &m_pVector->At( m_iIndex );
87 const T*
Get() const noexcept
91 return &m_pVector->At( m_iIndex );
98 return m_pVector->At( m_iIndex );
105 return m_pVector->At( m_iIndex );
127 operator const T*()
const
154 return a_rOther.m_pVector == m_pVector && a_rOther.m_iIndex == m_iIndex;
159 return a_rOther.m_pVector == m_pVector && a_rOther.m_iIndex > m_iIndex;
164 return a_rOther.m_pVector == m_pVector && a_rOther.m_iIndex >= m_iIndex;
169 return a_rOther.m_pVector == m_pVector && a_rOther.m_iIndex < m_iIndex;
174 return a_rOther.m_pVector == m_pVector && a_rOther.m_iIndex <= m_iIndex;
179 m_iIndex = a_rOther.m_iIndex;
180 m_pVector = a_rOther.m_pVector;
212 return Iterator( m_iIndex + a_iValue, m_pVector );
217 return Iterator( m_iIndex - a_iValue, m_pVector );
241 InsertGap( a_itInsertBefore.
Index(), 1,
sizeof( T ) );
249 InsertGap( a_itInsertAfter.
Index() + 1, 1,
sizeof( T ) );
283 template <
class... Args>
286 Grow( 1,
sizeof( T ) );
292 Grow( 1,
sizeof( T ) );
298 Grow( 1,
sizeof( T ) );
310 for (
auto it =
Begin(); it !=
End(); it++ )
312 if ( it.Value() == a_rcValue )
325 AtUnsafe( uiItemIndex ).~T();
327 if ( uiItemIndex + 1 <
Size() )
329 for (
TINT i = uiItemIndex + 1; i <
Size(); i++ )
331 TConstruct<T>( &AtUnsafe( i - 1 ), std::move( AtUnsafe( i ) ) );
342 auto it =
Find( a_rcItem );
354 AtUnsafe( uiItemIndex ) =
Back().
Value();
361 auto it =
Find( a_rcItem );
412 for (
TINT i = iOldNumElements; i < a_iNewSize; i++ )
413 new ( &AtUnsafe( i ) ) T( a_rcValue );
440 return At( a_iIndex );
445 return At( a_iIndex );
474 TINT iNumElementsBeforeGap = a_iGapAt;
482 if ( iNumElementsBeforeGap > 0 )
486 if ( iNumElementsAfterGap > 0 )
494 for (
TINT i = 0; i < iNumElementsBeforeGap; i++ )
TFORCEINLINE T * TConstruct(T *a_pMemory, Args &&... args)
Constructs an object in place.
#define TREINTERPRETCAST(TYPE, VALUE)
#define TOSHI_NAMESPACE_START
#define TOSHI_NAMESPACE_END
TFORCEINLINE T2Allocator * GetGlobalAllocator()
TFORCEINLINE const T & Max(const T &a, const T &b)
virtual void * Malloc(size_t size, size_t alignment)=0
static void * MemMove(void *dst, const void *src, TSIZE size)
static void * MemCopy(void *dst, const void *src, TSIZE size)
void Grow(TINT a_iNumElements, TINT a_iElementSize)
T2GenericDynamicVector(T2Allocator *a_pAllocator, TINT a_iInitialSize, TINT a_iGrowSize, TINT a_iElementSize)
T2Allocator * m_pAllocator
T2GenericDynamicVector(void *a_poElements, TINT a_iInitialSize, TINT a_iNumElements)
void Reallocate(TINT a_iNewSize, TINT a_iElementSize)
T2DynamicVector(T *a_poElements, TINT a_iInitialSize, TINT a_iNumElements)
const T & At(TINT a_iIndex) const
const T & operator[](TINT a_iIndex) const
void Erase(const Iterator &a_rIterator)
void FindAndErase(const T &a_rcItem)
Iterator Find(const T &a_rcValue)
void SetSize(TINT a_iNewSize)
void SetSize(TINT a_iNewSize, const T &a_rcValue)
void FindAndEraseFast(const T &a_rcItem)
Iterator InsertAfter(Iterator a_itInsertAfter, const T &a_rcItem=T())
T & operator[](TINT a_iIndex)
T2DynamicVector(T2Allocator *a_pAllocator=GetGlobalAllocator(), TINT a_iInitialSize=0, TINT a_iGrowSize=-1)
T * EmplaceBack(Args &&... args)
Iterator MakeIterator(TINT a_iIndex)
void PushBack(const T &item=T())
Iterator InsertBefore(Iterator a_itInsertBefore, const T &a_rcItem=T())
void EraseFast(const Iterator &a_rIterator)
void Reserve(TINT a_iSize)
constexpr Iterator & operator=(const Iterator &a_rOther) noexcept
Iterator operator++(TINT)
constexpr Iterator(T2DynamicVector *a_pVector)
const T & operator*() const noexcept
TBOOL operator<=(const Iterator &a_rOther) const noexcept
Iterator operator--(TINT)
const T * Get() const noexcept
constexpr Iterator(TINT a_iIndex, T2DynamicVector *a_pVector)
constexpr Iterator(const Iterator &a_rOther)
TBOOL operator>=(const Iterator &a_rOther) const noexcept
const T * operator->() const
Iterator operator-(TINT a_iValue) const
constexpr TINT Index() const
constexpr Iterator(T2DynamicVector &a_rVector)
TBOOL operator<(const Iterator &a_rOther) const noexcept
TBOOL operator>(const Iterator &a_rOther) const noexcept
Iterator operator+(TINT a_iValue) const
TBOOL operator==(const Iterator &a_rOther) const noexcept