OpenBarnyard
 
Loading...
Searching...
No Matches
T2DynamicVector< T > Class Template Reference

#include <T2DynamicVector.h>

Inheritance diagram for T2DynamicVector< T >:
T2GenericDynamicVector

Classes

class  Iterator
 

Public Member Functions

 T2DynamicVector (T2Allocator *a_pAllocator=GetGlobalAllocator(), TINT a_iInitialSize=0, TINT a_iGrowSize=-1)
 
 T2DynamicVector (T *a_poElements, TINT a_iInitialSize, TINT a_iNumElements)
 
 ~T2DynamicVector ()
 
Iterator InsertBefore (Iterator a_itInsertBefore, const T &a_rcItem=T())
 
Iterator InsertAfter (Iterator a_itInsertAfter, const T &a_rcItem=T())
 
void Clear ()
 
void FreeMemory ()
 
void Reserve (TINT a_iSize)
 
template<class... Args>
T * EmplaceBack (Args &&... args)
 
void PushBack (const T &item=T())
 
void PushBack (T &&item)
 
void PopBack ()
 
Iterator Find (const T &a_rcValue)
 
void Erase (const Iterator &a_rIterator)
 
void FindAndErase (const T &a_rcItem)
 
void EraseFast (const Iterator &a_rIterator)
 
void FindAndEraseFast (const T &a_rcItem)
 
Iterator Front ()
 
Iterator Back ()
 
Iterator Begin ()
 
Iterator End ()
 
Iterator MakeIterator (TINT a_iIndex)
 
TINT Size () const
 
void SetSize (TINT a_iNewSize)
 
void SetSize (TINT a_iNewSize, const T &a_rcValue)
 
TINT Capacity () const
 
TBOOL IsEmpty () const
 
T & At (TINT a_iIndex)
 
const T & At (TINT a_iIndex) const
 
T & operator[] (TINT a_iIndex)
 
const T & operator[] (TINT a_iIndex) const
 

Additional Inherited Members

- Protected Member Functions inherited from T2GenericDynamicVector
 T2GenericDynamicVector (T2Allocator *a_pAllocator, TINT a_iInitialSize, TINT a_iGrowSize, TINT a_iElementSize)
 
 T2GenericDynamicVector (void *a_poElements, TINT a_iInitialSize, TINT a_iNumElements)
 
void Reallocate (TINT a_iNewSize, TINT a_iElementSize)
 
void Grow (TINT a_iNumElements, TINT a_iElementSize)
 
- Protected Attributes inherited from T2GenericDynamicVector
T2Allocatorm_pAllocator
 
TINT m_iGrowSize
 
TINT m_iNumElements
 
TINT m_iAllocSize
 
void * m_poElements
 

Detailed Description

template<class T>
class T2DynamicVector< T >

Definition at line 50 of file T2DynamicVector.h.

Constructor & Destructor Documentation

◆ T2DynamicVector() [1/2]

template<class T>
T2DynamicVector< T >::T2DynamicVector ( T2Allocator * a_pAllocator = GetGlobalAllocator(),
TINT a_iInitialSize = 0,
TINT a_iGrowSize = -1 )
inline

Definition at line 226 of file T2DynamicVector.h.

228 {}
T2GenericDynamicVector(T2Allocator *a_pAllocator, TINT a_iInitialSize, TINT a_iGrowSize, TINT a_iElementSize)

◆ T2DynamicVector() [2/2]

template<class T>
T2DynamicVector< T >::T2DynamicVector ( T * a_poElements,
TINT a_iInitialSize,
TINT a_iNumElements )
inline

◆ ~T2DynamicVector()

template<class T>
T2DynamicVector< T >::~T2DynamicVector ( )
inline

Definition at line 234 of file T2DynamicVector.h.

235 {
236 FreeMemory();
237 }

Member Function Documentation

◆ At() [1/2]

template<class T>
T & T2DynamicVector< T >::At ( TINT a_iIndex)
inline

Definition at line 426 of file T2DynamicVector.h.

427 {
429 return *( TREINTERPRETCAST( T*, m_poElements ) + a_iIndex );
430 }
#define TASSERT(X,...)
Definition Defines.h:138
#define TREINTERPRETCAST(TYPE, VALUE)
Definition Defines.h:68

◆ At() [2/2]

template<class T>
const T & T2DynamicVector< T >::At ( TINT a_iIndex) const
inline

Definition at line 432 of file T2DynamicVector.h.

433 {
435 return *( TREINTERPRETCAST( T*, m_poElements ) + a_iIndex );
436 }

