OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_ | 7 #ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_ |
8 #define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_ | 8 #define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_ |
9 | 9 |
| 10 #include <set> |
| 11 |
10 #include "core/fxcrt/include/fx_string.h" | 12 #include "core/fxcrt/include/fx_string.h" |
11 #include "core/fxcrt/include/fx_system.h" | 13 #include "core/fxcrt/include/fx_system.h" |
12 | 14 |
13 class CPDF_Array; | 15 class CPDF_Array; |
14 class CPDF_Boolean; | 16 class CPDF_Boolean; |
15 class CPDF_Dictionary; | 17 class CPDF_Dictionary; |
16 class CPDF_Name; | 18 class CPDF_Name; |
17 class CPDF_Null; | 19 class CPDF_Null; |
18 class CPDF_Number; | 20 class CPDF_Number; |
19 class CPDF_Reference; | 21 class CPDF_Reference; |
(...skipping 12 matching lines...) Expand all Loading... |
32 DICTIONARY, | 34 DICTIONARY, |
33 STREAM, | 35 STREAM, |
34 NULLOBJ, | 36 NULLOBJ, |
35 REFERENCE | 37 REFERENCE |
36 }; | 38 }; |
37 | 39 |
38 virtual Type GetType() const = 0; | 40 virtual Type GetType() const = 0; |
39 uint32_t GetObjNum() const { return m_ObjNum; } | 41 uint32_t GetObjNum() const { return m_ObjNum; } |
40 uint32_t GetGenNum() const { return m_GenNum; } | 42 uint32_t GetGenNum() const { return m_GenNum; } |
41 | 43 |
42 virtual CPDF_Object* Clone(FX_BOOL bDirect = FALSE) const = 0; | 44 // Create a deep copy of the object. |
| 45 virtual CPDF_Object* Clone() const = 0; |
| 46 // Create a deep copy of the object except any reference object be |
| 47 // copied to the object it points to directly. |
| 48 virtual CPDF_Object* CloneDirectObject() const; |
43 virtual CPDF_Object* GetDirect() const; | 49 virtual CPDF_Object* GetDirect() const; |
44 | 50 |
45 void Release(); | 51 void Release(); |
46 | 52 |
47 virtual CFX_ByteString GetString() const; | 53 virtual CFX_ByteString GetString() const; |
48 virtual CFX_WideString GetUnicodeText() const; | 54 virtual CFX_WideString GetUnicodeText() const; |
49 virtual FX_FLOAT GetNumber() const; | 55 virtual FX_FLOAT GetNumber() const; |
50 virtual int GetInteger() const; | 56 virtual int GetInteger() const; |
51 virtual CPDF_Dictionary* GetDict() const; | 57 virtual CPDF_Dictionary* GetDict() const; |
52 | 58 |
(...skipping 19 matching lines...) Expand all Loading... |
72 virtual CPDF_Number* AsNumber(); | 78 virtual CPDF_Number* AsNumber(); |
73 virtual const CPDF_Number* AsNumber() const; | 79 virtual const CPDF_Number* AsNumber() const; |
74 virtual CPDF_Reference* AsReference(); | 80 virtual CPDF_Reference* AsReference(); |
75 virtual const CPDF_Reference* AsReference() const; | 81 virtual const CPDF_Reference* AsReference() const; |
76 virtual CPDF_Stream* AsStream(); | 82 virtual CPDF_Stream* AsStream(); |
77 virtual const CPDF_Stream* AsStream() const; | 83 virtual const CPDF_Stream* AsStream() const; |
78 virtual CPDF_String* AsString(); | 84 virtual CPDF_String* AsString(); |
79 virtual const CPDF_String* AsString() const; | 85 virtual const CPDF_String* AsString() const; |
80 | 86 |
81 protected: | 87 protected: |
| 88 friend class CPDF_Array; |
| 89 friend class CPDF_Dictionary; |
| 90 friend class CPDF_Document; |
| 91 friend class CPDF_IndirectObjectHolder; |
| 92 friend class CPDF_Parser; |
| 93 friend class CPDF_Reference; |
| 94 friend class CPDF_Stream; |
| 95 |
82 CPDF_Object() : m_ObjNum(0), m_GenNum(0) {} | 96 CPDF_Object() : m_ObjNum(0), m_GenNum(0) {} |
83 virtual ~CPDF_Object(); | 97 virtual ~CPDF_Object(); |
84 void Destroy() { delete this; } | 98 void Destroy() { delete this; } |
85 | 99 |
| 100 CPDF_Object* CloneObjectNonCyclic(bool bDirect) const; |
| 101 |
| 102 // Create a deep copy of the object with the option to either |
| 103 // copy a reference object or directly copy the object it refers to |
| 104 // when |bDirect| is true. |
| 105 // Also check cyclic reference against |pVisited|, no copy if it is found. |
| 106 // Complex objects should implement their own CloneNonCyclic() |
| 107 // function to properly check for possible loop. |
| 108 virtual CPDF_Object* CloneNonCyclic( |
| 109 bool bDirect, |
| 110 std::set<const CPDF_Object*>* pVisited) const; |
| 111 |
86 uint32_t m_ObjNum; | 112 uint32_t m_ObjNum; |
87 uint32_t m_GenNum; | 113 uint32_t m_GenNum; |
88 | 114 |
89 friend class CPDF_IndirectObjectHolder; | |
90 friend class CPDF_Parser; | |
91 | |
92 private: | 115 private: |
93 CPDF_Object(const CPDF_Object& src) {} | 116 CPDF_Object(const CPDF_Object& src) {} |
94 }; | 117 }; |
95 | 118 |
96 inline CPDF_Boolean* ToBoolean(CPDF_Object* obj) { | 119 inline CPDF_Boolean* ToBoolean(CPDF_Object* obj) { |
97 return obj ? obj->AsBoolean() : nullptr; | 120 return obj ? obj->AsBoolean() : nullptr; |
98 } | 121 } |
99 | 122 |
100 inline const CPDF_Boolean* ToBoolean(const CPDF_Object* obj) { | 123 inline const CPDF_Boolean* ToBoolean(const CPDF_Object* obj) { |
101 return obj ? obj->AsBoolean() : nullptr; | 124 return obj ? obj->AsBoolean() : nullptr; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 173 |
151 inline CPDF_Stream* ToStream(CPDF_Object* obj) { | 174 inline CPDF_Stream* ToStream(CPDF_Object* obj) { |
152 return obj ? obj->AsStream() : nullptr; | 175 return obj ? obj->AsStream() : nullptr; |
153 } | 176 } |
154 | 177 |
155 inline const CPDF_Stream* ToStream(const CPDF_Object* obj) { | 178 inline const CPDF_Stream* ToStream(const CPDF_Object* obj) { |
156 return obj ? obj->AsStream() : nullptr; | 179 return obj ? obj->AsStream() : nullptr; |
157 } | 180 } |
158 | 181 |
159 #endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_ | 182 #endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_OBJECT_H_ |
OLD | NEW |