summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_reference.cpp
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2016-10-04 11:55:50 -0700
committerCommit bot <commit-bot@chromium.org>2016-10-04 11:55:51 -0700
commit488b7ad845d6de212d89cd957303b294ecfa5922 (patch)
treeadfdd2327724bd3597a1a7614bbe29a01a0c8dc0 /core/fpdfapi/parser/cpdf_reference.cpp
parent41872fa5ac7448a50f66ad56d7bde8d1aa77db4b (diff)
downloadpdfium-488b7ad845d6de212d89cd957303b294ecfa5922.tar.xz
Move core/fpdfapi/fpdf_parser to core/fpdfapi/parser
BUG=pdfium:603 Review-Url: https://codereview.chromium.org/2392603004
Diffstat (limited to 'core/fpdfapi/parser/cpdf_reference.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_reference.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/core/fpdfapi/parser/cpdf_reference.cpp b/core/fpdfapi/parser/cpdf_reference.cpp
new file mode 100644
index 0000000000..a9cdf54855
--- /dev/null
+++ b/core/fpdfapi/parser/cpdf_reference.cpp
@@ -0,0 +1,83 @@
+// 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/fpdfapi/parser/cpdf_reference.h"
+
+#include "core/fpdfapi/parser/cpdf_indirect_object_holder.h"
+#include "third_party/base/stl_util.h"
+
+CPDF_Reference::CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, int objnum)
+ : m_pObjList(pDoc), m_RefObjNum(objnum) {}
+
+CPDF_Reference::~CPDF_Reference() {}
+
+CPDF_Object::Type CPDF_Reference::GetType() const {
+ return REFERENCE;
+}
+
+CFX_ByteString CPDF_Reference::GetString() const {
+ CPDF_Object* obj = SafeGetDirect();
+ return obj ? obj->GetString() : CFX_ByteString();
+}
+
+FX_FLOAT CPDF_Reference::GetNumber() const {
+ CPDF_Object* obj = SafeGetDirect();
+ return obj ? obj->GetNumber() : 0;
+}
+
+int CPDF_Reference::GetInteger() const {
+ CPDF_Object* obj = SafeGetDirect();
+ return obj ? obj->GetInteger() : 0;
+}
+
+CPDF_Dictionary* CPDF_Reference::GetDict() const {
+ CPDF_Object* obj = SafeGetDirect();
+ return obj ? obj->GetDict() : nullptr;
+}
+
+bool CPDF_Reference::IsReference() const {
+ return true;
+}
+
+CPDF_Reference* CPDF_Reference::AsReference() {
+ return this;
+}
+
+const CPDF_Reference* CPDF_Reference::AsReference() const {
+ return this;
+}
+
+CPDF_Object* CPDF_Reference::Clone() const {
+ return CloneObjectNonCyclic(false);
+}
+
+CPDF_Object* CPDF_Reference::CloneNonCyclic(
+ bool bDirect,
+ std::set<const CPDF_Object*>* pVisited) const {
+ pVisited->insert(this);
+ if (bDirect) {
+ auto* pDirect = GetDirect();
+ return pDirect && !pdfium::ContainsKey(*pVisited, pDirect)
+ ? pDirect->CloneNonCyclic(true, pVisited)
+ : nullptr;
+ }
+ return new CPDF_Reference(m_pObjList, m_RefObjNum);
+}
+
+CPDF_Object* CPDF_Reference::SafeGetDirect() const {
+ CPDF_Object* obj = GetDirect();
+ return (obj && !obj->IsReference()) ? obj : nullptr;
+}
+
+void CPDF_Reference::SetRef(CPDF_IndirectObjectHolder* pDoc, uint32_t objnum) {
+ m_pObjList = pDoc;
+ m_RefObjNum = objnum;
+}
+
+CPDF_Object* CPDF_Reference::GetDirect() const {
+ return m_pObjList ? m_pObjList->GetOrParseIndirectObject(m_RefObjNum)
+ : nullptr;
+}