summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-16 14:45:46 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-16 14:45:46 -0800
commitd5b81ce5722398cc8c259d76e7cd1a5ddc2c562f (patch)
tree3daa9b7e6c691a358b83ac9797bffe27753b2964 /core/fpdfdoc
parentad3cd2aeff15bd31aa38544063075d910ac63823 (diff)
downloadpdfium-d5b81ce5722398cc8c259d76e7cd1a5ddc2c562f.tar.xz
Return unique_ptr<> from IPDF_StructTree
Delete some dead code in the process. Review-Url: https://codereview.chromium.org/2585873002
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/doc_tagged.cpp47
-rw-r--r--core/fpdfdoc/fpdf_tagged.h8
-rw-r--r--core/fpdfdoc/tagged_int.h1
3 files changed, 13 insertions, 43 deletions
diff --git a/core/fpdfdoc/doc_tagged.cpp b/core/fpdfdoc/doc_tagged.cpp
index 10c573b5ca..39feaeef88 100644
--- a/core/fpdfdoc/doc_tagged.cpp
+++ b/core/fpdfdoc/doc_tagged.cpp
@@ -5,6 +5,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include <map>
+#include <memory>
+#include <utility>
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
@@ -16,6 +18,7 @@
#include "core/fpdfdoc/cpdf_numbertree.h"
#include "core/fpdfdoc/fpdf_tagged.h"
#include "core/fpdfdoc/tagged_int.h"
+#include "third_party/base/ptr_util.h"
namespace {
@@ -30,24 +33,15 @@ bool IsTagged(const CPDF_Document* pDoc) {
} // namespace
// static
-IPDF_StructTree* IPDF_StructTree::LoadPage(const CPDF_Document* pDoc,
- const CPDF_Dictionary* pPageDict) {
+std::unique_ptr<IPDF_StructTree> IPDF_StructTree::LoadPage(
+ const CPDF_Document* pDoc,
+ const CPDF_Dictionary* pPageDict) {
if (!IsTagged(pDoc))
return nullptr;
- CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc);
+ auto pTree = pdfium::MakeUnique<CPDF_StructTreeImpl>(pDoc);
pTree->LoadPageTree(pPageDict);
- return pTree;
-}
-
-// static.
-IPDF_StructTree* IPDF_StructTree::LoadDoc(const CPDF_Document* pDoc) {
- if (!IsTagged(pDoc))
- return nullptr;
-
- CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc);
- pTree->LoadDocTree();
- return pTree;
+ return std::move(pTree);
}
CPDF_StructTreeImpl::CPDF_StructTreeImpl(const CPDF_Document* pDoc)
@@ -65,31 +59,6 @@ IPDF_StructElement* CPDF_StructTreeImpl::GetTopElement(int i) const {
return m_Kids[i].Get();
}
-void CPDF_StructTreeImpl::LoadDocTree() {
- m_pPage = nullptr;
- if (!m_pTreeRoot)
- return;
-
- CPDF_Object* pKids = m_pTreeRoot->GetDirectObjectFor("K");
- if (!pKids)
- return;
-
- if (CPDF_Dictionary* pDict = pKids->AsDictionary()) {
- m_Kids.push_back(CFX_RetainPtr<CPDF_StructElementImpl>(
- new CPDF_StructElementImpl(this, nullptr, pDict)));
- return;
- }
-
- CPDF_Array* pArray = pKids->AsArray();
- if (!pArray)
- return;
-
- for (size_t i = 0; i < pArray->GetCount(); i++) {
- m_Kids.push_back(CFX_RetainPtr<CPDF_StructElementImpl>(
- new CPDF_StructElementImpl(this, nullptr, pArray->GetDictAt(i))));
- }
-}
-
void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) {
m_pPage = pPageDict;
if (!m_pTreeRoot)
diff --git a/core/fpdfdoc/fpdf_tagged.h b/core/fpdfdoc/fpdf_tagged.h
index 716e626743..aa697ca248 100644
--- a/core/fpdfdoc/fpdf_tagged.h
+++ b/core/fpdfdoc/fpdf_tagged.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFDOC_FPDF_TAGGED_H_
#define CORE_FPDFDOC_FPDF_TAGGED_H_
+#include <memory>
+
#include "core/fxge/fx_dib.h"
class CPDF_Dictionary;
@@ -15,9 +17,9 @@ class IPDF_StructElement;
class IPDF_StructTree {
public:
- static IPDF_StructTree* LoadDoc(const CPDF_Document* pDoc);
- static IPDF_StructTree* LoadPage(const CPDF_Document* pDoc,
- const CPDF_Dictionary* pPageDict);
+ static std::unique_ptr<IPDF_StructTree> LoadPage(
+ const CPDF_Document* pDoc,
+ const CPDF_Dictionary* pPageDict);
virtual ~IPDF_StructTree() {}
diff --git a/core/fpdfdoc/tagged_int.h b/core/fpdfdoc/tagged_int.h
index 43e43f1ed6..03f1c40ad6 100644
--- a/core/fpdfdoc/tagged_int.h
+++ b/core/fpdfdoc/tagged_int.h
@@ -26,7 +26,6 @@ class CPDF_StructTreeImpl final : public IPDF_StructTree {
int CountTopElements() const override;
IPDF_StructElement* GetTopElement(int i) const override;
- void LoadDocTree();
void LoadPageTree(const CPDF_Dictionary* pPageDict);
CPDF_StructElementImpl* AddPageNode(
CPDF_Dictionary* pElement,