| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_ | 7 #ifndef CORE_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_ |
| 8 #define CORE_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_ | 8 #define CORE_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_ |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "core/fpdfapi/parser/cpdf_object.h" |
| 14 #include "core/fxcrt/cfx_string_pool_template.h" |
| 15 #include "core/fxcrt/cfx_weak_ptr.h" |
| 13 #include "core/fxcrt/fx_system.h" | 16 #include "core/fxcrt/fx_system.h" |
| 14 | 17 |
| 15 class CPDF_Object; | 18 class CPDF_Array; |
| 19 class CPDF_Dictionary; |
| 20 class CPDF_Stream; |
| 16 | 21 |
| 17 class CPDF_IndirectObjectHolder { | 22 class CPDF_IndirectObjectHolder { |
| 18 public: | 23 public: |
| 19 using const_iterator = | 24 using const_iterator = |
| 20 std::map<uint32_t, std::unique_ptr<CPDF_Object>>::const_iterator; | 25 std::map<uint32_t, std::unique_ptr<CPDF_Object>>::const_iterator; |
| 21 | 26 |
| 22 CPDF_IndirectObjectHolder(); | 27 CPDF_IndirectObjectHolder(); |
| 23 virtual ~CPDF_IndirectObjectHolder(); | 28 virtual ~CPDF_IndirectObjectHolder(); |
| 24 | 29 |
| 25 CPDF_Object* GetIndirectObject(uint32_t objnum) const; | 30 CPDF_Object* GetIndirectObject(uint32_t objnum) const; |
| 26 CPDF_Object* GetOrParseIndirectObject(uint32_t objnum); | 31 CPDF_Object* GetOrParseIndirectObject(uint32_t objnum); |
| 27 void ReleaseIndirectObject(uint32_t objnum); | 32 void DeleteIndirectObject(uint32_t objnum); |
| 28 | 33 |
| 29 // Take ownership of |pObj|. | 34 // Take ownership of |pObj|, returns unowned pointer to it. |
| 30 uint32_t AddIndirectObject(CPDF_Object* pObj); | 35 CPDF_Object* AddIndirectObject(UniqueObject pObj); |
| 36 |
| 37 // Adds and owns a new object, returns unowned pointer to it. |
| 38 CPDF_Array* AddIndirectArray(); |
| 39 CPDF_Dictionary* AddIndirectDictionary(); |
| 40 CPDF_Dictionary* AddIndirectDictionary( |
| 41 const CFX_WeakPtr<CFX_ByteStringPool>& pPool); |
| 42 CPDF_Stream* AddIndirectStream(); |
| 43 CPDF_Stream* AddIndirectStream(uint8_t* pData, |
| 44 uint32_t size, |
| 45 CPDF_Dictionary* pDict); |
| 46 |
| 31 bool ReplaceIndirectObjectIfHigherGeneration(uint32_t objnum, | 47 bool ReplaceIndirectObjectIfHigherGeneration(uint32_t objnum, |
| 32 CPDF_Object* pObj); | 48 UniqueObject pObj); |
| 33 | 49 |
| 34 uint32_t GetLastObjNum() const { return m_LastObjNum; } | 50 uint32_t GetLastObjNum() const { return m_LastObjNum; } |
| 35 void SetLastObjNum(uint32_t objnum) { m_LastObjNum = objnum; } | 51 void SetLastObjNum(uint32_t objnum) { m_LastObjNum = objnum; } |
| 36 | 52 |
| 37 const_iterator begin() const { return m_IndirectObjs.begin(); } | 53 const_iterator begin() const { return m_IndirectObjs.begin(); } |
| 38 const_iterator end() const { return m_IndirectObjs.end(); } | 54 const_iterator end() const { return m_IndirectObjs.end(); } |
| 39 | 55 |
| 40 protected: | 56 protected: |
| 41 virtual CPDF_Object* ParseIndirectObject(uint32_t objnum); | 57 virtual CPDF_Object* ParseIndirectObject(uint32_t objnum); |
| 42 | 58 |
| 43 private: | 59 private: |
| 44 uint32_t m_LastObjNum; | 60 uint32_t m_LastObjNum; |
| 61 |
| 62 // Ordinary deleter, not Release(). |
| 45 std::map<uint32_t, std::unique_ptr<CPDF_Object>> m_IndirectObjs; | 63 std::map<uint32_t, std::unique_ptr<CPDF_Object>> m_IndirectObjs; |
| 46 }; | 64 }; |
| 47 | 65 |
| 48 #endif // CORE_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_ | 66 #endif // CORE_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_ |
| OLD | NEW |