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

#include <TArray.h>

Inheritance diagram for TGenericArray< T >:
TArray< T >

Classes

class  Iterator
 

Public Member Functions

 TGenericArray (TINT a_iGrowSize, TINT a_iSize)
 
 ~TGenericArray ()
 
void Resize (TINT a_iNewSize)
 
void Clear ()
 
Iterator Begin ()
 
Iterator Tail ()
 
Iterator End ()
 
TINT Size () const
 
void SetSize (TINT a_iSize)
 
TINT SizeAllocated () const
 
TINT GetGrowSize () const
 
void SetGrowSize (TINT a_iGrowSize)
 
T * Push (const T &element=T())
 
template<class... Args>
T * EmplaceBack (Args &&... args)
 
T & Pop ()
 
T & operator[] (TINT a_iIndex)
 
const T & operator[] (TINT a_iIndex) const
 

Detailed Description

template<class T>
class TGenericArray< T >

Definition at line 12 of file TArray.h.

Constructor & Destructor Documentation

◆ TGenericArray()

template<class T>
TGenericArray< T >::TGenericArray ( TINT a_iGrowSize,
TINT a_iSize )
inline

Definition at line 133 of file TArray.h.

134 {
135 m_iGrowSize = a_iGrowSize;
136 m_iNumAllocElements = a_iSize;
137 m_iNumElements = 0;
138
139 if ( m_iNumAllocElements > 0 )
140 {
141 m_pData = TSTATICCAST( T, TMemalign( m_iNumAllocElements * sizeof( T ), alignof( T ) ) );
142 }
143 else
144 {
145 TASSERT( m_iGrowSize != 0 );
146 m_pData = TNULL;
147 }
148 }
void * TMemalign(TSIZE a_uiAlignment, TSIZE a_uiSize, Toshi::TMemory::MemBlock *a_pMemBlock)
Allocates aligned memory from a specific memory block.
Definition TMemory.cpp:1020
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69

◆ ~TGenericArray()

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

Definition at line 150 of file TArray.h.

151 {
152 if ( m_pData )
153 {
154 TFree( m_pData );
155 }
156 }
void TFree(void *a_pMem)
Frees previously allocated memory.
Definition TMemory.cpp:1054

Member Function Documentation

◆ Begin()

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

Definition at line 198 of file TArray.h.

199 {
200 return Iterator( ( m_iNumElements == 0 ) ? -1 : 0, *this );
201 }

◆ Clear()

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

Definition at line 182 of file TArray.h.

183 {
184 if ( m_iNumAllocElements < 0 )
185 {
186 if ( m_pData )
187 {
188 TFree( m_pData );
189 m_pData = TNULL;
190 }
191
192 m_iNumAllocElements = 0;
193 }
194
195 m_iNumElements = 0;
196 }

◆ EmplaceBack()

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

Definition at line 245 of file TArray.h.

246 {
247 GrowBy( 1 );
248 return TConstruct( &m_pData[ m_iNumElements++ ], std::forward<Args>( args )... );
249 }
TFORCEINLINE T * TConstruct(T *a_pMemory, Args &&... args)
Constructs an object in place.
Definition TMemory.h:431

◆ End()

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

Definition at line 208 of file TArray.h.

209 {
210 return Iterator( -1, *this );
211 }

◆ GetGrowSize()

template<class T>
TINT TGenericArray< T >::GetGrowSize ( ) const
inline

Definition at line 228 of file TArray.h.

229 {
230 return m_iGrowSize;
231 }

◆ operator[]() [1/2]

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

Definition at line 257 of file TArray.h.

258 {
259 TASSERT( a_iIndex >= 0 );
260 TASSERT( a_iIndex < m_iNumElements );
261 return m_pData[ a_iIndex ];
262 }

◆ operator[]() [2/2]

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

Definition at line 264 of file TArray.h.

265 {
266 TASSERT( a_iIndex >= 0 );
267 TASSERT( a_iIndex < m_iNumElements );
268 return m_pData[ a_iIndex ];
269 }

◆ Pop()

template<class T>
T & TGenericArray< T >::Pop ( )
inline

Definition at line 251 of file TArray.h.

252 {
253 TASSERT( m_iNumElements >= 1 );
254 return m_pData[ --m_iNumElements ];
255 }

◆ Push()

template<class T>
T * TGenericArray< T >::Push ( const T & element = T())
inline

Definition at line 238 of file TArray.h.

239 {
240 GrowBy( 1 );
241 return TConstruct( &m_pData[ m_iNumElements++ ], element );
242 }

◆ Resize()

template<class T>
void TGenericArray< T >::Resize ( TINT a_iNewSize)
inline

Definition at line 158 of file TArray.h.

159 {
160 if ( a_iNewSize != 0 )
161 {
162 T* pNewBuffer = TSTATICCAST( T, TMemalign( a_iNewSize * sizeof( T ), alignof( T ) ) );
163 size_t uiCopySize = TMath::Min( m_iNumElements, a_iNewSize );
164
165 TUtil::MemCopy( pNewBuffer, m_pData, sizeof( T ) * uiCopySize );
166
167 m_iNumAllocElements = a_iNewSize;
168 TASSERT( m_iNumElements <= m_iNumAllocElements );
169
170 if ( m_pData ) TFree( m_pData );
171 m_pData = pNewBuffer;
172 }
173 else
174 {
175 if ( m_pData ) TFree( m_pData );
176 m_pData = TNULL;
177 m_iNumAllocElements = 0;
178 m_iNumElements = 0;
179 }
180 }
TFORCEINLINE const T & Min(const T &a, const T &b)
static void * MemCopy(void *dst, const void *src, TSIZE size)
Definition TUtil.h:90

◆ SetGrowSize()

template<class T>
void TGenericArray< T >::SetGrowSize ( TINT a_iGrowSize)
inline

Definition at line 233 of file TArray.h.

234 {
235 m_iGrowSize = a_iGrowSize;
236 }

◆ SetSize()

template<class T>
void TGenericArray< T >::SetSize ( TINT a_iSize)
inline

Definition at line 218 of file TArray.h.

219 {
220 m_iNumElements = a_iSize;
221 }

◆ Size()

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

Definition at line 213 of file TArray.h.

214 {
215 return m_iNumElements;
216 }

◆ SizeAllocated()

template<class T>
TINT TGenericArray< T >::SizeAllocated ( ) const
inline

Definition at line 223 of file TArray.h.

224 {
225 return m_iNumAllocElements;
226 }

◆ Tail()

template<class T>
Iterator TGenericArray< T >::Tail ( )
inline

Definition at line 203 of file TArray.h.

204 {
205 return Iterator( ( m_iNumElements == 0 ) ? -1 : m_iNumElements - 1, *this );
206 }

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