◆ Back()

template<class T>
Iterator T2DynamicVector< T >::Back ( )
inline

Definition at line 373 of file T2DynamicVector.h.

374 {
375 TASSERT( m_iNumElements > 0 );
376 return Iterator( m_iNumElements - 1, this );
377 }

◆ Begin()

template<class T>
Iterator T2DynamicVector< T >::Begin ( )
inline

Definition at line 379 of file T2DynamicVector.h.

380 {
381 return Iterator( 0, this );
382 }

◆ Capacity()

template<class T>
TINT T2DynamicVector< T >::Capacity ( ) const
inline

Definition at line 416 of file T2DynamicVector.h.

417 {
418 return m_iAllocSize;
419 }

◆ Clear()

template<class T>
void T2DynamicVector< T >::Clear ( )
inline

Definition at line 255 of file T2DynamicVector.h.

256 {
257 for ( TINT i = 0; i < m_iNumElements; i++ )
258 {
259 ( (T*)m_poElements + i )->~T();
260 }
261
262 m_iNumElements = 0;
263 }

◆ EmplaceBack()

template<class T>
template<class... Args>
T * T2DynamicVector< T >::EmplaceBack ( Args &&... args)
inline

Definition at line 284 of file T2DynamicVector.h.

285 {
286 Grow( 1, sizeof( T ) );
287 return TConstruct<T>( &AtUnsafe( m_iNumElements++ ), std::forward<Args>( args )... );
288 }
TFORCEINLINE T * TConstruct(T *a_pMemory, Args &&... args)
Constructs an object in place.
Definition TMemory.h:431
void Grow(TINT a_iNumElements, TINT a_iElementSize)

◆ End()

template<class T>
Iterator T2DynamicVector< T >::End ( )
inline

Definition at line 384 of file T2DynamicVector.h.

385 {
386 return Iterator( m_iNumElements, this );
387 }

◆ Erase()

template<class T>
void T2DynamicVector< T >::Erase ( const Iterator & a_rIterator)
inline

Definition at line 320 of file T2DynamicVector.h.

321 {
322 TINT uiItemIndex = a_rIterator.Index();
324
325 AtUnsafe( uiItemIndex ).~T();
326
327 if ( uiItemIndex + 1 < Size() )
328 {
329 for ( TINT i = uiItemIndex + 1; i < Size(); i++ )
330 {
331 TConstruct<T>( &AtUnsafe( i - 1 ), std::move( AtUnsafe( i ) ) );
332 AtUnsafe( i ).~T();
333 }
334 }
335
337 }
TINT Size() const

◆ EraseFast()

template<class T>
void T2DynamicVector< T >::EraseFast ( const Iterator & a_rIterator)
inline

Definition at line 349 of file T2DynamicVector.h.

350 {
351 TINT uiItemIndex = a_rIterator.Index();
353
354 AtUnsafe( uiItemIndex ) = Back().Value();
355 PopBack();
356 }

◆ Find()

template<class T>
Iterator T2DynamicVector< T >::Find ( const T & a_rcValue)
inline

Definition at line 308 of file T2DynamicVector.h.

309 {
310 for ( auto it = Begin(); it != End(); it++ )
311 {
312 if ( it.Value() == a_rcValue )
313 return it;
314 }
315
316 return End();
317 }

◆ FindAndErase()

template<class T>
void T2DynamicVector< T >::FindAndErase ( const T & a_rcItem)
inline

Definition at line 340 of file T2DynamicVector.h.

341 {
342 auto it = Find( a_rcItem );
343
344 if ( it != End() )
345 Erase( it );
346 }
void Erase(const Iterator &a_rIterator)
Iterator Find(const T &a_rcValue)

◆ FindAndEraseFast()

template<class T>
void T2DynamicVector< T >::FindAndEraseFast ( const T & a_rcItem)
inline

Definition at line 359 of file T2DynamicVector.h.

360 {
361 auto it = Find( a_rcItem );
362
363 if ( it != End() )
364 EraseFast( it );
365 }
void EraseFast(const Iterator &a_rIterator)

◆ FreeMemory()

template<class T>
void T2DynamicVector< T >::FreeMemory ( )
inline

Definition at line 265 of file T2DynamicVector.h.

266 {
267 Clear();
268
269 if ( m_pAllocator )
270 Reallocate( 0, sizeof( T ) );
271 else
273 }
void Reallocate(TINT a_iNewSize, TINT a_iElementSize)

◆ Front()

