Chromium Code Reviews| 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 CORE_FXCRT_INCLUDE_FX_BASIC_H_ | 7 #ifndef CORE_FXCRT_INCLUDE_FX_BASIC_H_ |
| 8 #define CORE_FXCRT_INCLUDE_FX_BASIC_H_ | 8 #define CORE_FXCRT_INCLUDE_FX_BASIC_H_ |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0; | 641 return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0; |
| 642 } | 642 } |
| 643 | 643 |
| 644 protected: | 644 protected: |
| 645 uint32_t m_BitPos; | 645 uint32_t m_BitPos; |
| 646 | 646 |
| 647 uint32_t m_BitSize; | 647 uint32_t m_BitSize; |
| 648 | 648 |
| 649 const uint8_t* m_pData; | 649 const uint8_t* m_pData; |
| 650 }; | 650 }; |
| 651 | |
| 651 template <class ObjClass> | 652 template <class ObjClass> |
| 652 class CFX_CountRef { | 653 class CFX_CountRef { |
| 653 public: | 654 public: |
| 654 typedef CFX_CountRef<ObjClass> Ref; | 655 using Ref = CFX_CountRef<ObjClass>; |
| 655 | 656 |
| 656 class CountedObj : public ObjClass { | 657 class CountedObj : public ObjClass { |
| 657 public: | 658 public: |
| 658 CountedObj() {} | 659 CountedObj() {} |
| 659 | |
| 660 CountedObj(const CountedObj& src) : ObjClass(src) {} | 660 CountedObj(const CountedObj& src) : ObjClass(src) {} |
| 661 | 661 |
| 662 int m_RefCount; | 662 int m_RefCount; |
| 663 }; | 663 }; |
| 664 | 664 |
| 665 CFX_CountRef() { m_pObject = nullptr; } | 665 CFX_CountRef() : m_pObject(nullptr) {} |
| 666 | 666 CFX_CountRef(const Ref& ref) : m_pObject(ref.m_pObject) { |
| 667 CFX_CountRef(const Ref& ref) { | 667 if (m_pObject) |
| 668 m_pObject = ref.m_pObject; | |
| 669 if (m_pObject) { | |
| 670 m_pObject->m_RefCount++; | 668 m_pObject->m_RefCount++; |
| 671 } | |
| 672 } | 669 } |
| 673 | 670 |
| 674 ~CFX_CountRef() { SetNull(); } | 671 ~CFX_CountRef() { SetNull(); } |
| 675 | 672 |
| 676 ObjClass* New() { | 673 ObjClass* New() { |
| 677 SetNull(); | 674 SetNull(); |
| 678 m_pObject = new CountedObj; | 675 m_pObject = new CountedObj; |
| 679 m_pObject->m_RefCount = 1; | 676 m_pObject->m_RefCount = 1; |
| 680 return m_pObject; | 677 return m_pObject; |
| 681 } | 678 } |
| 682 | 679 |
| 683 void operator=(const Ref& ref) { | 680 void operator=(const Ref& ref) { |
| 684 if (ref.m_pObject) | 681 if (ref.m_pObject) |
| 685 ref.m_pObject->m_RefCount++; | 682 ref.m_pObject->m_RefCount++; |
| 686 SetNull(); | 683 SetNull(); |
| 687 m_pObject = ref.m_pObject; | 684 m_pObject = ref.m_pObject; |
| 688 } | 685 } |
| 689 | 686 |
| 687 bool IsNull() const { return !m_pObject; } | |
| 688 bool NotNull() const { return !IsNull(); } | |
|
dsinclair
2016/06/08 18:45:54
Can we have a followup to remove this? Seems just
| |
| 689 | |
| 690 const ObjClass* GetObject() const { return m_pObject; } | 690 const ObjClass* GetObject() const { return m_pObject; } |
| 691 | |
| 692 operator const ObjClass*() const { return m_pObject; } | |
| 693 | |
| 694 FX_BOOL IsNull() const { return !m_pObject; } | |
| 695 | |
| 696 FX_BOOL NotNull() const { return !IsNull(); } | |
| 697 | |
| 698 ObjClass* GetModify() { | 691 ObjClass* GetModify() { |
| 699 if (!m_pObject) { | 692 if (!m_pObject) { |
| 700 m_pObject = new CountedObj; | 693 m_pObject = new CountedObj; |
| 701 m_pObject->m_RefCount = 1; | 694 m_pObject->m_RefCount = 1; |
| 702 } else if (m_pObject->m_RefCount > 1) { | 695 } else if (m_pObject->m_RefCount > 1) { |
| 703 m_pObject->m_RefCount--; | 696 m_pObject->m_RefCount--; |
| 704 CountedObj* pOldObject = m_pObject; | 697 CountedObj* pOldObject = m_pObject; |
| 705 m_pObject = new CountedObj(*pOldObject); | 698 m_pObject = new CountedObj(*pOldObject); |
| 706 m_pObject->m_RefCount = 1; | 699 m_pObject->m_RefCount = 1; |
| 707 } | 700 } |
| 708 return m_pObject; | 701 return m_pObject; |
| 709 } | 702 } |
| 710 | 703 |
| 711 void SetNull() { | 704 void SetNull() { |
| 712 if (!m_pObject) { | 705 if (!m_pObject) { |
| 713 return; | 706 return; |
| 714 } | 707 } |
| 715 m_pObject->m_RefCount--; | 708 m_pObject->m_RefCount--; |
| 716 if (m_pObject->m_RefCount <= 0) { | 709 if (m_pObject->m_RefCount <= 0) { |
| 717 delete m_pObject; | 710 delete m_pObject; |
| 718 } | 711 } |
| 719 m_pObject = nullptr; | 712 m_pObject = nullptr; |
| 720 } | 713 } |
| 721 | 714 |
| 722 bool operator==(const Ref& ref) const { return m_pObject == ref.m_pObject; } | 715 bool operator==(const Ref& ref) const { return m_pObject == ref.m_pObject; } |
| 723 | 716 |
| 724 protected: | 717 protected: |
| 725 CountedObj* m_pObject; | 718 CountedObj* m_pObject; |
| 726 }; | 719 }; |
| 720 | |
| 727 class IFX_Pause { | 721 class IFX_Pause { |
| 728 public: | 722 public: |
| 729 virtual ~IFX_Pause() {} | 723 virtual ~IFX_Pause() {} |
| 730 virtual FX_BOOL NeedToPauseNow() = 0; | 724 virtual FX_BOOL NeedToPauseNow() = 0; |
| 731 }; | 725 }; |
| 732 | 726 |
| 733 template <typename T> | 727 template <typename T> |
| 734 class CFX_AutoRestorer { | 728 class CFX_AutoRestorer { |
| 735 public: | 729 public: |
| 736 explicit CFX_AutoRestorer(T* location) | 730 explicit CFX_AutoRestorer(T* location) |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 925 FX_FLOAT e; | 919 FX_FLOAT e; |
| 926 FX_FLOAT f; | 920 FX_FLOAT f; |
| 927 FX_FLOAT g; | 921 FX_FLOAT g; |
| 928 FX_FLOAT h; | 922 FX_FLOAT h; |
| 929 FX_FLOAT i; | 923 FX_FLOAT i; |
| 930 }; | 924 }; |
| 931 | 925 |
| 932 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits); | 926 uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits); |
| 933 | 927 |
| 934 #endif // CORE_FXCRT_INCLUDE_FX_BASIC_H_ | 928 #endif // CORE_FXCRT_INCLUDE_FX_BASIC_H_ |
| OLD | NEW |