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
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#ifndef XFA_FGAS_CRT_FGAS_UTILS_H_
#define XFA_FGAS_CRT_FGAS_UTILS_H_
#include "core/fxcrt/fx_coordinates.h"
#include "xfa/fgas/crt/fgas_memory.h"
class FX_BASEARRAYDATA;
class CFX_BaseArray : public CFX_Target {
protected:
CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize);
~CFX_BaseArray() override;
int32_t GetSize() const;
int32_t GetBlockSize() const;
uint8_t* AddSpaceTo(int32_t index);
uint8_t* GetAt(int32_t index) const;
uint8_t* GetBuffer() const;
int32_t Append(const CFX_BaseArray& src, int32_t iStart, int32_t iCount);
int32_t Copy(const CFX_BaseArray& src, int32_t iStart, int32_t iCount);
int32_t RemoveLast(int32_t iCount);
void RemoveAll(bool bLeaveMemory);
FX_BASEARRAYDATA* m_pData;
};
template <class baseType>
class CFX_BaseArrayTemplate : public CFX_BaseArray {
public:
explicit CFX_BaseArrayTemplate(int32_t iGrowSize)
: CFX_BaseArray(iGrowSize, sizeof(baseType)) {}
CFX_BaseArrayTemplate(int32_t iGrowSize, int32_t iBlockSize)
: CFX_BaseArray(iGrowSize, iBlockSize) {}
int32_t GetSize() const { return CFX_BaseArray::GetSize(); }
int32_t GetBlockSize() const { return CFX_BaseArray::GetBlockSize(); }
baseType* AddSpace() {
return (baseType*)CFX_BaseArray::AddSpaceTo(CFX_BaseArray::GetSize());
}
int32_t Add(const baseType& element) {
int32_t index = CFX_BaseArray::GetSize();
*(baseType*)CFX_BaseArray::AddSpaceTo(index) = element;
return index;
}
baseType* GetBuffer() const { return (baseType*)CFX_BaseArray::GetBuffer(); }
baseType& GetAt(int32_t index) const {
return *(baseType*)CFX_BaseArray::GetAt(index);
}
baseType* GetPtrAt(int32_t index) const {
return (baseType*)CFX_BaseArray::GetAt(index);
}
void SetAt(int32_t index, const baseType& element) {
*(baseType*)CFX_BaseArray::GetAt(index) = element;
}
void SetAtGrow(int32_t index, const baseType& element) {
*(baseType*)CFX_BaseArray::AddSpaceTo(index) = element;
}
int32_t Append(const CFX_BaseArrayTemplate& src,
int32_t iStart,
int32_t iCount) {
return CFX_BaseArray::Append(src, iStart, iCount);
}
int32_t Copy(const CFX_BaseArrayTemplate& src,
int32_t iStart,
int32_t iCount) {
return CFX_BaseArray::Copy(src, iStart, iCount);
}
int32_t RemoveLast(int32_t iCount) {
return CFX_BaseArray::RemoveLast(iCount);
}
void RemoveAll(bool bLeaveMemory) { CFX_BaseArray::RemoveAll(bLeaveMemory); }
};
class CFX_BaseMassArrayImp : public CFX_Target {
public:
CFX_BaseMassArrayImp(int32_t iChunkSize, int32_t iBlockSize);
~CFX_BaseMassArrayImp() override;
uint8_t* AddSpace() { return AddSpaceTo(m_iBlockCount); }
uint8_t* AddSpaceTo(int32_t index);
uint8_t* GetAt(int32_t index) const;
int32_t Append(const CFX_BaseMassArrayImp& src,
int32_t iStart,
int32_t iCount);
int32_t Copy(const CFX_BaseMassArrayImp& src, int32_t iStart, int32_t iCount);
int32_t RemoveLast(int32_t iCount);
void RemoveAll(bool bLeaveMemory);
int32_t m_iChunkSize;
int32_t m_iBlockSize;
int32_t m_iChunkCount;
int32_t m_iBlockCount;
CFX_ArrayTemplate<void*>* m_pData;
protected:
void Append(int32_t iDstStart,
const CFX_BaseMassArrayImp& src,
int32_t iSrcStart,
int32_t iSrcCount);
};
class CFX_BaseMassArray : public CFX_Target {
protected:
CFX_BaseMassArray(int32_t iChunkSize, int32_t iBlockSize);
~CFX_BaseMassArray() override;
int32_t GetSize() const;
uint8_t* AddSpaceTo(int32_t index);
uint8_t* GetAt(int32_t index) const;
int32_t Append(const CFX_BaseMassArray& src, int32_t iStart, int32_t iCount);
int32_t Copy(const CFX_BaseMassArray& src, int32_t iStart, int32_t iCount);
int32_t RemoveLast(int32_t iCount);
void RemoveAll(bool bLeaveMemory);
CFX_BaseMassArrayImp* m_pData;
};
template <class baseType>
class CFX_MassArrayTemplate : public CFX_BaseMassArray {
public:
explicit CFX_MassArrayTemplate(int32_t iChunkSize)
: CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {}
CFX_MassArrayTemplate(int32_t iChunkSize, int32_t iBlockSize)
: CFX_BaseMassArray(iChunkSize, iBlockSize) {}
int32_t GetSize() const { return CFX_BaseMassArray::GetSize(); }
baseType* AddSpace() {
return (baseType*)CFX_BaseMassArray::AddSpaceTo(
CFX_BaseMassArray::GetSize());
}
int32_t Add(const baseType& element) {
int32_t index = CFX_BaseMassArray::GetSize();
*(baseType*)CFX_BaseMassArray::AddSpaceTo(index) = element;
return index;
}
baseType& GetAt(int32_t index) const {
return *(baseType*)CFX_BaseMassArray::GetAt(index);
}
baseType* GetPtrAt(int32_t index) const {
return (baseType*)CFX_BaseMassArray::GetAt(index);
}
void SetAt(int32_t index, const baseType& element) {
*(baseType*)CFX_BaseMassArray::GetAt(index) = element;
}
void SetAtGrow(int32_t index, const baseType& element) {
*(baseType*)CFX_BaseMassArray::AddSpaceTo(index) = element;
}
int32_t Append(const CFX_MassArrayTemplate& src,
int32_t iStart,
int32_t iCount) {
return CFX_BaseMassArray::Append(src, iStart, iCount);
}
int32_t Copy(const CFX_MassArrayTemplate& src,
int32_t iStart,
int32_t iCount) {
return CFX_BaseMassArray::Copy(src, iStart, iCount);
}
int32_t RemoveLast(int32_t iCount) {
return CFX_BaseMassArray::RemoveLast(iCount);
}
void RemoveAll(bool bLeaveMemory) {
CFX_BaseMassArray::RemoveAll(bLeaveMemory);
}
};
template <class baseType>
class CFX_ObjectMassArrayTemplate : public CFX_BaseMassArray {
public:
explicit CFX_ObjectMassArrayTemplate(int32_t iChunkSize)
: CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {}
~CFX_ObjectMassArrayTemplate() { RemoveAll(false); }
int32_t GetSize() const { return CFX_BaseMassArray::GetSize(); }
int32_t Add(const baseType& element) {
int32_t index = CFX_BaseMassArray::GetSize();
baseType* p = (baseType*)CFX_BaseMassArray::AddSpaceTo(index);
new ((void*)p) baseType(element);
return index;
}
baseType& GetAt(int32_t index) const {
return *(baseType*)CFX_BaseMassArray::GetAt(index);
}
baseType* GetPtrAt(int32_t index) const {
return (baseType*)CFX_BaseMassArray::GetAt(index);
}
int32_t Append(const CFX_ObjectMassArrayTemplate& src,
int32_t iStart,
int32_t iCount) {
if (iCount == 0) {
return CFX_BaseMassArray::GetSize();
}
int32_t iSize = src.GetSize();
ASSERT(iStart > -1 && iStart < iSize);
if (iCount < 0) {
iCount = iSize;
}
int32_t iEnd = iStart + iCount;
if (iEnd > iSize) {
iEnd = iSize;
}
for (int32_t i = iStart; i < iEnd; i++) {
Add(src.GetAt(i));
}
return CFX_BaseMassArray::GetSize();
}
int32_t Copy(const CFX_ObjectMassArrayTemplate& src,
int32_t iStart,
int32_t iCount) {
if (iCount == 0) {
return CFX_BaseMassArray::GetSize();
}
int32_t iSize = src.GetSize();
ASSERT(iStart > -1 && iStart < iSize);
if (iCount < 0) {
iCount = iSize;
}
int32_t iEnd = iStart + iCount;
if (iEnd > iSize) {
iEnd = iSize;
}
RemoveAll(true);
for (int32_t i = iStart; i < iEnd; i++) {
Add(src.GetAt(i));
}
return CFX_BaseMassArray::GetSize();
}
int32_t RemoveLast(int32_t iCount) {
int32_t iSize = CFX_BaseMassArray::GetSize();
if (iCount < 0 || iCount > iSize) {
iCount = iSize;
}
if (iCount == 0) {
return iSize;
}
for (int32_t i = iSize - iCount; i < iSize; i++) {
((baseType*)GetPtrAt(i))->~baseType();
}
return CFX_BaseMassArray::RemoveLast(iCount);
}
void RemoveAll(bool bLeaveMemory) {
int32_t iSize = CFX_BaseMassArray::GetSize();
for (int32_t i = 0; i < iSize; i++) {
((baseType*)GetPtrAt(i))->~baseType();
}
CFX_BaseMassArray::RemoveAll(bLeaveMemory);
}
};
class CFX_BaseDiscreteArray : public CFX_Target {
protected:
CFX_BaseDiscreteArray(int32_t iChunkSize, int32_t iBlockSize);
~CFX_BaseDiscreteArray() override;
uint8_t* AddSpaceTo(int32_t index);
uint8_t* GetAt(int32_t index) const;
void RemoveAll();
void* m_pData;
};
template <class baseType>
class CFX_DiscreteArrayTemplate : public CFX_BaseDiscreteArray {
public:
explicit CFX_DiscreteArrayTemplate(int32_t iChunkSize)
: CFX_BaseDiscreteArray(iChunkSize, sizeof(baseType)) {}
baseType& GetAt(int32_t index, const baseType& defValue) const {
baseType* p = (baseType*)CFX_BaseDiscreteArray::GetAt(index);
return p ? *p : (baseType&)defValue;
}
baseType* GetPtrAt(int32_t index) const {
return (baseType*)CFX_BaseDiscreteArray::GetAt(index);
}
void SetAtGrow(int32_t index, const baseType& element) {
*(baseType*)CFX_BaseDiscreteArray::AddSpaceTo(index) = element;
}
void RemoveAll() { CFX_BaseDiscreteArray::RemoveAll(); }
};
class CFX_BaseStack : public CFX_Target {
protected:
CFX_BaseStack(int32_t iChunkSize, int32_t iBlockSize);
~CFX_BaseStack() override;
uint8_t* Push();
void Pop();
uint8_t* GetTopElement() const;
int32_t GetSize() const;
uint8_t* GetAt(int32_t index) const;
void RemoveAll(bool bLeaveMemory);
CFX_BaseMassArrayImp* m_pData;
};
template <class baseType>
class CFX_StackTemplate : public CFX_BaseStack {
public:
explicit CFX_StackTemplate(int32_t iChunkSize)
: CFX_BaseStack(iChunkSize, sizeof(baseType)) {}
int32_t Push(const baseType& element) {
int32_t index = CFX_BaseStack::GetSize();
*(baseType*)CFX_BaseStack::Push() = element;
return index;
}
void Pop() { CFX_BaseStack::Pop(); }
baseType* GetTopElement() const {
return (baseType*)CFX_BaseStack::GetTopElement();
}
int32_t GetSize() const { return CFX_BaseStack::GetSize(); }
baseType* GetAt(int32_t index) const {
return (baseType*)CFX_BaseStack::GetAt(index);
}
void RemoveAll(bool bLeaveMemory) { CFX_BaseStack::RemoveAll(bLeaveMemory); }
};
template <class baseType>
class CFX_ObjectStackTemplate : public CFX_BaseStack {
public:
explicit CFX_ObjectStackTemplate(int32_t iChunkSize)
: CFX_BaseStack(iChunkSize, sizeof(baseType)) {}
~CFX_ObjectStackTemplate() { RemoveAll(false); }
int32_t Push(const baseType& element) {
int32_t index = CFX_BaseStack::GetSize();
baseType* p = (baseType*)CFX_BaseStack::Push();
new ((void*)p) baseType(element);
return index;
}
void Pop() {
baseType* p = (baseType*)CFX_BaseStack::GetTopElement();
if (p) {
p->~baseType();
}
CFX_BaseStack::Pop();
}
baseType* GetTopElement() const {
return (baseType*)CFX_BaseStack::GetTopElement();
}
int32_t GetSize() const { return CFX_BaseStack::GetSize(); }
baseType* GetAt(int32_t index) const {
return (baseType*)CFX_BaseStack::GetAt(index);
}
void RemoveAll(bool bLeaveMemory) {
int32_t iSize = CFX_BaseStack::GetSize();
for (int32_t i = 0; i < iSize; i++) {
((baseType*)CFX_BaseStack::GetAt(i))->~baseType();
}
CFX_BaseStack::RemoveAll(bLeaveMemory);
}
int32_t Copy(const CFX_ObjectStackTemplate& src,
int32_t iStart,
int32_t iCount) {
if (iCount == 0) {
return CFX_BaseStack::GetSize();
}
int32_t iSize = src.GetSize();
ASSERT(iStart > -1 && iStart < iSize);
if (iCount < 0) {
iCount = iSize;
}
int32_t iEnd = iStart + iCount;
if (iEnd > iSize) {
iEnd = iSize;
}
RemoveAll(true);
for (int32_t i = iStart; i < iEnd; i++) {
Push(*src.GetAt(i));
}
return CFX_BaseStack::GetSize();
}
};
#endif // XFA_FGAS_CRT_FGAS_UTILS_H_
|