From 39869b641511c882d78e17548293cdb458c36f38 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 20 Oct 2015 14:57:56 -0400 Subject: Revert "Revert "Add type cast definitions for CPDF_Dictionary."" This reverts commit 937840e1722d1f2b77d80575d6e710d760662c9c. Add type cast definitions for CPDF_Dictionary. This CL adds ToCPDFDictionary type definitions and updates one file to use instead of straight casts. I had to fix two places where we'd casted off the constness of the original pointer. BUG=pdfium:201 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1420583003 . --- core/include/fpdfapi/fpdf_objects.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'core/include/fpdfapi') diff --git a/core/include/fpdfapi/fpdf_objects.h b/core/include/fpdfapi/fpdf_objects.h index c2d838d35b..4141ec854a 100644 --- a/core/include/fpdfapi/fpdf_objects.h +++ b/core/include/fpdfapi/fpdf_objects.h @@ -78,6 +78,11 @@ class CPDF_Object { FX_BOOL IsModified() const { return FALSE; } + bool IsDictionary() const { return m_Type == PDFOBJ_DICTIONARY; } + + CPDF_Dictionary* AsDictionary(); + const CPDF_Dictionary* AsDictionary() const; + protected: CPDF_Object(FX_DWORD type) : m_Type(type), m_ObjNum(0), m_GenNum(0) {} ~CPDF_Object() {} @@ -402,6 +407,13 @@ class CPDF_Dictionary : public CPDF_Object { friend class CPDF_Object; }; +inline CPDF_Dictionary* ToDictionary(CPDF_Object* obj) { + return obj ? obj->AsDictionary() : nullptr; +} +inline const CPDF_Dictionary* ToDictionary(const CPDF_Object* obj) { + return obj ? obj->AsDictionary() : nullptr; +} + class CPDF_Stream : public CPDF_Object { public: static CPDF_Stream* Create(uint8_t* pData, -- cgit v1.2.3