diff options
author | Lei Zhang <thestig@chromium.org> | 2018-05-09 22:02:32 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-05-09 22:02:32 +0000 |
commit | 7e28208d26764438bef62e051d2e1fed13e1e0ec (patch) | |
tree | 781d3e250a4fd3af3eb16da299b56938b21a7414 /core/fpdfapi/parser/cpdf_reference.cpp | |
parent | 52489ee8114cf476342231be610e75b324290920 (diff) | |
download | pdfium-7e28208d26764438bef62e051d2e1fed13e1e0ec.tar.xz |
Add proper const/non-const versions of CPDF_Object methods.
Instead of having const methods that return non-const pointers.
BUG=pdfium:234
Change-Id: I598e9b4f267f702e2e71001cfe3aa3c9e9d8c12f
Reviewed-on: https://pdfium-review.googlesource.com/32182
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_reference.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_reference.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/core/fpdfapi/parser/cpdf_reference.cpp b/core/fpdfapi/parser/cpdf_reference.cpp index 2ca0bddc4f..3f45a96c6b 100644 --- a/core/fpdfapi/parser/cpdf_reference.cpp +++ b/core/fpdfapi/parser/cpdf_reference.cpp @@ -21,25 +21,30 @@ CPDF_Object::Type CPDF_Reference::GetType() const { } ByteString CPDF_Reference::GetString() const { - CPDF_Object* obj = SafeGetDirect(); + const CPDF_Object* obj = SafeGetDirect(); return obj ? obj->GetString() : ByteString(); } float CPDF_Reference::GetNumber() const { - CPDF_Object* obj = SafeGetDirect(); + const CPDF_Object* obj = SafeGetDirect(); return obj ? obj->GetNumber() : 0; } int CPDF_Reference::GetInteger() const { - CPDF_Object* obj = SafeGetDirect(); + const CPDF_Object* obj = SafeGetDirect(); return obj ? obj->GetInteger() : 0; } -CPDF_Dictionary* CPDF_Reference::GetDict() const { +CPDF_Dictionary* CPDF_Reference::GetDict() { CPDF_Object* obj = SafeGetDirect(); return obj ? obj->GetDict() : nullptr; } +const CPDF_Dictionary* CPDF_Reference::GetDict() const { + const CPDF_Object* obj = SafeGetDirect(); + return obj ? obj->GetDict() : nullptr; +} + bool CPDF_Reference::IsReference() const { return true; } @@ -69,17 +74,27 @@ std::unique_ptr<CPDF_Object> CPDF_Reference::CloneNonCyclic( return pdfium::MakeUnique<CPDF_Reference>(m_pObjList.Get(), m_RefObjNum); } -CPDF_Object* CPDF_Reference::SafeGetDirect() const { +CPDF_Object* CPDF_Reference::SafeGetDirect() { CPDF_Object* obj = GetDirect(); return (obj && !obj->IsReference()) ? obj : nullptr; } +const CPDF_Object* CPDF_Reference::SafeGetDirect() const { + 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 { +CPDF_Object* CPDF_Reference::GetDirect() { + return m_pObjList ? m_pObjList->GetOrParseIndirectObject(m_RefObjNum) + : nullptr; +} + +const CPDF_Object* CPDF_Reference::GetDirect() const { return m_pObjList ? m_pObjList->GetOrParseIndirectObject(m_RefObjNum) : nullptr; } |