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

Unified Diff: core/src/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp

Issue 1776913007: Split fpdf_parser_objects.cpp into per-class .cpp/.h files. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Address comments Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp ('k') | core/src/fpdfapi/fpdf_parser/cpdf_name.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
diff --git a/core/src/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp b/core/src/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b1606f9857fccf041a4b5718070cd55f90b4204a
--- /dev/null
+++ b/core/src/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp
@@ -0,0 +1,80 @@
+// Copyright 2016 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "core/include/fpdfapi/cpdf_indirect_object_holder.h"
+#include "core/include/fpdfapi/cpdf_object.h"
+#include "core/include/fpdfapi/cpdf_parser.h"
+
+CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser)
+ : m_pParser(pParser), m_LastObjNum(0) {
+ if (pParser)
+ m_LastObjNum = m_pParser->GetLastObjNum();
+}
+
+CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {
+ for (const auto& pair : m_IndirectObjs)
+ pair.second->Destroy();
+}
+
+CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(FX_DWORD objnum) {
+ if (objnum == 0)
+ return nullptr;
+
+ auto it = m_IndirectObjs.find(objnum);
+ if (it != m_IndirectObjs.end())
+ return it->second->GetObjNum() != -1 ? it->second : nullptr;
+
+ if (!m_pParser)
+ return nullptr;
+
+ CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum);
+ if (!pObj)
+ return nullptr;
+
+ pObj->m_ObjNum = objnum;
+ m_LastObjNum = std::max(m_LastObjNum, objnum);
+ if (m_IndirectObjs[objnum])
+ m_IndirectObjs[objnum]->Destroy();
+
+ m_IndirectObjs[objnum] = pObj;
+ return pObj;
+}
+
+FX_DWORD CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) {
+ if (pObj->m_ObjNum)
+ return pObj->m_ObjNum;
+
+ m_LastObjNum++;
+ m_IndirectObjs[m_LastObjNum] = pObj;
+ pObj->m_ObjNum = m_LastObjNum;
+ return m_LastObjNum;
+}
+
+void CPDF_IndirectObjectHolder::ReleaseIndirectObject(FX_DWORD objnum) {
+ auto it = m_IndirectObjs.find(objnum);
+ if (it == m_IndirectObjs.end() || it->second->GetObjNum() == -1)
+ return;
+ it->second->Destroy();
+ m_IndirectObjs.erase(it);
+}
+
+FX_BOOL CPDF_IndirectObjectHolder::InsertIndirectObject(FX_DWORD objnum,
+ CPDF_Object* pObj) {
+ if (!objnum || !pObj)
+ return FALSE;
+ auto it = m_IndirectObjs.find(objnum);
+ if (it != m_IndirectObjs.end()) {
+ if (pObj->GetGenNum() <= it->second->GetGenNum()) {
+ pObj->Destroy();
+ return FALSE;
+ }
+ it->second->Destroy();
+ }
+ pObj->m_ObjNum = objnum;
+ m_IndirectObjs[objnum] = pObj;
+ m_LastObjNum = std::max(m_LastObjNum, objnum);
+ return TRUE;
+}
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp ('k') | core/src/fpdfapi/fpdf_parser/cpdf_name.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698