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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 void* m_pData; | 371 void* m_pData; |
372 }; | 372 }; |
373 | 373 |
374 template <class baseType> | 374 template <class baseType> |
375 class CFX_DiscreteArrayTemplate : public CFX_BaseDiscreteArray { | 375 class CFX_DiscreteArrayTemplate : public CFX_BaseDiscreteArray { |
376 public: | 376 public: |
377 CFX_DiscreteArrayTemplate(int32_t iChunkSize = 100) | 377 CFX_DiscreteArrayTemplate(int32_t iChunkSize = 100) |
378 : CFX_BaseDiscreteArray(iChunkSize, sizeof(baseType)) {} | 378 : CFX_BaseDiscreteArray(iChunkSize, sizeof(baseType)) {} |
379 baseType& GetAt(int32_t index, const baseType& defValue) const { | 379 baseType& GetAt(int32_t index, const baseType& defValue) const { |
380 baseType* p = (baseType*)CFX_BaseDiscreteArray::GetAt(index); | 380 baseType* p = (baseType*)CFX_BaseDiscreteArray::GetAt(index); |
381 return p == NULL ? (baseType&)defValue : *p; | 381 return p ? *p : (baseType&)defValue; |
382 } | 382 } |
383 baseType* GetPtrAt(int32_t index) const { | 383 baseType* GetPtrAt(int32_t index) const { |
384 return (baseType*)CFX_BaseDiscreteArray::GetAt(index); | 384 return (baseType*)CFX_BaseDiscreteArray::GetAt(index); |
385 } | 385 } |
386 void SetAtGrow(int32_t index, const baseType& element) { | 386 void SetAtGrow(int32_t index, const baseType& element) { |
387 *(baseType*)CFX_BaseDiscreteArray::AddSpaceTo(index) = element; | 387 *(baseType*)CFX_BaseDiscreteArray::AddSpaceTo(index) = element; |
388 } | 388 } |
389 void RemoveAll() { CFX_BaseDiscreteArray::RemoveAll(); } | 389 void RemoveAll() { CFX_BaseDiscreteArray::RemoveAll(); } |
390 }; | 390 }; |
391 typedef CFX_DiscreteArrayTemplate<void*> CFX_PtrDiscreteArray; | 391 typedef CFX_DiscreteArrayTemplate<void*> CFX_PtrDiscreteArray; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} | 440 : CFX_BaseStack(iChunkSize, sizeof(baseType)) {} |
441 ~CFX_ObjectStackTemplate() { RemoveAll(); } | 441 ~CFX_ObjectStackTemplate() { RemoveAll(); } |
442 int32_t Push(const baseType& element) { | 442 int32_t Push(const baseType& element) { |
443 int32_t index = CFX_BaseStack::GetSize(); | 443 int32_t index = CFX_BaseStack::GetSize(); |
444 baseType* p = (baseType*)CFX_BaseStack::Push(); | 444 baseType* p = (baseType*)CFX_BaseStack::Push(); |
445 new ((void*)p) baseType(element); | 445 new ((void*)p) baseType(element); |
446 return index; | 446 return index; |
447 } | 447 } |
448 void Pop() { | 448 void Pop() { |
449 baseType* p = (baseType*)CFX_BaseStack::GetTopElement(); | 449 baseType* p = (baseType*)CFX_BaseStack::GetTopElement(); |
450 if (p != NULL) { | 450 if (p) { |
451 p->~baseType(); | 451 p->~baseType(); |
452 } | 452 } |
453 CFX_BaseStack::Pop(); | 453 CFX_BaseStack::Pop(); |
454 } | 454 } |
455 baseType* GetTopElement() const { | 455 baseType* GetTopElement() const { |
456 return (baseType*)CFX_BaseStack::GetTopElement(); | 456 return (baseType*)CFX_BaseStack::GetTopElement(); |
457 } | 457 } |
458 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } | 458 int32_t GetSize() const { return CFX_BaseStack::GetSize(); } |
459 baseType* GetAt(int32_t index) const { | 459 baseType* GetAt(int32_t index) const { |
460 return (baseType*)CFX_BaseStack::GetAt(index); | 460 return (baseType*)CFX_BaseStack::GetAt(index); |
(...skipping 22 matching lines...) Expand all Loading... |
483 } | 483 } |
484 RemoveAll(TRUE); | 484 RemoveAll(TRUE); |
485 for (int32_t i = iStart; i < iEnd; i++) { | 485 for (int32_t i = iStart; i < iEnd; i++) { |
486 Push(*src.GetAt(i)); | 486 Push(*src.GetAt(i)); |
487 } | 487 } |
488 return CFX_BaseStack::GetSize(); | 488 return CFX_BaseStack::GetSize(); |
489 } | 489 } |
490 }; | 490 }; |
491 | 491 |
492 #endif // XFA_FGAS_CRT_FGAS_UTILS_H_ | 492 #endif // XFA_FGAS_CRT_FGAS_UTILS_H_ |
OLD | NEW |