ReactOS  0.4.14-dev-815-ge410a12
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
 

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 161 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 164 of file atlcoll.h.

◆ OUTARGTYPE

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

Definition at line 165 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 261 of file atlcoll.h.

262  : m_pData(NULL)
263  , m_Size(0)
264  , m_AllocatedSize(0)
265  , m_GrowBy(0)
266 {
267 }
size_t m_Size
Definition: atlcoll.h:169
smooth NULL
Definition: ftsmooth.c:416
size_t m_GrowBy
Definition: atlcoll.h:171
size_t m_AllocatedSize
Definition: atlcoll.h:170

◆ ~CAtlArray()

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

Definition at line 270 of file atlcoll.h.

271 {
272  // Destroy all items
273  SetCount(0, -1);
274 }
bool SetCount(size_t nNewSize, int nGrowBy=- 1)
Definition: atlcoll.h:310

Member Function Documentation

◆ Add() [1/2]

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

Definition at line 280 of file atlcoll.h.

281 {
282  if (m_Size >= m_AllocatedSize)
283  {
284  if (!GrowAllocatedData(m_Size + 1))
285  {
287  }
288  }
289 
291  m_Size++;
292 
293  return m_Size - 1;
294 }
size_t m_Size
Definition: atlcoll.h:169
#define new(TYPE, numElems)
Definition: treelist.c:54
#define AtlThrow(x)
Definition: atldef.h:20
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
bool GrowAllocatedData(size_t nNewSize)
Definition: atlcoll.h:195
static const WCHAR E[]
Definition: oid.c:1253
size_t m_AllocatedSize
Definition: atlcoll.h:170

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

◆ Add() [2/2]

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

Definition at line 299 of file atlcoll.h.

300 {
301  if (!SetCount(m_Size + 1))
302  {
304  }
305 
306  return m_Size - 1;
307 }
size_t m_Size
Definition: atlcoll.h:169
bool SetCount(size_t nNewSize, int nGrowBy=- 1)
Definition: atlcoll.h:310
#define AtlThrow(x)
Definition: atldef.h:20
#define E_OUTOFMEMORY
Definition: ddrawi.h:100

◆ CreateItems()

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

Definition at line 177 of file atlcoll.h.

178  {
179  for (size_t n = 0; n < Size; ++n)
180  {
181  ::new (pData + n) E;
182  }
183  }
#define new(TYPE, numElems)
Definition: treelist.c:54
GLdouble n
Definition: glext.h:7729
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
static const WCHAR E[]
Definition: oid.c:1253
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827

◆ DestructItems()

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

Definition at line 187 of file atlcoll.h.

188  {
189  for (size_t n = 0; n < Size; ++n)
190  {
191  pData[n].~E();
192  }
193  }
GLdouble n
Definition: glext.h:7729
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827

◆ GetAt() [1/2]

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

Definition at line 380 of file atlcoll.h.

381 {
382  ATLASSERT(iElement < m_Size);
383 
384  return m_pData[iElement];
385 }
size_t m_Size
Definition: atlcoll.h:169
#define ATLASSERT(x)
Definition: CComVariant.cpp:9

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 388 of file atlcoll.h.

389 {
390  ATLASSERT(iElement < m_Size);
391 
392  return m_pData[iElement];
393 }
size_t m_Size
Definition: atlcoll.h:169
#define ATLASSERT(x)
Definition: CComVariant.cpp:9

◆ GetCount()

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

Definition at line 358 of file atlcoll.h.

359 {
360  return m_Size;
361 }
size_t m_Size
Definition: atlcoll.h:169

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

◆ GrowAllocatedData()

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

Definition at line 195 of file atlcoll.h.

196  {
197  if (m_pData)
198  {
199  size_t addSize = m_GrowBy > 0 ? m_GrowBy : m_AllocatedSize / 2;
200  size_t allocSize = m_AllocatedSize + addSize;
201  if (allocSize < nNewSize)
202  allocSize = nNewSize;
203 
204  E* pData = (E*)malloc(nNewSize * sizeof(E));
205 
206  if (pData == NULL)
207  {
208  return false;
209  }
210 
211  // Copy the objects over (default implementation will just move them without calling anything
212  ETraits::RelocateElements(pData, m_pData, m_Size);
213 
214  free(m_pData);
215  m_pData = pData;
216  m_AllocatedSize = nNewSize;
217  }
218  else
219  {
220  // We need to allocate a new buffer
221  size_t allocSize = m_GrowBy > nNewSize ? m_GrowBy : nNewSize;
222  m_pData = (E*)malloc(allocSize * sizeof(E));
223  if (m_pData == NULL)
224  {
225  return false;
226  }
227  m_AllocatedSize = allocSize;
228  }
229  return true;
230  }
size_t m_Size
Definition: atlcoll.h:169
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:416
size_t m_GrowBy
Definition: atlcoll.h:171
static const WCHAR E[]
Definition: oid.c:1253
size_t m_AllocatedSize
Definition: atlcoll.h:170
#define malloc
Definition: debug_ros.c:4
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827

◆ 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 364 of file atlcoll.h.

365 {
366  ATLASSERT(iElement < m_Size);
367 
368  return m_pData[iElement];
369 }
size_t m_Size
Definition: atlcoll.h:169
#define ATLASSERT(x)
Definition: CComVariant.cpp:9

◆ operator[]() [2/2]

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

Definition at line 372 of file atlcoll.h.

373 {
374  ATLASSERT(iElement < m_Size);
375 
376  return m_pData[iElement];
377 }
size_t m_Size
Definition: atlcoll.h:169
#define ATLASSERT(x)
Definition: CComVariant.cpp:9

◆ SetCount()

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

Definition at line 310 of file atlcoll.h.

311 {
312 
313  if (nGrowBy > -1)
314  {
315  m_GrowBy = (size_t)nGrowBy;
316  }
317 
318  if (nNewSize == m_Size)
319  {
320  // Do nothing
321  }
322  else if (nNewSize == 0)
323  {
324  if (m_pData)
325  {
327  m_pData = NULL;
328  }
330  }
331  else if (nNewSize < m_AllocatedSize)
332  {
333  if (nNewSize > m_Size)
334  {
335  CreateItems(m_pData + m_Size, nNewSize - m_Size);
336  }
337  else
338  {
339  DestructItems(m_pData + nNewSize, m_Size - nNewSize);
340  }
341  m_Size = nNewSize;
342  }
343  else
344  {
345  if (!GrowAllocatedData(nNewSize))
346  {
347  return false;
348  }
349 
350  CreateItems(m_pData + m_Size, nNewSize - m_Size);
351  m_Size = nNewSize;
352  }
353 
354  return true;
355 }
size_t m_Size
Definition: atlcoll.h:169
smooth NULL
Definition: ftsmooth.c:416
size_t m_GrowBy
Definition: atlcoll.h:171
__kernel_size_t size_t
Definition: linux.h:237
void CreateItems(E *pData, size_t Size)
Definition: atlcoll.h:177
void DestructItems(E *pData, size_t Size)
Definition: atlcoll.h:187
bool GrowAllocatedData(size_t nNewSize)
Definition: atlcoll.h:195
size_t m_AllocatedSize
Definition: atlcoll.h:170

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 170 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 171 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 168 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 169 of file atlcoll.h.

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


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