summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_array.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-05-09 23:15:12 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-09 23:15:12 +0000
commit3774c7a452886b9c8beeb5fa1b54a34611551180 (patch)
treeaba96eeb7d9fc266ecbe7bc460dcaac869514ecf /core/fpdfapi/parser/cpdf_array.cpp
parent7e28208d26764438bef62e051d2e1fed13e1e0ec (diff)
downloadpdfium-3774c7a452886b9c8beeb5fa1b54a34611551180.tar.xz
Add proper const/non-const versions of CPDF_Array methods.
Instead of having const methods that return non-const pointers. BUG=pdfium:234 Change-Id: I61495543f67229500dfcf2248e93468e9a9b23cf Reviewed-on: https://pdfium-review.googlesource.com/32183 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_array.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_array.cpp43
1 files changed, 37 insertions, 6 deletions
diff --git a/core/fpdfapi/parser/cpdf_array.cpp b/core/fpdfapi/parser/cpdf_array.cpp
index 9293101b32..4f802d9e7f 100644
--- a/core/fpdfapi/parser/cpdf_array.cpp
+++ b/core/fpdfapi/parser/cpdf_array.cpp
@@ -87,13 +87,25 @@ CFX_Matrix CPDF_Array::GetMatrix() const {
GetNumberAt(3), GetNumberAt(4), GetNumberAt(5));
}
-CPDF_Object* CPDF_Array::GetObjectAt(size_t i) const {
+CPDF_Object* CPDF_Array::GetObjectAt(size_t i) {
if (i >= m_Objects.size())
return nullptr;
return m_Objects[i].get();
}
-CPDF_Object* CPDF_Array::GetDirectObjectAt(size_t i) const {
+const CPDF_Object* CPDF_Array::GetObjectAt(size_t i) const {
+ if (i >= m_Objects.size())
+ return nullptr;
+ return m_Objects[i].get();
+}
+
+CPDF_Object* CPDF_Array::GetDirectObjectAt(size_t i) {
+ if (i >= m_Objects.size())
+ return nullptr;
+ return m_Objects[i]->GetDirect();
+}
+
+const CPDF_Object* CPDF_Array::GetDirectObjectAt(size_t i) const {
if (i >= m_Objects.size())
return nullptr;
return m_Objects[i]->GetDirect();
@@ -123,7 +135,7 @@ float CPDF_Array::GetNumberAt(size_t i) const {
return m_Objects[i]->GetNumber();
}
-CPDF_Dictionary* CPDF_Array::GetDictAt(size_t i) const {
+CPDF_Dictionary* CPDF_Array::GetDictAt(size_t i) {
CPDF_Object* p = GetDirectObjectAt(i);
if (!p)
return nullptr;
@@ -134,11 +146,30 @@ CPDF_Dictionary* CPDF_Array::GetDictAt(size_t i) const {
return nullptr;
}
-CPDF_Stream* CPDF_Array::GetStreamAt(size_t i) const {
+const CPDF_Dictionary* CPDF_Array::GetDictAt(size_t i) const {
+ const CPDF_Object* p = GetDirectObjectAt(i);
+ if (!p)
+ return nullptr;
+ if (const CPDF_Dictionary* pDict = p->AsDictionary())
+ return pDict;
+ if (const CPDF_Stream* pStream = p->AsStream())
+ return pStream->GetDict();
+ return nullptr;
+}
+
+CPDF_Stream* CPDF_Array::GetStreamAt(size_t i) {
return ToStream(GetDirectObjectAt(i));
}
-CPDF_Array* CPDF_Array::GetArrayAt(size_t i) const {
+const CPDF_Stream* CPDF_Array::GetStreamAt(size_t i) const {
+ return ToStream(GetDirectObjectAt(i));
+}
+
+CPDF_Array* CPDF_Array::GetArrayAt(size_t i) {
+ return ToArray(GetDirectObjectAt(i));
+}
+
+const CPDF_Array* CPDF_Array::GetArrayAt(size_t i) const {
return ToArray(GetDirectObjectAt(i));
}
@@ -204,7 +235,7 @@ bool CPDF_Array::WriteTo(IFX_ArchiveStream* archive) const {
return false;
for (size_t i = 0; i < GetCount(); ++i) {
- CPDF_Object* pElement = GetObjectAt(i);
+ const CPDF_Object* pElement = GetObjectAt(i);
if (!pElement->IsInline()) {
if (!archive->WriteString(" ") ||
!archive->WriteDWord(pElement->GetObjNum()) ||