template<class T>
Iterator T2DynamicVector< T >::Front ( )
inline

Definition at line 367 of file T2DynamicVector.h.

368 {
369 TASSERT( m_iNumElements > 0 );
370 return Iterator( 0, this );
371 }

◆ InsertAfter()

template<class T>
Iterator T2DynamicVector< T >::InsertAfter ( Iterator a_itInsertAfter,
const T & a_rcItem = T() )
inline

Definition at line 247 of file T2DynamicVector.h.

248 {
249 InsertGap( a_itInsertAfter.Index() + 1, 1, sizeof( T ) );
250 TConstruct<T>( &AtUnsafe( a_itInsertAfter.Index() + 1 ), a_rcItem );
251
252 return Iterator( a_itInsertAfter.Index() + 1, this );
253 }

◆ InsertBefore()

template<class T>
Iterator T2DynamicVector< T >::InsertBefore ( Iterator a_itInsertBefore,
const T & a_rcItem = T() )
inline

Definition at line 239 of file T2DynamicVector.h.

240 {
241 InsertGap( a_itInsertBefore.Index(), 1, sizeof( T ) );
242 TConstruct<T>( &AtUnsafe( a_itInsertBefore.Index() ), a_rcItem );
243
244 return Iterator( a_itInsertBefore.Index(), this );
245 }

◆ IsEmpty()

template<class T>
TBOOL T2DynamicVector< T >::IsEmpty ( ) const
inline

Definition at line 421 of file T2DynamicVector.h.

422 {
423 return Size() == 0;
424 }

◆ MakeIterator()

template<class T>
Iterator T2DynamicVector< T >::MakeIterator ( TINT a_iIndex)
inline

Definition at line 389 of file T2DynamicVector.h.

390 {
391 return Iterator( a_iIndex, this );
392 }

◆ operator[]() [1/2]

template<class T>
T & T2DynamicVector< T >::operator[] ( TINT a_iIndex)
inline

Definition at line 438 of file T2DynamicVector.h.

439 {
440 return At( a_iIndex );
441 }
T & At(TINT a_iIndex)

◆ operator[]() [2/2]

template<class T>
const T & T2DynamicVector< T >::operator[] ( TINT a_iIndex) const
inline

Definition at line 443 of file T2DynamicVector.h.

444 {
445 return At( a_iIndex );
446 }

◆ PopBack()

template<class T>
void T2DynamicVector< T >::PopBack ( )
inline

Definition at line 302 of file T2DynamicVector.h.

303 {
304 TASSERT( m_iNumElements > 0 );
305 AtUnsafe( --m_iNumElements ).~T();
306 }

◆ PushBack() [1/2]

template<class T>
void T2DynamicVector< T >::PushBack ( const T & item = T())
inline

Definition at line 290 of file T2DynamicVector.h.

291 {
292 Grow( 1, sizeof( T ) );
293 TConstruct<T>( &AtUnsafe( m_iNumElements++ ), item );
294 }

◆ PushBack() [2/2]

template<class T>
void T2DynamicVector< T >::PushBack ( T && item)
inline

Definition at line 296 of file T2DynamicVector.h.

297 {
298 Grow( 1, sizeof( T ) );
299 TConstruct<T>( &AtUnsafe( m_iNumElements++ ), item );
300 }

◆ Reserve()

template<class T>
void T2DynamicVector< T >::Reserve ( TINT a_iSize)
inline

Definition at line 275 of file T2DynamicVector.h.

276 {
277 if ( a_iSize > m_iAllocSize )
278 {
279 Reallocate( a_iSize, sizeof( T ) );
280 }
281 }

◆ SetSize() [1/2]

template<class T>
void T2DynamicVector< T >::SetSize ( TINT a_iNewSize)
inline

Definition at line 399 of file T2DynamicVector.h.

400 {
403 }
void Reserve(TINT a_iSize)

◆ SetSize() [2/2]

template<class T>
void T2DynamicVector< T >::SetSize ( TINT a_iNewSize,
const T & a_rcValue )
inline

Definition at line 405 of file T2DynamicVector.h.

406 {
408
411
412 for ( TINT i = iOldNumElements; i < a_iNewSize; i++ )
413 new ( &AtUnsafe( i ) ) T( a_rcValue );
414 }

◆ Size()

template<class T>
TINT T2DynamicVector< T >::Size ( ) const
inline

Definition at line 394 of file T2DynamicVector.h.

395 {
396 return m_iNumElements;
397 }

The documentation for this class was generated from the following file: