ReactOS 0.4.15-dev-7942-gd23573b
ATL::CAtlArray< E, ETraits > Class Template Reference

#include <atlcoll.h>

Public Types

typedef ETraits::INARGTYPE INARGTYPE
 
typedef ETraits::OUTARGTYPE OUTARGTYPE
 

Public Member Functions

 CAtlArray ()
 
 ~CAtlArray ()
 
size_t Add (INARGTYPE element)
 
size_t Add ()
 
bool SetCount (size_t nNewSize, int nGrowBy=- 1)
 
size_t GetCount () const
 
Eoperator[] (size_t ielement)
 
const Eoperator[] (size_t ielement) const
 
EGetAt (size_t iElement)
 
const EGetAt (size_t iElement) const
 
EGetData ()
 
const EGetData () const
 

Private Member Functions

void CreateItems (E *pData, size_t Size)
 
void DestructItems (E *pData, size_t Size)
 
bool GrowAllocatedData (size_t nNewSize)
 
 CAtlArray (_In_ const CAtlArray &)
 
CAtlArrayoperator= (_In_ const CAtlArray &)
 

Private Attributes

Em_pData
 
size_t m_Size
 
size_t m_AllocatedSize
 
size_t m_GrowBy
 

Detailed Description

template<typename E, class ETraits = CElementTraits<E>>
class ATL::CAtlArray< E, ETraits >

Definition at line 172 of file atlcoll.h.

Member Typedef Documentation

◆ INARGTYPE

template<typename E , class ETraits = CElementTraits<E>>
typedef ETraits::INARGTYPE ATL::CAtlArray< E, ETraits >::INARGTYPE

Definition at line 175 of file atlcoll.h.

◆ OUTARGTYPE

template<typename E , class ETraits = CElementTraits<E>>
typedef ETraits::OUTARGTYPE ATL::CAtlArray< E, ETraits >::OUTARGTYPE

Definition at line 176 of file atlcoll.h.

Constructor & Destructor Documentation

◆ CAtlArray() [1/2]

template<typename E , class ETraits = CElementTraits<E>>
ATL::CAtlArray< E, ETraits >::CAtlArray ( _In_ const CAtlArray< E, ETraits > &  )
private

◆ CAtlArray() [2/2]

template<typename E , class ETraits >
ATL::CAtlArray< E, ETraits >::CAtlArray

Definition at line 276 of file atlcoll.h.

277 : m_pData(NULL)
278 , m_Size(0)
279 , m_AllocatedSize(0)
280 , m_GrowBy(0)
281{
282}
size_t m_Size
Definition: atlcoll.h:180
size_t m_AllocatedSize
Definition: atlcoll.h:181
size_t m_GrowBy
Definition: atlcoll.h:182
#define NULL
Definition: types.h:112

◆ ~CAtlArray()

template<typename E , class ETraits >
ATL::CAtlArray< E, ETraits >::~CAtlArray

Definition at line 285 of file atlcoll.h.

286{
287 // Destroy all items
288 SetCount(0, -1);
289}
bool SetCount(size_t nNewSize, int nGrowBy=- 1)
Definition: atlcoll.h:325

Member Function Documentation

◆ Add() [1/2]

template<typename E , class ETraits >
size_t ATL::CAtlArray< E, ETraits >::Add

Definition at line 314 of file atlcoll.h.

315{
316 if (!SetCount(m_Size + 1))
317 {
319 }
320
321 return m_Size - 1;
322}
#define AtlThrow(x)
Definition: atldef.h:20
#define E_OUTOFMEMORY
Definition: ddrawi.h:100

◆ Add() [2/2]

template<typename E , class ETraits >
size_t ATL::CAtlArray< E, ETraits >::Add ( INARGTYPE  element)

Definition at line 295 of file atlcoll.h.

296{
297 if (m_Size >= m_AllocatedSize)
298 {
299 if (!GrowAllocatedData(m_Size + 1))
300 {
302 }
303 }
304
306 m_Size++;
307
308 return m_Size - 1;
309}
bool GrowAllocatedData(size_t nNewSize)
Definition: atlcoll.h:206
static const WCHAR E[]
Definition: oid.c:1253
#define new(TYPE, numElems)
Definition: treelist.c:54

Referenced by CFontExt::Drop(), and START_TEST().

◆ CreateItems()

template<typename E , class ETraits = CElementTraits<E>>
void ATL::CAtlArray< E, ETraits >::CreateItems ( E pData,
size_t  Size 
)
inlineprivate

Definition at line 188 of file atlcoll.h.

189 {
190 for (size_t n = 0; n < Size; ++n)
191 {
192 ::new (pData + n) E;
193 }
194 }
GLdouble n
Definition: glext.h:7729
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

◆ DestructItems()

template<typename E , class ETraits = CElementTraits<E>>
void ATL::CAtlArray< E, ETraits >::DestructItems ( E pData,
size_t  Size 
)
inlineprivate

Definition at line 198 of file atlcoll.h.

199 {
200 for (size_t n = 0; n < Size; ++n)
201 {
202 pData[n].~E();
203 }
204 }

◆ GetAt() [1/2]

template<typename E , class ETraits >
E & ATL::CAtlArray< E, ETraits >::GetAt ( size_t  iElement)

Definition at line 395 of file atlcoll.h.

396{
397 ATLASSERT(iElement < m_Size);
398
399 return m_pData[iElement];
400}
#define ATLASSERT(x)
Definition: CComVariant.cpp:10

Referenced by START_TEST().

◆ GetAt() [2/2]

template<typename E , class ETraits >
const E & ATL::CAtlArray< E, ETraits >::GetAt ( size_t  iElement) const

