OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef XFA_FGAS_CRT_FGAS_UTILS_H_ | 7 #ifndef XFA_FGAS_CRT_FGAS_UTILS_H_ |
8 #define XFA_FGAS_CRT_FGAS_UTILS_H_ | 8 #define XFA_FGAS_CRT_FGAS_UTILS_H_ |
9 | 9 |
10 #include "core/fxcrt/fx_coordinates.h" | 10 #include "core/fxcrt/fx_coordinates.h" |
11 #include "xfa/fgas/crt/fgas_memory.h" | 11 #include "xfa/fgas/crt/fgas_memory.h" |
12 | 12 |
13 class FX_BASEARRAYDATA; | 13 class FX_BASEARRAYDATA; |
14 | 14 |
15 class CFX_BaseArray : public CFX_Target { | 15 class CFX_BaseArray : public CFX_Target { |
16 protected: | 16 protected: |
17 CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize); | 17 CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize); |
18 ~CFX_BaseArray() override; | 18 ~CFX_BaseArray() override; |
19 | 19 |
20 int32_t GetSize() const; | 20 int32_t GetSize() const; |
21 int32_t GetBlockSize() const; | 21 int32_t GetBlockSize() const; |
22 uint8_t* AddSpaceTo(int32_t index); | 22 uint8_t* AddSpaceTo(int32_t index); |
23 uint8_t* GetAt(int32_t index) const; | 23 uint8_t* GetAt(int32_t index) const; |
24 uint8_t* GetBuffer() const; | 24 uint8_t* GetBuffer() const; |
25 int32_t Append(const CFX_BaseArray& src, int32_t iStart, int32_t iCount); | 25 int32_t Append(const CFX_BaseArray& src, int32_t iStart, int32_t iCount); |
26 int32_t Copy(const CFX_BaseArray& src, int32_t iStart, int32_t iCount); | 26 int32_t Copy(const CFX_BaseArray& src, int32_t iStart, int32_t iCount); |
27 int32_t RemoveLast(int32_t iCount); | 27 int32_t RemoveLast(int32_t iCount); |
28 void RemoveAll(FX_BOOL bLeaveMemory); | 28 void RemoveAll(bool bLeaveMemory); |
29 | 29 |
30 FX_BASEARRAYDATA* m_pData; | 30 FX_BASEARRAYDATA* m_pData; |
31 }; | 31 }; |
32 | 32 |
33 template <class baseType> | 33 template <class baseType> |
34 class CFX_BaseArrayTemplate : public CFX_BaseArray { | 34 class CFX_BaseArrayTemplate : public CFX_BaseArray { |
35 public: | 35 public: |
36 CFX_BaseArrayTemplate(int32_t iGrowSize) | 36 CFX_BaseArrayTemplate(int32_t iGrowSize) |
37 : CFX_BaseArray(iGrowSize, sizeof(baseType)) {} | 37 : CFX_BaseArray(iGrowSize, sizeof(baseType)) {} |
38 CFX_BaseArrayTemplate(int32_t iGrowSize, int32_t iBlockSize) | 38 CFX_BaseArrayTemplate(int32_t iGrowSize, int32_t iBlockSize) |
(...skipping 28 matching lines...) Expand all Loading... |
67 return CFX_BaseArray::Append(src, iStart, iCount); | 67 return CFX_BaseArray::Append(src, iStart, iCount); |
68 } | 68 } |
69 int32_t Copy(const CFX_BaseArrayTemplate& src, | 69 int32_t Copy(const CFX_BaseArrayTemplate& src, |
70 int32_t iStart, | 70 int32_t iStart, |
71 int32_t iCount) { | 71 int32_t iCount) { |
72 return CFX_BaseArray::Copy(src, iStart, iCount); | 72 return CFX_BaseArray::Copy(src, iStart, iCount); |
73 } | 73 } |
74 int32_t RemoveLast(int32_t iCount) { | 74 int32_t RemoveLast(int32_t iCount) { |
75 return CFX_BaseArray::RemoveLast(iCount); | 75 return CFX_BaseArray::RemoveLast(iCount); |
76 } | 76 } |
77 void RemoveAll(FX_BOOL bLeaveMemory) { | 77 void RemoveAll(bool bLeaveMemory) { CFX_BaseArray::RemoveAll(bLeaveMemory); } |
78 CFX_BaseArray::RemoveAll(bLeaveMemory); | |
79 } | |
80 }; | 78 }; |
81 | 79 |
82 class CFX_BaseMassArrayImp : public CFX_Target { | 80 class CFX_BaseMassArrayImp : public CFX_Target { |
83 public: | 81 public: |
84 CFX_BaseMassArrayImp(int32_t iChunkSize, int32_t iBlockSize); | 82 CFX_BaseMassArrayImp(int32_t iChunkSize, int32_t iBlockSize); |
85 ~CFX_BaseMassArrayImp() override; | 83 ~CFX_BaseMassArrayImp() override; |
86 | 84 |
87 uint8_t* AddSpace() { return AddSpaceTo(m_iBlockCount); } | 85 uint8_t* AddSpace() { return AddSpaceTo(m_iBlockCount); } |
88 uint8_t* AddSpaceTo(int32_t index); | 86 uint8_t* AddSpaceTo(int32_t index); |
89 uint8_t* GetAt(int32_t index) const; | 87 uint8_t* GetAt(int32_t index) const; |
90 int32_t Append(const CFX_BaseMassArrayImp& src, | 88 int32_t Append(const CFX_BaseMassArrayImp& src, |
91 int32_t iStart, | 89 int32_t iStart, |
92 int32_t iCount); | 90 int32_t iCount); |
93 int32_t Copy(const CFX_BaseMassArrayImp& src, int32_t iStart, int32_t iCount); | 91 int32_t Copy(const CFX_BaseMassArrayImp& src, int32_t iStart, int32_t iCount); |
94 int32_t RemoveLast(int32_t iCount); | 92 int32_t RemoveLast(int32_t iCount); |
95 void RemoveAll(FX_BOOL bLeaveMemory); | 93 void RemoveAll(bool bLeaveMemory); |
96 | 94 |
97 int32_t m_iChunkSize; | 95 int32_t m_iChunkSize; |
98 int32_t m_iBlockSize; | 96 int32_t m_iBlockSize; |
99 int32_t m_iChunkCount; | 97 int32_t m_iChunkCount; |
100 int32_t m_iBlockCount; | 98 int32_t m_iBlockCount; |
101 CFX_ArrayTemplate<void*>* m_pData; | 99 CFX_ArrayTemplate<void*>* m_pData; |
102 | 100 |
103 protected: | 101 protected: |
104 void Append(int32_t iDstStart, | 102 void Append(int32_t iDstStart, |
105 const CFX_BaseMassArrayImp& src, | 103 const CFX_BaseMassArrayImp& src, |
106 int32_t iSrcStart, | 104 int32_t iSrcStart, |
107 int32_t iSrcCount); | 105 int32_t iSrcCount); |
108 }; | 106 }; |
109 | 107 |
110 class CFX_BaseMassArray : public CFX_Target { | 108 class CFX_BaseMassArray : public CFX_Target { |
111 protected: | 109 protected: |
112 CFX_BaseMassArray(int32_t iChunkSize, int32_t iBlockSize); | 110 CFX_BaseMassArray(int32_t iChunkSize, int32_t iBlockSize); |
113 ~CFX_BaseMassArray() override; | 111 ~CFX_BaseMassArray() override; |
114 | 112 |
115 int32_t GetSize() const; | 113 int32_t GetSize() const; |
116 uint8_t* AddSpaceTo(int32_t index); | 114 uint8_t* AddSpaceTo(int32_t index); |
117 uint8_t* GetAt(int32_t index) const; | 115 uint8_t* GetAt(int32_t index) const; |
118 int32_t Append(const CFX_BaseMassArray& src, int32_t iStart, int32_t iCount); | 116 int32_t Append(const CFX_BaseMassArray& src, int32_t iStart, int32_t iCount); |
119 int32_t Copy(const CFX_BaseMassArray& src, int32_t iStart, int32_t iCount); | 117 int32_t Copy(const CFX_BaseMassArray& src, int32_t iStart, int32_t iCount); |
120 int32_t RemoveLast(int32_t iCount); | 118 int32_t RemoveLast(int32_t iCount); |
121 void RemoveAll(FX_BOOL bLeaveMemory); | 119 void RemoveAll(bool bLeaveMemory); |
122 CFX_BaseMassArrayImp* m_pData; | 120 CFX_BaseMassArrayImp* m_pData; |
123 }; | 121 }; |
124 | 122 |
125 template <class baseType> | 123 template <class baseType> |
126 class CFX_MassArrayTemplate : public CFX_BaseMassArray { | 124 class CFX_MassArrayTemplate : public CFX_BaseMassArray { |
127 public: | 125 public: |
128 CFX_MassArrayTemplate(int32_t iChunkSize) | 126 CFX_MassArrayTemplate(int32_t iChunkSize) |
129 : CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {} | 127 : CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {} |
130 CFX_MassArrayTemplate(int32_t iChunkSize, int32_t iBlockSize) | 128 CFX_MassArrayTemplate(int32_t iChunkSize, int32_t iBlockSize) |
131 : CFX_BaseMassArray(iChunkSize, iBlockSize) {} | 129 : CFX_BaseMassArray(iChunkSize, iBlockSize) {} |
(...skipping 26 matching lines...) Expand all Loading... |
158 return CFX_BaseMassArray::Append(src, iStart, iCount); | 156 return CFX_BaseMassArray::Append(src, iStart, iCount); |
159 } | 157 } |
160 int32_t Copy(const CFX_MassArrayTemplate& src, | 158 int32_t Copy(const CFX_MassArrayTemplate& src, |
161 int32_t iStart, | 159 int32_t iStart, |
162 int32_t iCount) { | 160 int32_t iCount) { |
163 return CFX_BaseMassArray::Copy(src, iStart, iCount); | 161 return CFX_BaseMassArray::Copy(src, iStart, iCount); |
164 } | 162 } |
165 int32_t RemoveLast(int32_t iCount) { | 163 int32_t RemoveLast(int32_t iCount) { |
166 return CFX_BaseMassArray::RemoveLast(iCount); | 164 return CFX_BaseMassArray::RemoveLast(iCount); |
167 } | 165 } |
168 void RemoveAll(FX_BOOL bLeaveMemory) { | 166 void RemoveAll(bool bLeaveMemory) { |
169 CFX_BaseMassArray::RemoveAll(bLeaveMemory); | 167 CFX_BaseMassArray::RemoveAll(bLeaveMemory); |
170 } | 168 } |
171 }; | 169 }; |
172 | 170 |
173 template <class baseType> | 171 template <class baseType> |
174 class CFX_ObjectMassArrayTemplate : public CFX_BaseMassArray { | 172 class CFX_ObjectMassArrayTemplate : public CFX_BaseMassArray { |
175 public: | 173 public: |
176 CFX_ObjectMassArrayTemplate(int32_t iChunkSize) | 174 CFX_ObjectMassArrayTemplate(int32_t iChunkSize) |
177 : CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {} | 175 : CFX_BaseMassArray(iChunkSize, sizeof(baseType)) {} |
178 ~CFX_ObjectMassArrayTemplate() { RemoveAll(FALSE); } | 176 ~CFX_ObjectMassArrayTemplate() { RemoveAll(false); } |
179 | 177 |
180 int32_t GetSize() const { return CFX_BaseMassArray::GetSize(); } | 178 int32_t GetSize() const { return CFX_BaseMassArray::GetSize(); } |
181 int32_t Add(const baseType& element) { | 179 int32_t Add(const baseType& element) { |
182 int32_t index = CFX_BaseMassArray::GetSize(); | 180 int32_t index = CFX_BaseMassArray::GetSize(); |
183 baseType* p = (baseType*)CFX_BaseMassArray::AddSpaceTo(index); | 181 baseType* p = (baseType*)CFX_BaseMassArray::AddSpaceTo(index); |
184 new ((void*)p) baseType(element); | 182 new ((void*)p) baseType(element); |
185 return index; | 183 return index; |
186 } | 184 } |
187 baseType& GetAt(int32_t index) const { | 185 baseType& GetAt(int32_t index) const { |
188 return *(baseType*)CFX_BaseMassArray::GetAt(index); | 186 return *(baseType*)CFX_BaseMassArray::GetAt(index); |
(...skipping 29 matching lines...) Expand all Loading... |
218 } | 216 } |
219 int32_t iSize = src.GetSize(); | 217 int32_t iSize = src.GetSize(); |
220 ASSERT(iStart > -1 && iStart < iSize); | 218 ASSERT(iStart > -1 && iStart < iSize); |
221 if (iCount < 0) { | 219 if (iCount < 0) { |
222 iCount = iSize; | 220 iCount = iSize; |
223 } | 221 } |
224 int32_t iEnd = iStart + iCount; | 222 int32_t iEnd = iStart + iCount; |
225 if (iEnd > iSize) { | 223 if (iEnd > iSize) { |
226 iEnd = iSize; | 224 iEnd = iSize; |
227 } | 225 } |
228 RemoveAll(TRUE); | 226 RemoveAll(true); |
229 for (int32_t i = iStart; i < iEnd; i++) { | 227 for (int32_t i = iStart; i < iEnd; i++) { |
230 Add(src.GetAt(i)); | 228 Add(src.GetAt(i)); |
231 } | 229 } |
232 return CFX_BaseMassArray::GetSize(); | 230 return CFX_BaseMassArray::GetSize(); |
233 } | 231 } |
234 int32_t RemoveLast(int32_t iCount) { | 232 int32_t RemoveLast(int32_t iCount) { |
235 int32_t iSize = CFX_BaseMassArray::GetSize(); | 233 int32_t iSize = CFX_BaseMassArray::GetSize(); |
236 if (iCount < 0 || iCount > iSize) { | 234 if (iCount < 0 || iCount > iSize) { |
237 iCount = iSize; | 235 iCount = iSize; |
238 } | 236 } |
239 if (iCount == 0) { | 237 if (iCount == 0) { |
240 return iSize; | 238 return iSize; |
241 } | 239 } |
242 for (int32_t i = iSize - iCount; i < iSize; i++) { | 240 for (int32_t i = iSize - iCount; i < iSize; i++) { |
243 ((baseType*)GetPtrAt(i))->~baseType(); | 241 ((baseType*)GetPtrAt(i))->~baseType(); |
244 } | 242 } |
245 return CFX_BaseMassArray::RemoveLast(iCount); | 243 return CFX_BaseMassArray::RemoveLast(iCount); |
246 } | 244 } |
247 void RemoveAll(FX_BOOL bLeaveMemory) { | 245 void RemoveAll(bool bLeaveMemory) { |
248 int32_t iSize = CFX_BaseMassArray::GetSize(); | 246 int32_t iSize = CFX_BaseMassArray::GetSize(); |
249 for (int32_t i = 0; i < iSize; i++) { | 247 for (int32_t i = 0; i < iSize; i++) { |
250 ((baseType*)GetPtrAt(i))->~baseType(); | 248 ((baseType*)GetPtrAt(i))->~baseType(); |
251 } | 249 } |
252 CFX_BaseMassArray::RemoveAll(bLeaveMemory); | 250 CFX_BaseMassArray::RemoveAll(bLeaveMemory); |
253 } | 251 } |
254 }; | 252 }; |
255 | 253 |
256 class CFX_BaseDiscreteArray : public CFX_Target { | 254 class CFX_BaseDiscreteArray : public CFX_Target { |
257 protected: | 255 protected: |
(...skipping 28 matching lines...) Expand all Loading... |
286 class CFX_BaseStack : public CFX_Target { | 284 class CFX_BaseStack : public CFX_Target { |
287 protected: | 285 protected: |
288 CFX_BaseStack(int32_t iChunkSize, int32_t iBlockSize); | 286 CFX_BaseStack(int32_t iChunkSize, int32_t iBlockSize); |
289 ~CFX_BaseStack() override; | 287 ~CFX_BaseStack() override; |
290 | 288 |
291 uint8_t* Push(); | 289 uint8_t* Push(); |
292 void Pop(); | 290 void Pop(); |
293 uint8_t* GetTopElement() const; | 291 uint8_t* GetTopElement() const; |
294 int32_t GetSize() const; | 292 int32_t GetSize() const; |
295 uint8_t* GetAt(int32_t index) const; | 293 uint8_t* GetAt(int32_t index) const; |
296 void RemoveAll(FX_BOOL bLeaveMemory); | 294 void RemoveAll(bool bLeaveMemory); |
297 CFX_BaseMassArrayImp* m_pData; | 295 CFX_BaseMassArrayImp* m_pData; |
298 }; | 296 }; |
299 | 297 |
300 template <class baseType> | 298 template <class baseType> |
301 class CFX_StackTemplate : public CFX_BaseStack { | 299 class CFX_StackTemplate : public CFX_BaseStack { |
302 public: | 300 public: |
303 CFX_StackTemplate(int32_t iChunkSize) | 301 CFX_StackTemplate(int32_t iChunkSize) |
304 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} | 302 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} |
305 | 303 |
306 int32_t Push(const baseType& element) { | 304 int32_t Push(const baseType& element) { |
307 int32_t index = CFX_BaseStack::GetSize(); | 305 int32_t index = CFX_BaseStack::GetSize(); |
308 *(baseType*)CFX_BaseStack::Push() = element; | 306 *(baseType*)CFX_BaseStack::Push() = element; |
309 return index; | 307 return index; |
310 } | 308 } |
311 void Pop() { CFX_BaseStack::Pop(); } | 309 void Pop() { CFX_BaseStack::Pop(); } |
312 baseType* GetTopElement() const { | 310 baseType* GetTopElement() const { |
313 return (baseType*)CFX_BaseStack::GetTopElement(); | 311 return (baseType*)CFX_BaseStack::GetTopElement(); |
314 } | 312 } |
315 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } | 313 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } |
316 baseType* GetAt(int32_t index) const { | 314 baseType* GetAt(int32_t index) const { |
317 return (baseType*)CFX_BaseStack::GetAt(index); | 315 return (baseType*)CFX_BaseStack::GetAt(index); |
318 } | 316 } |
319 void RemoveAll(FX_BOOL bLeaveMemory) { | 317 void RemoveAll(bool bLeaveMemory) { CFX_BaseStack::RemoveAll(bLeaveMemory); } |
320 CFX_BaseStack::RemoveAll(bLeaveMemory); | |
321 } | |
322 }; | 318 }; |
323 | 319 |
324 template <class baseType> | 320 template <class baseType> |
325 class CFX_ObjectStackTemplate : public CFX_BaseStack { | 321 class CFX_ObjectStackTemplate : public CFX_BaseStack { |
326 public: | 322 public: |
327 CFX_ObjectStackTemplate(int32_t iChunkSize) | 323 CFX_ObjectStackTemplate(int32_t iChunkSize) |
328 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} | 324 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} |
329 ~CFX_ObjectStackTemplate() { RemoveAll(FALSE); } | 325 ~CFX_ObjectStackTemplate() { RemoveAll(false); } |
330 | 326 |
331 int32_t Push(const baseType& element) { | 327 int32_t Push(const baseType& element) { |
332 int32_t index = CFX_BaseStack::GetSize(); | 328 int32_t index = CFX_BaseStack::GetSize(); |
333 baseType* p = (baseType*)CFX_BaseStack::Push(); | 329 baseType* p = (baseType*)CFX_BaseStack::Push(); |
334 new ((void*)p) baseType(element); | 330 new ((void*)p) baseType(element); |
335 return index; | 331 return index; |
336 } | 332 } |
337 void Pop() { | 333 void Pop() { |
338 baseType* p = (baseType*)CFX_BaseStack::GetTopElement(); | 334 baseType* p = (baseType*)CFX_BaseStack::GetTopElement(); |
339 if (p) { | 335 if (p) { |
340 p->~baseType(); | 336 p->~baseType(); |
341 } | 337 } |
342 CFX_BaseStack::Pop(); | 338 CFX_BaseStack::Pop(); |
343 } | 339 } |
344 baseType* GetTopElement() const { | 340 baseType* GetTopElement() const { |
345 return (baseType*)CFX_BaseStack::GetTopElement(); | 341 return (baseType*)CFX_BaseStack::GetTopElement(); |
346 } | 342 } |
347 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } | 343 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } |
348 baseType* GetAt(int32_t index) const { | 344 baseType* GetAt(int32_t index) const { |
349 return (baseType*)CFX_BaseStack::GetAt(index); | 345 return (baseType*)CFX_BaseStack::GetAt(index); |
350 } | 346 } |
351 void RemoveAll(FX_BOOL bLeaveMemory) { | 347 void RemoveAll(bool bLeaveMemory) { |
352 int32_t iSize = CFX_BaseStack::GetSize(); | 348 int32_t iSize = CFX_BaseStack::GetSize(); |
353 for (int32_t i = 0; i < iSize; i++) { | 349 for (int32_t i = 0; i < iSize; i++) { |
354 ((baseType*)CFX_BaseStack::GetAt(i))->~baseType(); | 350 ((baseType*)CFX_BaseStack::GetAt(i))->~baseType(); |
355 } | 351 } |
356 CFX_BaseStack::RemoveAll(bLeaveMemory); | 352 CFX_BaseStack::RemoveAll(bLeaveMemory); |
357 } | 353 } |
358 int32_t Copy(const CFX_ObjectStackTemplate& src, | 354 int32_t Copy(const CFX_ObjectStackTemplate& src, |
359 int32_t iStart, | 355 int32_t iStart, |
360 int32_t iCount) { | 356 int32_t iCount) { |
361 if (iCount == 0) { | 357 if (iCount == 0) { |
362 return CFX_BaseStack::GetSize(); | 358 return CFX_BaseStack::GetSize(); |
363 } | 359 } |
364 int32_t iSize = src.GetSize(); | 360 int32_t iSize = src.GetSize(); |
365 ASSERT(iStart > -1 && iStart < iSize); | 361 ASSERT(iStart > -1 && iStart < iSize); |
366 if (iCount < 0) { | 362 if (iCount < 0) { |
367 iCount = iSize; | 363 iCount = iSize; |
368 } | 364 } |
369 int32_t iEnd = iStart + iCount; | 365 int32_t iEnd = iStart + iCount; |
370 if (iEnd > iSize) { | 366 if (iEnd > iSize) { |
371 iEnd = iSize; | 367 iEnd = iSize; |
372 } | 368 } |
373 RemoveAll(TRUE); | 369 RemoveAll(true); |
374 for (int32_t i = iStart; i < iEnd; i++) { | 370 for (int32_t i = iStart; i < iEnd; i++) { |
375 Push(*src.GetAt(i)); | 371 Push(*src.GetAt(i)); |
376 } | 372 } |
377 return CFX_BaseStack::GetSize(); | 373 return CFX_BaseStack::GetSize(); |
378 } | 374 } |
379 }; | 375 }; |
380 | 376 |
381 #endif // XFA_FGAS_CRT_FGAS_UTILS_H_ | 377 #endif // XFA_FGAS_CRT_FGAS_UTILS_H_ |
OLD | NEW |