ReactOS 0.4.16-dev-92-g0c2cdca
ATL::CSimpleArray< T, TEqual > Class Template Reference

#include <atlsimpcoll.h>

Collaboration diagram for ATL::CSimpleArray< T, TEqual >:

Classes

struct  ConstructImpl
 

Public Types

typedef T _ArrayElementType
 

Public Member Functions

 CSimpleArray ()
 
 CSimpleArray (const CSimpleArray< T, TEqual > &src)
 
 ~CSimpleArray ()
 
BOOL Add (const T &t)
 
int Find (const T &t) const
 
TGetData ()
 
const TGetData () const
 
int GetSize () const
 
BOOL Remove (const T &t)
 
void RemoveAll ()
 
BOOL RemoveAt (int nIndex)
 
BOOL SetAtIndex (int nIndex, const T &t)
 
Toperator[] (int nIndex)
 
const Toperator[] (int nIndex) const
 
CSimpleArray< T, TEqual > & operator= (const CSimpleArray< T, TEqual > &src)
 

Protected Member Functions

void ConstructItemInPlace (int nIndex, const T &src)
 
void DestructItem (int nIndex)
 

Protected Attributes

Tm_pData
 
int m_nCount
 
int m_nCapacity
 

Static Protected Attributes

static const int c_nGrow = 8
 

Detailed Description

template<typename T, typename TEqual = CSimpleArrayEqualHelper<T>>
class ATL::CSimpleArray< T, TEqual >

Definition at line 38 of file atlsimpcoll.h.

Member Typedef Documentation

◆ _ArrayElementType

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
typedef T ATL::CSimpleArray< T, TEqual >::_ArrayElementType

Definition at line 41 of file atlsimpcoll.h.

Constructor & Destructor Documentation

◆ CSimpleArray() [1/2]

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
ATL::CSimpleArray< T, TEqual >::CSimpleArray ( )
inline

Definition at line 43 of file atlsimpcoll.h.

44 {
45 }
#define NULL
Definition: types.h:112

◆ CSimpleArray() [2/2]

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
ATL::CSimpleArray< T, TEqual >::CSimpleArray ( const CSimpleArray< T, TEqual > &  src)
inline

Definition at line 47 of file atlsimpcoll.h.

47 :
49 {
50 *this = src;
51 }
GLenum src
Definition: glext.h:6340

◆ ~CSimpleArray()

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
ATL::CSimpleArray< T, TEqual >::~CSimpleArray ( )
inline

Definition at line 53 of file atlsimpcoll.h.

54 {
55 RemoveAll();
56 }

Member Function Documentation

◆ Add()

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
BOOL ATL::CSimpleArray< T, TEqual >::Add ( const T t)
inline

Definition at line 58 of file atlsimpcoll.h.

59 {
60 // is the capacity enough?
61 if (m_nCapacity < m_nCount + 1)
62 {
63 // allocate extra capacity for optimization
64 const int nNewCapacity = (m_nCount + 1) + c_nGrow;
65 T *pNewData = (T *)realloc(static_cast<void *>(m_pData), nNewCapacity * sizeof(T));
66 if (pNewData == NULL)
67 return FALSE; // failure
68
69 m_pData = pNewData;
70 m_nCapacity = nNewCapacity;
71 }
72
73 // call constructor
75
76 // increment
77 ++m_nCount;
78
79 return TRUE;
80 }
void ConstructItemInPlace(int nIndex, const T &src)
Definition: atlsimpcoll.h:226
static const int c_nGrow
Definition: atlsimpcoll.h:218
#define realloc
Definition: debug_ros.c:6
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLdouble GLdouble t
Definition: gl.h:2047
#define T
Definition: mbstring.h:31

Referenced by CDownloadManager::Add(), CUiWindow< T >::AppendTabOrderWindow(), ATL::CImage::BuildCodecFilterString(), CDownloadManager::Download(), CAutoComplete::ExtractInnerList(), RunOnceExInstance::HandleSubKey(), RunOnceExSection::HandleValue(), CAutoComplete::ReLoadInnerList(), CAvailableApplicationInfo::RetrieveLanguages(), and CIDLDataObj::SetData().

◆ ConstructItemInPlace()

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
void ATL::CSimpleArray< T, TEqual >::ConstructItemInPlace ( int  nIndex,
const T src 
)
inlineprotected

Definition at line 226 of file atlsimpcoll.h.

227 {
228 new(&m_pData[nIndex]) ConstructImpl(src);
229 }

Referenced by ATL::CSimpleArray< T, TEqual >::Add(), and ATL::CSimpleArray< T, TEqual >::operator=().

◆ DestructItem()

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
void ATL::CSimpleArray< T, TEqual >::DestructItem ( int  nIndex)
inlineprotected

◆ Find()

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
int ATL::CSimpleArray< T, TEqual >::Find ( const T t) const
inline

Definition at line 82 of file atlsimpcoll.h.

83 {
84 for (int nIndex = 0; nIndex < m_nCount; ++nIndex)
85 {
86 if (TEqual::IsEqual(m_pData[nIndex], t))
87 {
88 return nIndex; // success
89 }
90 }
91 return -1; // failure
92 }

Referenced by CMainWindow::HandleTabOrder(), CAvailableApplicationInfo::InsertLanguageInfo(), and ATL::CSimpleArray< T, TEqual >::Remove().

◆ GetData() [1/2]

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
T * ATL::CSimpleArray< T, TEqual >::GetData ( )
inline

