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

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

Issue 2509123002: Make CPDF_Object subclass constructors intern strings (Closed)
Patch Set: finish 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 #include <type_traits>
12 13
14 #include "core/fpdfapi/parser/cpdf_object.h"
13 #include "core/fxcrt/cfx_string_pool_template.h" 15 #include "core/fxcrt/cfx_string_pool_template.h"
14 #include "core/fxcrt/cfx_weak_ptr.h" 16 #include "core/fxcrt/cfx_weak_ptr.h"
15 #include "core/fxcrt/fx_system.h" 17 #include "core/fxcrt/fx_system.h"
16 #include "third_party/base/ptr_util.h" 18 #include "third_party/base/ptr_util.h"
17 19
18 class CPDF_Object;
19
20 class CPDF_IndirectObjectHolder { 20 class CPDF_IndirectObjectHolder {
21 public: 21 public:
22 using const_iterator = 22 using const_iterator =
23 std::map<uint32_t, std::unique_ptr<CPDF_Object>>::const_iterator; 23 std::map<uint32_t, std::unique_ptr<CPDF_Object>>::const_iterator;
24 24
25 CPDF_IndirectObjectHolder(); 25 CPDF_IndirectObjectHolder();
26 virtual ~CPDF_IndirectObjectHolder(); 26 virtual ~CPDF_IndirectObjectHolder();
27 27
28 CPDF_Object* GetIndirectObject(uint32_t objnum) const; 28 CPDF_Object* GetIndirectObject(uint32_t objnum) const;
29 CPDF_Object* GetOrParseIndirectObject(uint32_t objnum); 29 CPDF_Object* GetOrParseIndirectObject(uint32_t objnum);
30 void DeleteIndirectObject(uint32_t objnum); 30 void DeleteIndirectObject(uint32_t objnum);
31 31
32 // Creates and adds a new object owned by the indirect object holder, 32 // Creates and adds a new object owned by the indirect object holder,
33 // and returns an unowned pointer to it. 33 // and returns an unowned pointer to it. We have a special case to
34 // handle objects that can intern strings from our ByteStringPool.
34 template <typename T, typename... Args> 35 template <typename T, typename... Args>
35 T* NewIndirect(Args... args) { 36 typename std::enable_if<!CanInternStrings<T>::value, T*>::type NewIndirect(
37 Args... args) {
36 return static_cast<T*>(AddIndirectObject(pdfium::MakeUnique<T>(args...))); 38 return static_cast<T*>(AddIndirectObject(pdfium::MakeUnique<T>(args...)));
37 } 39 }
40 template <typename T, typename... Args>
41 typename std::enable_if<CanInternStrings<T>::value, T*>::type NewIndirect(
42 Args... args) {
43 return static_cast<T*>(
44 AddIndirectObject(pdfium::MakeUnique<T>(m_pByteStringPool, args...)));
45 }
38 46
39 // Takes ownership of |pObj|, returns unowned pointer to it. 47 // Takes ownership of |pObj|, returns unowned pointer to it.
40 CPDF_Object* AddIndirectObject(std::unique_ptr<CPDF_Object> pObj); 48 CPDF_Object* AddIndirectObject(std::unique_ptr<CPDF_Object> pObj);
41 49
42 // Always takes ownership of |pObj|, return true if higher generation number. 50 // Always takes ownership of |pObj|, return true if higher generation number.
43 bool ReplaceIndirectObjectIfHigherGeneration( 51 bool ReplaceIndirectObjectIfHigherGeneration(
44 uint32_t objnum, 52 uint32_t objnum,
45 std::unique_ptr<CPDF_Object> pObj); 53 std::unique_ptr<CPDF_Object> pObj);
46 54
47 uint32_t GetLastObjNum() const { return m_LastObjNum; } 55 uint32_t GetLastObjNum() const { return m_LastObjNum; }
48 void SetLastObjNum(uint32_t objnum) { m_LastObjNum = objnum; } 56 void SetLastObjNum(uint32_t objnum) { m_LastObjNum = objnum; }
49 57
50 CFX_WeakPtr<CFX_ByteStringPool> GetByteStringPool() const { 58 CFX_WeakPtr<CFX_ByteStringPool> GetByteStringPool() const {
51 return m_pByteStringPool; 59 return m_pByteStringPool;
52 } 60 }
53 61
54 const_iterator begin() const { return m_IndirectObjs.begin(); } 62 const_iterator begin() const { return m_IndirectObjs.begin(); }
55 const_iterator end() const { return m_IndirectObjs.end(); } 63 const_iterator end() const { return m_IndirectObjs.end(); }
56 64
57 protected: 65 protected:
58 virtual std::unique_ptr<CPDF_Object> ParseIndirectObject(uint32_t objnum); 66 virtual std::unique_ptr<CPDF_Object> ParseIndirectObject(uint32_t objnum);
59 67
60 private: 68 private:
61 uint32_t m_LastObjNum; 69 uint32_t m_LastObjNum;
62 std::map<uint32_t, std::unique_ptr<CPDF_Object>> m_IndirectObjs; 70 std::map<uint32_t, std::unique_ptr<CPDF_Object>> m_IndirectObjs;
63 CFX_WeakPtr<CFX_ByteStringPool> m_pByteStringPool; 71 CFX_WeakPtr<CFX_ByteStringPool> m_pByteStringPool;
64 }; 72 };
65 73
66 #endif // CORE_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_ 74 #endif // CORE_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698