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

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp

Issue 2275703002: Make indirect object holder private. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@indirect_naming
Patch Set: Created 4 years, 3 months 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 #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h"
11 11
12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser) 12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser)
13 : m_pParser(pParser), m_LastObjNum(0) { 13 : m_pParser(pParser), m_LastObjNum(0) {
14 if (pParser) 14 if (pParser)
15 m_LastObjNum = m_pParser->GetLastObjNum(); 15 m_LastObjNum = m_pParser->GetLastObjNum();
16 } 16 }
17 17
18 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { 18 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {
19 for (const auto& pair : m_IndirectObjs) 19 for (const auto& pair : m_IndirectObjs)
20 pair.second->Destroy(); 20 pair.second->Destroy();
21 } 21 }
22 22
23 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(
24 uint32_t objnum) const {
25 auto it = m_IndirectObjs.find(objnum);
26 return it != m_IndirectObjs.end() ? it->second : nullptr;
27 }
28
23 CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject( 29 CPDF_Object* CPDF_IndirectObjectHolder::GetOrParseIndirectObject(
24 uint32_t objnum) { 30 uint32_t objnum) {
25 if (objnum == 0) 31 if (objnum == 0)
26 return nullptr; 32 return nullptr;
27 33
28 auto it = m_IndirectObjs.find(objnum); 34 CPDF_Object* pObj = GetIndirectObject(objnum);
29 if (it != m_IndirectObjs.end()) 35 if (pObj)
30 return it->second->GetObjNum() != CPDF_Object::kInvalidObjNum ? it->second 36 return pObj->GetObjNum() != CPDF_Object::kInvalidObjNum ? pObj : nullptr;
31 : nullptr;
32 37
33 if (!m_pParser) 38 if (!m_pParser)
34 return nullptr; 39 return nullptr;
35 40
36 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum); 41 pObj = m_pParser->ParseIndirectObject(this, objnum);
37 if (!pObj) 42 if (!pObj)
38 return nullptr; 43 return nullptr;
39 44
40 pObj->m_ObjNum = objnum; 45 pObj->m_ObjNum = objnum;
41 m_LastObjNum = std::max(m_LastObjNum, objnum); 46 m_LastObjNum = std::max(m_LastObjNum, objnum);
42 if (m_IndirectObjs[objnum]) 47 if (m_IndirectObjs[objnum])
43 m_IndirectObjs[objnum]->Destroy(); 48 m_IndirectObjs[objnum]->Destroy();
44 49
45 m_IndirectObjs[objnum] = pObj; 50 m_IndirectObjs[objnum] = pObj;
46 return pObj; 51 return pObj;
47 } 52 }
48 53
49 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { 54 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) {
50 if (pObj->m_ObjNum) 55 if (pObj->m_ObjNum)
51 return pObj->m_ObjNum; 56 return pObj->m_ObjNum;
52 57
53 m_LastObjNum++; 58 m_LastObjNum++;
54 m_IndirectObjs[m_LastObjNum] = pObj; 59 m_IndirectObjs[m_LastObjNum] = pObj;
55 pObj->m_ObjNum = m_LastObjNum; 60 pObj->m_ObjNum = m_LastObjNum;
56 return m_LastObjNum; 61 return m_LastObjNum;
57 } 62 }
58 63
59 bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration( 64 bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration(
60 uint32_t objnum, 65 uint32_t objnum,
61 CPDF_Object* pObj) { 66 CPDF_Object* pObj) {
62 if (!objnum || !pObj) 67 if (!objnum || !pObj)
63 return false; 68 return false;
64 69
65 auto it = m_IndirectObjs.find(objnum); 70 CPDF_Object* pOldObj = GetIndirectObject(objnum);
66 if (it != m_IndirectObjs.end()) { 71 if (pOldObj) {
67 if (pObj->GetGenNum() <= it->second->GetGenNum()) { 72 if (pObj->GetGenNum() <= pOldObj->GetGenNum()) {
68 pObj->Destroy(); 73 pObj->Destroy();
69 return false; 74 return false;
70 } 75 }
71 it->second->Destroy(); 76 pOldObj->Destroy();
72 } 77 }
73 pObj->m_ObjNum = objnum; 78 pObj->m_ObjNum = objnum;
74 m_IndirectObjs[objnum] = pObj; 79 m_IndirectObjs[objnum] = pObj;
75 m_LastObjNum = std::max(m_LastObjNum, objnum); 80 m_LastObjNum = std::max(m_LastObjNum, objnum);
76 return true; 81 return true;
77 } 82 }
78 83
79 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { 84 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) {
80 auto it = m_IndirectObjs.find(objnum); 85 CPDF_Object* pObj = GetIndirectObject(objnum);
81 if (it == m_IndirectObjs.end() || 86 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum)
82 it->second->GetObjNum() == CPDF_Object::kInvalidObjNum) {
83 return; 87 return;
84 } 88
85 it->second->Destroy(); 89 pObj->Destroy();
86 m_IndirectObjs.erase(it); 90 m_IndirectObjs.erase(objnum);
87 } 91 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_document.cpp ('k') | core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698