1 // Copyright 2016 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FPDFAPI_PARSER_CPDF_REFERENCE_H_ 8 #define CORE_FPDFAPI_PARSER_CPDF_REFERENCE_H_ 9 10 #include <memory> 11 #include <set> 12 13 #include "core/fpdfapi/parser/cpdf_object.h" 14 #include "core/fxcrt/unowned_ptr.h" 15 16 class CPDF_IndirectObjectHolder; 17 18 class CPDF_Reference final : public CPDF_Object { 19 public: 20 template <typename T, typename... Args> 21 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); 22 23 // CPDF_Object: 24 Type GetType() const override; 25 RetainPtr<CPDF_Object> Clone() const override; 26 CPDF_Object* GetDirect() override; 27 const CPDF_Object* GetDirect() const override; 28 ByteString GetString() const override; 29 float GetNumber() const override; 30 int GetInteger() const override; 31 CPDF_Dictionary* GetDict() override; 32 const CPDF_Dictionary* GetDict() const override; 33 bool IsReference() const override; 34 CPDF_Reference* AsReference() override; 35 const CPDF_Reference* AsReference() const override; 36 bool WriteTo(IFX_ArchiveStream* archive, 37 const CPDF_Encryptor* encryptor) const override; 38 RetainPtr<CPDF_Object> MakeReference( 39 CPDF_IndirectObjectHolder* holder) const override; 40 GetObjList()41 CPDF_IndirectObjectHolder* GetObjList() const { return m_pObjList.Get(); } GetRefObjNum()42 uint32_t GetRefObjNum() const { return m_RefObjNum; } 43 void SetRef(CPDF_IndirectObjectHolder* pDoc, uint32_t objnum); 44 45 private: 46 CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, uint32_t objnum); 47 ~CPDF_Reference() override; 48 49 RetainPtr<CPDF_Object> CloneNonCyclic( 50 bool bDirect, 51 std::set<const CPDF_Object*>* pVisited) const override; 52 CPDF_Object* SafeGetDirect(); 53 const CPDF_Object* SafeGetDirect() const; 54 55 UnownedPtr<CPDF_IndirectObjectHolder> m_pObjList; 56 uint32_t m_RefObjNum; 57 }; 58 ToReference(CPDF_Object * obj)59inline CPDF_Reference* ToReference(CPDF_Object* obj) { 60 return obj ? obj->AsReference() : nullptr; 61 } 62 ToReference(const CPDF_Object * obj)63inline const CPDF_Reference* ToReference(const CPDF_Object* obj) { 64 return obj ? obj->AsReference() : nullptr; 65 } 66 67 #endif // CORE_FPDFAPI_PARSER_CPDF_REFERENCE_H_ 68