From f22b4e2f6682fe26113c591a01139a8b5fa4e3bf Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Wed, 18 Jul 2018 18:35:09 +0000 Subject: Use casts to deduplicate implementation of const/non-const methods. Change-Id: Ia5a4e89bff8a1dbc46246f5a734170765b7ee74e Reviewed-on: https://pdfium-review.googlesource.com/38250 Reviewed-by: Lei Zhang Commit-Queue: Henrique Nakashima --- core/fpdfapi/page/cpdf_contentmark.cpp | 12 ++++++------ core/fpdfapi/page/cpdf_contentmark.h | 4 ++-- core/fpdfapi/page/cpdf_contentmarkitem.cpp | 11 ++--------- 3 files changed, 10 insertions(+), 17 deletions(-) (limited to 'core/fpdfapi/page') diff --git a/core/fpdfapi/page/cpdf_contentmark.cpp b/core/fpdfapi/page/cpdf_contentmark.cpp index 13945d9337..725a17348b 100644 --- a/core/fpdfapi/page/cpdf_contentmark.cpp +++ b/core/fpdfapi/page/cpdf_contentmark.cpp @@ -30,14 +30,14 @@ bool CPDF_ContentMark::ContainsItem(const CPDF_ContentMarkItem* pItem) const { return m_pMarkData && m_pMarkData->ContainsItem(pItem); } -CPDF_ContentMarkItem* CPDF_ContentMark::GetItem(size_t i) { - ASSERT(i < CountItems()); - return m_pMarkData->GetItem(i); +CPDF_ContentMarkItem* CPDF_ContentMark::GetItem(size_t index) { + return const_cast( + static_cast(this)->GetItem(index)); } -const CPDF_ContentMarkItem* CPDF_ContentMark::GetItem(size_t i) const { - ASSERT(i < CountItems()); - return m_pMarkData->GetItem(i); +const CPDF_ContentMarkItem* CPDF_ContentMark::GetItem(size_t index) const { + ASSERT(index < CountItems()); + return m_pMarkData->GetItem(index); } int CPDF_ContentMark::GetMarkedContentID() const { diff --git a/core/fpdfapi/page/cpdf_contentmark.h b/core/fpdfapi/page/cpdf_contentmark.h index 4f678aff8e..dc4cc08838 100644 --- a/core/fpdfapi/page/cpdf_contentmark.h +++ b/core/fpdfapi/page/cpdf_contentmark.h @@ -27,8 +27,8 @@ class CPDF_ContentMark { bool ContainsItem(const CPDF_ContentMarkItem* pItem) const; // The returned pointer is never null. - CPDF_ContentMarkItem* GetItem(size_t i); - const CPDF_ContentMarkItem* GetItem(size_t i) const; + CPDF_ContentMarkItem* GetItem(size_t index); + const CPDF_ContentMarkItem* GetItem(size_t index) const; void AddMark(ByteString name); void AddMarkWithDirectDict(ByteString name, CPDF_Dictionary* pDict); diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.cpp b/core/fpdfapi/page/cpdf_contentmarkitem.cpp index 90a2930b23..8eba4aa15f 100644 --- a/core/fpdfapi/page/cpdf_contentmarkitem.cpp +++ b/core/fpdfapi/page/cpdf_contentmarkitem.cpp @@ -28,15 +28,8 @@ const CPDF_Dictionary* CPDF_ContentMarkItem::GetParam() const { } CPDF_Dictionary* CPDF_ContentMarkItem::GetParam() { - switch (m_ParamType) { - case PropertiesDict: - return m_pPropertiesDict.Get(); - case DirectDict: - return m_pDirectDict.get(); - case None: - default: - return nullptr; - } + return const_cast( + static_cast(this)->GetParam()); } bool CPDF_ContentMarkItem::HasMCID() const { -- cgit v1.2.3