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/include/fx_coordinates.h" | 10 #include "core/fxcrt/include/fx_coordinates.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 void* m_pData; | 367 void* m_pData; |
368 }; | 368 }; |
369 | 369 |
370 template <class baseType> | 370 template <class baseType> |
371 class CFX_DiscreteArrayTemplate : public CFX_BaseDiscreteArray { | 371 class CFX_DiscreteArrayTemplate : public CFX_BaseDiscreteArray { |
372 public: | 372 public: |
373 CFX_DiscreteArrayTemplate(int32_t iChunkSize = 100) | 373 CFX_DiscreteArrayTemplate(int32_t iChunkSize = 100) |
374 : CFX_BaseDiscreteArray(iChunkSize, sizeof(baseType)) {} | 374 : CFX_BaseDiscreteArray(iChunkSize, sizeof(baseType)) {} |
375 baseType& GetAt(int32_t index, const baseType& defValue) const { | 375 baseType& GetAt(int32_t index, const baseType& defValue) const { |
376 baseType* p = (baseType*)CFX_BaseDiscreteArray::GetAt(index); | 376 baseType* p = (baseType*)CFX_BaseDiscreteArray::GetAt(index); |
377 return p == NULL ? (baseType&)defValue : *p; | 377 return p ? *p : (baseType&)defValue; |
378 } | 378 } |
379 baseType* GetPtrAt(int32_t index) const { | 379 baseType* GetPtrAt(int32_t index) const { |
380 return (baseType*)CFX_BaseDiscreteArray::GetAt(index); | 380 return (baseType*)CFX_BaseDiscreteArray::GetAt(index); |
381 } | 381 } |
382 void SetAtGrow(int32_t index, const baseType& element) { | 382 void SetAtGrow(int32_t index, const baseType& element) { |
383 *(baseType*)CFX_BaseDiscreteArray::AddSpaceTo(index) = element; | 383 *(baseType*)CFX_BaseDiscreteArray::AddSpaceTo(index) = element; |
384 } | 384 } |
385 void RemoveAll() { CFX_BaseDiscreteArray::RemoveAll(); } | 385 void RemoveAll() { CFX_BaseDiscreteArray::RemoveAll(); } |
386 }; | 386 }; |
387 typedef CFX_DiscreteArrayTemplate<void*> CFX_PtrDiscreteArray; | 387 typedef CFX_DiscreteArrayTemplate<void*> CFX_PtrDiscreteArray; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} | 435 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} |
436 ~CFX_ObjectStackTemplate() { RemoveAll(); } | 436 ~CFX_ObjectStackTemplate() { RemoveAll(); } |
437 int32_t Push(const baseType& element) { | 437 int32_t Push(const baseType& element) { |
438 int32_t index = CFX_BaseStack::GetSize(); | 438 int32_t index = CFX_BaseStack::GetSize(); |
439 baseType* p = (baseType*)CFX_BaseStack::Push(); | 439 baseType* p = (baseType*)CFX_BaseStack::Push(); |
440 new ((void*)p) baseType(element); | 440 new ((void*)p) baseType(element); |
441 return index; | 441 return index; |
442 } | 442 } |
443 void Pop() { | 443 void Pop() { |
444 baseType* p = (baseType*)CFX_BaseStack::GetTopElement(); | 444 baseType* p = (baseType*)CFX_BaseStack::GetTopElement(); |
445 if (p != NULL) { | 445 if (p) { |
446 p->~baseType(); | 446 p->~baseType(); |
447 } | 447 } |
448 CFX_BaseStack::Pop(); | 448 CFX_BaseStack::Pop(); |
449 } | 449 } |
450 baseType* GetTopElement() const { | 450 baseType* GetTopElement() const { |
451 return (baseType*)CFX_BaseStack::GetTopElement(); | 451 return (baseType*)CFX_BaseStack::GetTopElement(); |
452 } | 452 } |
453 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } | 453 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } |
454 baseType* GetAt(int32_t index) const { | 454 baseType* GetAt(int32_t index) const { |
455 return (baseType*)CFX_BaseStack::GetAt(index); | 455 return (baseType*)CFX_BaseStack::GetAt(index); |
(...skipping 22 matching lines...) Expand all Loading... |
478 } | 478 } |
479 RemoveAll(TRUE); | 479 RemoveAll(TRUE); |
480 for (int32_t i = iStart; i < iEnd; i++) { | 480 for (int32_t i = iStart; i < iEnd; i++) { |
481 Push(*src.GetAt(i)); | 481 Push(*src.GetAt(i)); |
482 } | 482 } |
483 return CFX_BaseStack::GetSize(); | 483 return CFX_BaseStack::GetSize(); |
484 } | 484 } |
485 }; | 485 }; |
486 | 486 |
487 #endif // XFA_FGAS_CRT_FGAS_UTILS_H_ | 487 #endif // XFA_FGAS_CRT_FGAS_UTILS_H_ |
OLD | NEW |