-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathByteArray.h
More file actions
379 lines (290 loc) · 9.42 KB
/
Copy pathByteArray.h
File metadata and controls
379 lines (290 loc) · 9.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
// ByteArray.h: interface for the CByteArray class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_BYTEARRAY_H__7A0D8168_8418_49F4_8589_A0142C1725CF__INCLUDED_)
#define AFX_BYTEARRAY_H__7A0D8168_8418_49F4_8589_A0142C1725CF__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CByteArray
{
int GetSize() const;
int GetUpperBound() const;
void SetSize(int nNewSize, int nGrowBy = -1);
// Operations
// Clean up
void FreeExtra();
void RemoveAll();
// Accessing elements
BYTE GetAt(int nIndex) const;
void SetAt(int nIndex, BYTE newElement);
BYTE& ElementAt(int nIndex);
// Direct Access to the element data (may return NULL)
const BYTE* GetData() const;
BYTE* GetData();
// Potentially growing the array
void SetAtGrow(int nIndex, BYTE newElement);
int Add(BYTE newElement);
int Append(const CByteArray& src);
int Append(BYTE * newElement,int length);
void Copy(const CByteArray& src);
// overloaded operator helpers
BYTE operator[](int nIndex) const;
BYTE& operator[](int nIndex);
// Operations that move elements around
void InsertAt(int nIndex, BYTE newElement, int nCount = 1);
void RemoveAt(int nIndex, int nCount = 1);
void InsertAt(int nStartIndex, CByteArray* pNewArray);
BYTE * GetWritePtr(int length);
// Implementation
protected:
BYTE* m_pData; // the actual array of data
int m_nSize; // # of elements (upperBound - 1)
int m_nMaxSize; // max allocated
int m_nGrowBy; // grow amount
public:
CByteArray();
~CByteArray();
};
class CWordArray
{
public:
// Construction
CWordArray();
// Attributes
int GetSize() const;
int GetUpperBound() const;
void SetSize(int nNewSize, int nGrowBy = -1);
// Operations
// Clean up
void FreeExtra();
void RemoveAll();
// Accessing elements
WORD GetAt(int nIndex) const;
void SetAt(int nIndex, WORD newElement);
WORD& ElementAt(int nIndex);
// Direct Access to the element data (may return NULL)
const WORD* GetData() const;
WORD* GetData();
// Potentially growing the array
void SetAtGrow(int nIndex, WORD newElement);
int Add(WORD newElement);
int Append(const CWordArray& src);
void Copy(const CWordArray& src);
// overloaded operator helpers
WORD operator[](int nIndex) const;
WORD& operator[](int nIndex);
// Operations that move elements around
void InsertAt(int nIndex, WORD newElement, int nCount = 1);
void RemoveAt(int nIndex, int nCount = 1);
void InsertAt(int nStartIndex, CWordArray* pNewArray);
// Implementation
protected:
WORD* m_pData; // the actual array of data
int m_nSize; // # of elements (upperBound - 1)
int m_nMaxSize; // max allocated
int m_nGrowBy; // grow amount
public:
~CWordArray();
};
////////////////////////////////////////////////////////////////////////////
class CDWordArray
{
//DECLARE_SERIAL(CDWordArray)
public:
// Construction
CDWordArray();
// Attributes
int GetSize() const;
int GetUpperBound() const;
void SetSize(int nNewSize, int nGrowBy = -1);
// Operations
// Clean up
void FreeExtra();
void RemoveAll();
// Accessing elements
DWORD GetAt(int nIndex) const;
void SetAt(int nIndex, DWORD newElement);
DWORD& ElementAt(int nIndex);
// Direct Access to the element data (may return NULL)
const DWORD* GetData() const;
DWORD* GetData();
// Potentially growing the array
void SetAtGrow(int nIndex, DWORD newElement);
int Add(DWORD newElement);
int Append(const CDWordArray& src);
void Copy(const CDWordArray& src);
// overloaded operator helpers
DWORD operator[](int nIndex) const;
DWORD& operator[](int nIndex);
// Operations that move elements around
void InsertAt(int nIndex, DWORD newElement, int nCount = 1);
void RemoveAt(int nIndex, int nCount = 1);
void InsertAt(int nStartIndex, CDWordArray* pNewArray);
// Implementation
protected:
DWORD* m_pData; // the actual array of data
int m_nSize; // # of elements (upperBound - 1)
int m_nMaxSize; // max allocated
int m_nGrowBy; // grow amount
public:
~CDWordArray();
protected:
// local typedefs for class templates
typedef DWORD BASE_TYPE;
typedef DWORD BASE_ARG_TYPE;
};
class CUIntArray
{
//DECLARE_DYNAMIC(CUIntArray)
public:
// Construction
CUIntArray();
// Attributes
int GetSize() const;
int GetUpperBound() const;
void SetSize(int nNewSize, int nGrowBy = -1);
// Operations
// Clean up
void FreeExtra();
void RemoveAll();
// Accessing elements
UINT GetAt(int nIndex) const;
void SetAt(int nIndex, UINT newElement);
UINT& ElementAt(int nIndex);
// Direct Access to the element data (may return NULL)
const UINT* GetData() const;
UINT* GetData();
// Potentially growing the array
void SetAtGrow(int nIndex, UINT newElement);
int Add(UINT newElement);
int Append(const CUIntArray& src);
void Copy(const CUIntArray& src);
// overloaded operator helpers
UINT operator[](int nIndex) const;
UINT& operator[](int nIndex);
// Operations that move elements around
void InsertAt(int nIndex, UINT newElement, int nCount = 1);
void RemoveAt(int nIndex, int nCount = 1);
void InsertAt(int nStartIndex, CUIntArray* pNewArray);
// Implementation
protected:
UINT* m_pData; // the actual array of data
int m_nSize; // # of elements (upperBound - 1)
int m_nMaxSize; // max allocated
int m_nGrowBy; // grow amount
public:
~CUIntArray();
};
inline int CByteArray::GetSize() const
{ return m_nSize; }
inline int CByteArray::GetUpperBound() const
{ return m_nSize-1; }
inline void CByteArray::RemoveAll()
{ SetSize(0); }
inline BYTE CByteArray::GetAt(int nIndex) const
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
return m_pData[nIndex]; }
inline void CByteArray::SetAt(int nIndex, BYTE newElement)
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
m_pData[nIndex] = newElement; }
inline BYTE& CByteArray::ElementAt(int nIndex)
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
return m_pData[nIndex]; }
inline const BYTE* CByteArray::GetData() const
{ return (const BYTE*)m_pData; }
inline BYTE* CByteArray::GetData()
{ return (BYTE*)m_pData; }
inline int CByteArray::Add(BYTE newElement)
{ int nIndex = m_nSize;
SetAtGrow(nIndex, newElement);
return nIndex; }
inline BYTE CByteArray::operator[](int nIndex) const
{ return GetAt(nIndex); }
inline BYTE& CByteArray::operator[](int nIndex)
{ return ElementAt(nIndex); }
////////////////////////////////////////////////////////////////////////////
inline int CWordArray::GetSize() const
{ return m_nSize; }
inline int CWordArray::GetUpperBound() const
{ return m_nSize-1; }
inline void CWordArray::RemoveAll()
{ SetSize(0); }
inline WORD CWordArray::GetAt(int nIndex) const
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
return m_pData[nIndex]; }
inline void CWordArray::SetAt(int nIndex, WORD newElement)
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
m_pData[nIndex] = newElement; }
inline WORD& CWordArray::ElementAt(int nIndex)
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
return m_pData[nIndex]; }
inline const WORD* CWordArray::GetData() const
{ return (const WORD*)m_pData; }
inline WORD* CWordArray::GetData()
{ return (WORD*)m_pData; }
inline int CWordArray::Add(WORD newElement)
{ int nIndex = m_nSize;
SetAtGrow(nIndex, newElement);
return nIndex; }
inline WORD CWordArray::operator[](int nIndex) const
{ return GetAt(nIndex); }
inline WORD& CWordArray::operator[](int nIndex)
{ return ElementAt(nIndex); }
////////////////////////////////////////////////////////////////////////////
inline int CDWordArray::GetSize() const
{ return m_nSize; }
inline int CDWordArray::GetUpperBound() const
{ return m_nSize-1; }
inline void CDWordArray::RemoveAll()
{ SetSize(0); }
inline DWORD CDWordArray::GetAt(int nIndex) const
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
return m_pData[nIndex]; }
inline void CDWordArray::SetAt(int nIndex, DWORD newElement)
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
m_pData[nIndex] = newElement; }
inline DWORD& CDWordArray::ElementAt(int nIndex)
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
return m_pData[nIndex]; }
inline const DWORD* CDWordArray::GetData() const
{ return (const DWORD*)m_pData; }
inline DWORD* CDWordArray::GetData()
{ return (DWORD*)m_pData; }
inline int CDWordArray::Add(DWORD newElement)
{ int nIndex = m_nSize;
SetAtGrow(nIndex, newElement);
return nIndex; }
inline DWORD CDWordArray::operator[](int nIndex) const
{ return GetAt(nIndex); }
inline DWORD& CDWordArray::operator[](int nIndex)
{ return ElementAt(nIndex); }
////////////////////////////////////////////////////////////////////////////
inline int CUIntArray::GetSize() const
{ return m_nSize; }
inline int CUIntArray::GetUpperBound() const
{ return m_nSize-1; }
inline void CUIntArray::RemoveAll()
{ SetSize(0); }
inline UINT CUIntArray::GetAt(int nIndex) const
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
return m_pData[nIndex]; }
inline void CUIntArray::SetAt(int nIndex, UINT newElement)
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
m_pData[nIndex] = newElement; }
inline UINT& CUIntArray::ElementAt(int nIndex)
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
return m_pData[nIndex]; }
inline const UINT* CUIntArray::GetData() const
{ return (const UINT*)m_pData; }
inline UINT* CUIntArray::GetData()
{ return (UINT*)m_pData; }
inline int CUIntArray::Add(UINT newElement)
{ int nIndex = m_nSize;
SetAtGrow(nIndex, newElement);
return nIndex; }
inline UINT CUIntArray::operator[](int nIndex) const
{ return GetAt(nIndex); }
inline UINT& CUIntArray::operator[](int nIndex)
{ return ElementAt(nIndex); }
#endif // !defined(AFX_BYTEARRAY_H__7A0D8168_8418_49F4_8589_A0142C1725CF__INCLUDED_)