OpenBarnyard
 
Loading...
Searching...
No Matches
T2GenericDynamicVector Class Reference

#include <T2DynamicVector.h>

Inheritance diagram for T2GenericDynamicVector:
T2DynamicVector< T2SharedRenderBuffer::SubBuffer * > T2DynamicVector< TModelCollisionType > T2DynamicVector< TTMDBase::CollisionTypeS1 > T2DynamicVector< T > T2SortedVector< T2SharedRenderBuffer::SubBuffer *, T2DynamicVector< T2SharedRenderBuffer::SubBuffer * >, T2SharedRenderBuffer::SubBufferSort >

Protected Member Functions

 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

T2Allocatorm_pAllocator
 
TINT m_iGrowSize
 
TINT m_iNumElements
 
TINT m_iAllocSize
 
void * m_poElements
 

Detailed Description

Definition at line 17 of file T2DynamicVector.h.

Constructor & Destructor Documentation

◆ T2GenericDynamicVector() [1/2]

T2GenericDynamicVector::T2GenericDynamicVector ( T2Allocator * a_pAllocator,
TINT a_iInitialSize,
TINT a_iGrowSize,
TINT a_iElementSize )
inlineprotected

Definition at line 20 of file T2DynamicVector.h.

21 {
22 m_pAllocator = a_pAllocator;
23 m_iGrowSize = a_iGrowSize;
25 m_iAllocSize = a_iInitialSize;
26 m_poElements = ( a_iInitialSize > 0 ) ? a_pAllocator->Malloc( a_iInitialSize * a_iElementSize ) : TNULL;
27 }
#define TNULL
Definition Typedefs.h:23
virtual void * Malloc(size_t size, size_t alignment)=0

◆ T2GenericDynamicVector() [2/2]

T2GenericDynamicVector::T2GenericDynamicVector ( void * a_poElements,
TINT a_iInitialSize,
TINT a_iNumElements )
inlineprotected

Definition at line 29 of file T2DynamicVector.h.

30 {
32 m_iGrowSize = 0;
33 m_iNumElements = a_iNumElements;
34 m_iAllocSize = a_iInitialSize;
35 m_poElements = a_poElements;
36 }

Member Function Documentation

◆ Grow()

void T2GenericDynamicVector::Grow ( TINT a_iNumElements,
TINT a_iElementSize )
protected

Definition at line 38 of file T2DynamicVector.cpp.

39{
40 TINT newSize = m_iNumElements + a_iNumElements;
41 TINT curSize = m_iAllocSize;
42
43 if ( curSize < newSize )
44 {
45 TASSERT( m_iGrowSize != 0 );
46
47 while ( curSize < newSize )
48 {
49 if ( m_iGrowSize == -1 )
50 {
51 curSize = m_iAllocSize * 2 < 3 ? 2 : m_iAllocSize * 2;
52 }
53 else
54 {
55 curSize += m_iGrowSize;
56 }
57 }
58
59 Reallocate( curSize, a_iElementSize );
60 }
61}
#define TASSERT(X,...)
Definition Defines.h:138
int TINT
Definition Typedefs.h:7
void Reallocate(TINT a_iNewSize, TINT a_iElementSize)

◆ Reallocate()

void T2GenericDynamicVector::Reallocate ( TINT a_iNewSize,
TINT a_iElementSize )
protected

Definition at line 12 of file T2DynamicVector.cpp.

13{
14 if ( a_iNewSize != m_iAllocSize )
15 {
16 TASSERT( m_pAllocator != TNULL, "Cannot reallocate a T2DynamicVector with no allocator specified!" );
17
18 void* elements = TNULL;
19
20 if ( 0 < a_iNewSize )
21 {
22 elements = m_pAllocator->Malloc( a_iNewSize * a_iElementSize );
23 TUtil::MemCopy( elements, m_poElements, m_iNumElements <= a_iNewSize ? m_iNumElements * a_iElementSize : a_iNewSize * a_iElementSize );
24 }
25
26 m_iAllocSize = a_iNewSize;
28
29 if ( m_poElements )
30 {
32 }
33
34 m_poElements = elements;
35 }
36}
TFORCEINLINE const T & Min(const T &a, const T &b)
static void * MemCopy(void *dst, const void *src, TSIZE size)
Definition TUtil.h:90

Member Data Documentation

◆ m_iAllocSize

TINT T2GenericDynamicVector::m_iAllocSize
protected

Definition at line 45 of file T2DynamicVector.h.

◆ m_iGrowSize

TINT T2GenericDynamicVector::m_iGrowSize
protected

Definition at line 43 of file T2DynamicVector.h.

◆ m_iNumElements

TINT T2GenericDynamicVector::m_iNumElements
protected

Definition at line 44 of file T2DynamicVector.h.

◆ m_pAllocator

T2Allocator* T2GenericDynamicVector::m_pAllocator
protected

Definition at line 42 of file T2DynamicVector.h.

◆ m_poElements

void* T2GenericDynamicVector::m_poElements
protected

Definition at line 46 of file T2DynamicVector.h.


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