Definition at line 403 of file atlcoll.h.

404{
405 ATLASSERT(iElement < m_Size);
406
407 return m_pData[iElement];
408}

◆ GetCount()

template<typename E , class ETraits >
size_t ATL::CAtlArray< E, ETraits >::GetCount

Definition at line 373 of file atlcoll.h.

374{
375 return m_Size;
376}

Referenced by CFontExt::Drop(), and START_TEST().

◆ GetData() [1/2]

template<typename E , class ETraits >
E * ATL::CAtlArray< E, ETraits >::GetData

Definition at line 411 of file atlcoll.h.

412{
413 return m_pData;
414}

◆ GetData() [2/2]

template<typename E , class ETraits >
const E * ATL::CAtlArray< E, ETraits >::GetData

Definition at line 417 of file atlcoll.h.

418{
419 return m_pData;
420}

◆ GrowAllocatedData()

template<typename E , class ETraits = CElementTraits<E>>
bool ATL::CAtlArray< E, ETraits >::GrowAllocatedData ( size_t  nNewSize)
inlineprivate

Definition at line 206 of file atlcoll.h.

207 {
208 if (m_pData)
209 {
210 size_t addSize = m_GrowBy > 0 ? m_GrowBy : m_AllocatedSize / 2;
211 size_t allocSize = m_AllocatedSize + addSize;
212 if (allocSize < nNewSize)
213 allocSize = nNewSize;
214
215 E* pData = (E*)malloc(nNewSize * sizeof(E));
216
217 if (pData == NULL)
218 {
219 return false;
220 }
221
222 // Copy the objects over (default implementation will just move them without calling anything
223 ETraits::RelocateElements(pData, m_pData, m_Size);
224
225 free(m_pData);
226 m_pData = pData;
227 m_AllocatedSize = nNewSize;
228 }
229 else
230 {
231 // We need to allocate a new buffer
232 size_t allocSize = m_GrowBy > nNewSize ? m_GrowBy : nNewSize;
233 m_pData = (E*)malloc(allocSize * sizeof(E));
234 if (m_pData == NULL)
235 {
236 return false;
237 }
238 m_AllocatedSize = allocSize;
239 }
240 return true;
241 }
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4

◆ operator=()

template<typename E , class ETraits = CElementTraits<E>>
CAtlArray & ATL::CAtlArray< E, ETraits >::operator= ( _In_ const CAtlArray< E, ETraits > &  )
private

◆ operator[]() [1/2]

template<typename E , class ETraits >
E & ATL::CAtlArray< E, ETraits >::operator[] ( size_t  ielement)

Definition at line 379 of file atlcoll.h.

380{
381 ATLASSERT(iElement < m_Size);
382
383 return m_pData[iElement];
384}

◆ operator[]() [2/2]

template<typename E , class ETraits >
const E & ATL::CAtlArray< E, ETraits >::operator[] ( size_t  ielement) const

Definition at line 387 of file atlcoll.h.

388{
389 ATLASSERT(iElement < m_Size);
390
391 return m_pData[iElement];
392}

◆ SetCount()

template<typename E , class ETraits >
bool ATL::CAtlArray< E, ETraits >::SetCount ( size_t  nNewSize,
int  nGrowBy = - 1 
)

Definition at line 325 of file atlcoll.h.

326{
327
328 if (nGrowBy > -1)
329 {
330 m_GrowBy = (size_t)nGrowBy;
331 }
332
333 if (nNewSize == m_Size)
334 {
335 // Do nothing
336 }
337 else if (nNewSize == 0)
338 {
339 if (m_pData)
340 {
342 m_pData = NULL;
343 }
345 }
346 else if (nNewSize < m_AllocatedSize)
347 {
348 if (nNewSize > m_Size)
349 {
350 CreateItems(m_pData + m_Size, nNewSize - m_Size);
351 }
352 else
353 {
354 DestructItems(m_pData + nNewSize, m_Size - nNewSize);
355 }
356 m_Size = nNewSize;
357 }
358 else
359 {
360 if (!GrowAllocatedData(nNewSize))
361 {
362 return false;
363 }
364
365 CreateItems(m_pData + m_Size, nNewSize - m_Size);
366 m_Size = nNewSize;
367 }
368
369 return true;
370}
void DestructItems(E *pData, size_t Size)
Definition: atlcoll.h:198
void CreateItems(E *pData, size_t Size)
Definition: atlcoll.h:188
__kernel_size_t size_t
Definition: linux.h:237

Referenced by START_TEST().

Member Data Documentation

◆ m_AllocatedSize

template<typename E , class ETraits = CElementTraits<E>>
size_t ATL::CAtlArray< E, ETraits >::m_AllocatedSize
private

Definition at line 181 of file atlcoll.h.

Referenced by ATL::CAtlArray< E, ETraits >::GrowAllocatedData().

◆ m_GrowBy

template<typename E , class ETraits = CElementTraits<E>>
size_t ATL::CAtlArray< E, ETraits >::m_GrowBy
private

Definition at line 182 of file atlcoll.h.

Referenced by ATL::CAtlArray< E, ETraits >::GrowAllocatedData().

◆ m_pData

template<typename E , class ETraits = CElementTraits<E>>
E* ATL::CAtlArray< E, ETraits >::m_pData
private

Definition at line 179 of file atlcoll.h.

Referenced by ATL::CAtlArray< E, ETraits >::GrowAllocatedData().

◆ m_Size

template<typename E , class ETraits = CElementTraits<E>>
size_t ATL::CAtlArray< E, ETraits >::m_Size
private

Definition at line 180 of file atlcoll.h.

Referenced by ATL::CAtlArray< E, ETraits >::GrowAllocatedData().


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