1 // Copyright 2016 The PDFium Authors 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 <set> 11 12 #include "core/fpdfapi/parser/cpdf_object.h" 13 #include "core/fxcrt/retain_ptr.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 CONSTRUCT_VIA_MAKE_RETAIN; 21 22 // CPDF_Object: 23 Type GetType() const override; 24 RetainPtr<CPDF_Object> Clone() const override; 25 ByteString GetString() const override; 26 float GetNumber() const override; 27 int GetInteger() const override; 28 CPDF_Reference* AsMutableReference() override; 29 bool WriteTo(IFX_ArchiveStream* archive, 30 const CPDF_Encryptor* encryptor) const override; 31 RetainPtr<CPDF_Reference> MakeReference( 32 CPDF_IndirectObjectHolder* holder) const override; 33 GetRefObjNum()34 uint32_t GetRefObjNum() const { return m_RefObjNum; } HasIndirectObjectHolder()35 bool HasIndirectObjectHolder() const { return !!m_pObjList; } 36 void SetRef(CPDF_IndirectObjectHolder* pDoc, uint32_t objnum); 37 38 private: 39 friend class CPDF_Dictionary; 40 41 CPDF_Reference(CPDF_IndirectObjectHolder* pDoc, uint32_t objnum); 42 ~CPDF_Reference() override; 43 44 const CPDF_Object* GetDirectInternal() const override; 45 const CPDF_Dictionary* GetDictInternal() const override; 46 RetainPtr<CPDF_Object> CloneNonCyclic( 47 bool bDirect, 48 std::set<const CPDF_Object*>* pVisited) const override; 49 50 const CPDF_Object* FastGetDirect() const; 51 52 UnownedPtr<CPDF_IndirectObjectHolder> m_pObjList; 53 uint32_t m_RefObjNum; 54 }; 55 ToReference(CPDF_Object * obj)56inline CPDF_Reference* ToReference(CPDF_Object* obj) { 57 return obj ? obj->AsMutableReference() : nullptr; 58 } 59 ToReference(const CPDF_Object * obj)60inline const CPDF_Reference* ToReference(const CPDF_Object* obj) { 61 return obj ? obj->AsReference() : nullptr; 62 } 63 ToReference(RetainPtr<CPDF_Object> obj)64inline RetainPtr<CPDF_Reference> ToReference(RetainPtr<CPDF_Object> obj) { 65 return RetainPtr<CPDF_Reference>(ToReference(obj.Get())); 66 } 67 ToReference(RetainPtr<const CPDF_Object> obj)68inline RetainPtr<const CPDF_Reference> ToReference( 69 RetainPtr<const CPDF_Object> obj) { 70 return RetainPtr<const CPDF_Reference>(ToReference(obj.Get())); 71 } 72 73 #endif // CORE_FPDFAPI_PARSER_CPDF_REFERENCE_H_ 74