Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: core/fpdfapi/parser/cpdf_indirect_object_holder.h

Issue 2489283003: Make AddIndirectObject() take a unique_ptr. (Closed)
Patch Set: Fix test Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/fxcrt/fx_system.h" 13 #include "core/fxcrt/fx_system.h"
14 #include "third_party/base/ptr_util.h"
14 15
15 class CPDF_Object; 16 class CPDF_Object;
16 17
17 class CPDF_IndirectObjectHolder { 18 class CPDF_IndirectObjectHolder {
18 public: 19 public:
19 using const_iterator = 20 using const_iterator =
20 std::map<uint32_t, std::unique_ptr<CPDF_Object>>::const_iterator; 21 std::map<uint32_t, std::unique_ptr<CPDF_Object>>::const_iterator;
21 22
22 CPDF_IndirectObjectHolder(); 23 CPDF_IndirectObjectHolder();
23 virtual ~CPDF_IndirectObjectHolder(); 24 virtual ~CPDF_IndirectObjectHolder();
24 25
25 CPDF_Object* GetIndirectObject(uint32_t objnum) const; 26 CPDF_Object* GetIndirectObject(uint32_t objnum) const;
26 CPDF_Object* GetOrParseIndirectObject(uint32_t objnum); 27 CPDF_Object* GetOrParseIndirectObject(uint32_t objnum);
27 void DeleteIndirectObject(uint32_t objnum); 28 void DeleteIndirectObject(uint32_t objnum);
28 29
29 // Take ownership of |pObj|. 30 // Creates and adds a new ojbect, returns unowned pointer to it.
dsinclair 2016/11/15 18:55:51 Returns unowned pointer is a bit confusing. Ouowne
Tom Sepez 2016/11/15 19:15:16 Done.
30 uint32_t AddIndirectObject(CPDF_Object* pObj); 31 template <typename T, typename... Args>
32 T* NewIndirect(Args... args) {
33 return static_cast<T*>(AddIndirectObject(pdfium::MakeUnique<T>(args...)));
34 }
35
36 // Takes ownership of |pObj|, returns unowned pointer to it.
37 CPDF_Object* AddIndirectObject(std::unique_ptr<CPDF_Object> pObj);
38
39 // Always takes ownership of |pObj|, return true if higher generation number.
31 bool ReplaceIndirectObjectIfHigherGeneration( 40 bool ReplaceIndirectObjectIfHigherGeneration(
32 uint32_t objnum, 41 uint32_t objnum,
33 std::unique_ptr<CPDF_Object> pObj); 42 std::unique_ptr<CPDF_Object> pObj);
34 43
35 uint32_t GetLastObjNum() const { return m_LastObjNum; } 44 uint32_t GetLastObjNum() const { return m_LastObjNum; }
36 void SetLastObjNum(uint32_t objnum) { m_LastObjNum = objnum; } 45 void SetLastObjNum(uint32_t objnum) { m_LastObjNum = objnum; }
37 46
38 const_iterator begin() const { return m_IndirectObjs.begin(); } 47 const_iterator begin() const { return m_IndirectObjs.begin(); }
39 const_iterator end() const { return m_IndirectObjs.end(); } 48 const_iterator end() const { return m_IndirectObjs.end(); }
40 49
41 protected: 50 protected:
42 virtual std::unique_ptr<CPDF_Object> ParseIndirectObject(uint32_t objnum); 51 virtual std::unique_ptr<CPDF_Object> ParseIndirectObject(uint32_t objnum);
43 52
44 private: 53 private:
45 uint32_t m_LastObjNum; 54 uint32_t m_LastObjNum;
46 std::map<uint32_t, std::unique_ptr<CPDF_Object>> m_IndirectObjs; 55 std::map<uint32_t, std::unique_ptr<CPDF_Object>> m_IndirectObjs;
47 }; 56 };
48 57
49 #endif // CORE_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_ 58 #endif // CORE_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698