◆ GetData() [2/2]

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
const T * ATL::CSimpleArray< T, TEqual >::GetData ( ) const
inline

Definition at line 99 of file atlsimpcoll.h.

100 {
101 return m_pData;
102 }

◆ GetSize()

◆ operator=()

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
CSimpleArray< T, TEqual > & ATL::CSimpleArray< T, TEqual >::operator= ( const CSimpleArray< T, TEqual > &  src)
inline

Definition at line 175 of file atlsimpcoll.h.

176 {
177 // don't copy if two objects are same
178 if (this == &src)
179 return *this;
180
181 if (src.GetSize() != GetSize())
182 {
183 RemoveAll();
184
185 int nNewCount = src.GetSize();
186
187 T *pNewData = (T *)realloc(static_cast<void *>(m_pData), nNewCount * sizeof(T));
188 ATLASSERT(pNewData);
189 if (pNewData == NULL)
190 return *this; // failure
191
192 // store new
193 m_pData = pNewData;
194 m_nCount = nNewCount;
195 m_nCapacity = nNewCount;
196 }
197 else
198 {
199 for (int nIndex = 0; nIndex < m_nCount; ++nIndex)
200 {
201 DestructItem(nIndex);
202 }
203 }
204
205 ATLASSERT(GetSize() == src.GetSize());
206 for (int nIndex = 0; nIndex < src.GetSize(); ++nIndex)
207 {
208 ConstructItemInPlace(nIndex, src[nIndex]);
209 }
210
211 return *this;
212 }
#define ATLASSERT(x)
Definition: CComVariant.cpp:10
int GetSize() const
Definition: atlsimpcoll.h:104
void DestructItem(int nIndex)
Definition: atlsimpcoll.h:232

◆ operator[]() [1/2]

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
T & ATL::CSimpleArray< T, TEqual >::operator[] ( int  nIndex)
inline

Definition at line 163 of file atlsimpcoll.h.

164 {
165 ATLASSERT(0 <= nIndex && nIndex < m_nCount);
166 return m_pData[nIndex];
167 }

◆ operator[]() [2/2]

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
const T & ATL::CSimpleArray< T, TEqual >::operator[] ( int  nIndex) const
inline

Definition at line 169 of file atlsimpcoll.h.

170 {
171 ATLASSERT(0 <= nIndex && nIndex < m_nCount);
172 return m_pData[nIndex];
173 }

◆ Remove()

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
BOOL ATL::CSimpleArray< T, TEqual >::Remove ( const T t)
inline

Definition at line 109 of file atlsimpcoll.h.

110 {
111 return RemoveAt(Find(t));
112 }
BOOL RemoveAt(int nIndex)
Definition: atlsimpcoll.h:132
int Find(const T &t) const
Definition: atlsimpcoll.h:82

◆ RemoveAll()

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
void ATL::CSimpleArray< T, TEqual >::RemoveAll ( )
inline

Definition at line 114 of file atlsimpcoll.h.

115 {
116 if (m_pData)
117 {
118 // call destructor
119 const int nCount = m_nCount;
120 for (int nIndex = 0; nIndex < nCount; ++nIndex)
121 {
122 DestructItem(nIndex);
123 }
124
125 free(m_pData);
126 m_pData = NULL;
127 }
128 m_nCount = 0;
129 m_nCapacity = 0;
130 }
#define free
Definition: debug_ros.c:5

Referenced by CDownloadManager::Download(), CDownloadManager::DownloadDlgProc(), ATL::CSimpleArray< T, TEqual >::operator=(), CTrayWindow::RestoreAll(), CTrayWindow::RestoreMinimizedNonTaskWnds(), CIDLDataObj::~CIDLDataObj(), and ATL::CSimpleArray< T, TEqual >::~CSimpleArray().

◆ RemoveAt()

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
BOOL ATL::CSimpleArray< T, TEqual >::RemoveAt ( int  nIndex)
inline

Definition at line 132 of file atlsimpcoll.h.

133 {
134 // boundary check
135 if (nIndex < 0 || m_nCount <= nIndex)
136 return FALSE; // failure
137
138 // call destructor
139 DestructItem(nIndex);
140
141 // move range [nIndex + 1, m_nCount) to nIndex
142 const int nRightCount = m_nCount - (nIndex + 1);
143 const int nRightSize = nRightCount * sizeof(T);
144 memmove(static_cast<void *>(&m_pData[nIndex]), &m_pData[nIndex + 1], nRightSize);
145
146 // decrement
147 --m_nCount;
148
149 return TRUE;
150 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881

Referenced by ATL::CSimpleArray< T, TEqual >::Remove().

◆ SetAtIndex()

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
BOOL ATL::CSimpleArray< T, TEqual >::SetAtIndex ( int  nIndex,
const T t 
)
inline

Definition at line 152 of file atlsimpcoll.h.

153 {
154 // boundary check
155 if (nIndex < 0 || m_nCount <= nIndex)
156 return FALSE; // failure
157
158 // store it
159 m_pData[nIndex] = t;
160 return TRUE;
161 }

Member Data Documentation

◆ c_nGrow

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
const int ATL::CSimpleArray< T, TEqual >::c_nGrow = 8
staticprotected

Definition at line 218 of file atlsimpcoll.h.

Referenced by ATL::CSimpleArray< T, TEqual >::Add().

◆ m_nCapacity

template<typename T , typename TEqual = CSimpleArrayEqualHelper<T>>
int ATL::CSimpleArray< T, TEqual >::m_nCapacity
protected

◆ m_nCount

◆ m_pData


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