• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "core/fpdfapi/parser/cpdf_object.h"
8 
9 #include <algorithm>
10 
11 #include "core/fpdfapi/parser/cpdf_array.h"
12 #include "core/fpdfapi/parser/cpdf_dictionary.h"
13 #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h"
14 #include "core/fpdfapi/parser/cpdf_parser.h"
15 #include "core/fpdfapi/parser/cpdf_reference.h"
16 #include "core/fxcrt/fx_string.h"
17 #include "third_party/base/notreached.h"
18 
19 CPDF_Object::~CPDF_Object() = default;
20 
21 static_assert(sizeof(uint64_t) >= sizeof(CPDF_Object*),
22               "Need a bigger type for cache keys");
23 
24 static_assert(CPDF_Parser::kMaxObjectNumber < static_cast<uint32_t>(1) << 31,
25               "Need a smaller kMaxObjNumber for cache keys");
26 
KeyForCache() const27 uint64_t CPDF_Object::KeyForCache() const {
28   if (IsInline())
29     return (static_cast<uint64_t>(1) << 63) | reinterpret_cast<uint64_t>(this);
30 
31   return (static_cast<uint64_t>(m_ObjNum) << 32) |
32          static_cast<uint64_t>(m_GenNum);
33 }
34 
GetMutableDirect()35 RetainPtr<CPDF_Object> CPDF_Object::GetMutableDirect() {
36   return pdfium::WrapRetain(const_cast<CPDF_Object*>(GetDirectInternal()));
37 }
38 
GetDirect() const39 RetainPtr<const CPDF_Object> CPDF_Object::GetDirect() const {
40   return pdfium::WrapRetain(GetDirectInternal());
41 }
42 
GetDirectInternal() const43 const CPDF_Object* CPDF_Object::GetDirectInternal() const {
44   return this;
45 }
46 
CloneObjectNonCyclic(bool bDirect) const47 RetainPtr<CPDF_Object> CPDF_Object::CloneObjectNonCyclic(bool bDirect) const {
48   std::set<const CPDF_Object*> visited_objs;
49   return CloneNonCyclic(bDirect, &visited_objs);
50 }
51 
CloneDirectObject() const52 RetainPtr<CPDF_Object> CPDF_Object::CloneDirectObject() const {
53   return CloneObjectNonCyclic(true);
54 }
55 
CloneNonCyclic(bool bDirect,std::set<const CPDF_Object * > * pVisited) const56 RetainPtr<CPDF_Object> CPDF_Object::CloneNonCyclic(
57     bool bDirect,
58     std::set<const CPDF_Object*>* pVisited) const {
59   return Clone();
60 }
61 
GetString() const62 ByteString CPDF_Object::GetString() const {
63   return ByteString();
64 }
65 
GetUnicodeText() const66 WideString CPDF_Object::GetUnicodeText() const {
67   return WideString();
68 }
69 
GetNumber() const70 float CPDF_Object::GetNumber() const {
71   return 0;
72 }
73 
GetInteger() const74 int CPDF_Object::GetInteger() const {
75   return 0;
76 }
77 
GetDict() const78 RetainPtr<const CPDF_Dictionary> CPDF_Object::GetDict() const {
79   return pdfium::WrapRetain(GetDictInternal());
80 }
81 
GetMutableDict()82 RetainPtr<CPDF_Dictionary> CPDF_Object::GetMutableDict() {
83   return pdfium::WrapRetain(const_cast<CPDF_Dictionary*>(GetDictInternal()));
84 }
85 
GetDictInternal() const86 const CPDF_Dictionary* CPDF_Object::GetDictInternal() const {
87   return nullptr;
88 }
89 
SetString(const ByteString & str)90 void CPDF_Object::SetString(const ByteString& str) {
91   NOTREACHED();
92 }
93 
AsMutableArray()94 CPDF_Array* CPDF_Object::AsMutableArray() {
95   return nullptr;
96 }
97 
AsArray() const98 const CPDF_Array* CPDF_Object::AsArray() const {
99   return const_cast<CPDF_Object*>(this)->AsMutableArray();
100 }
101 
AsMutableBoolean()102 CPDF_Boolean* CPDF_Object::AsMutableBoolean() {
103   return nullptr;
104 }
105 
AsBoolean() const106 const CPDF_Boolean* CPDF_Object::AsBoolean() const {
107   return const_cast<CPDF_Object*>(this)->AsMutableBoolean();
108 }
109 
AsMutableDictionary()110 CPDF_Dictionary* CPDF_Object::AsMutableDictionary() {
111   return nullptr;
112 }
113 
AsDictionary() const114 const CPDF_Dictionary* CPDF_Object::AsDictionary() const {
115   return const_cast<CPDF_Object*>(this)->AsMutableDictionary();
116 }
117 
AsMutableName()118 CPDF_Name* CPDF_Object::AsMutableName() {
119   return nullptr;
120 }
121 
AsName() const122 const CPDF_Name* CPDF_Object::AsName() const {
123   return const_cast<CPDF_Object*>(this)->AsMutableName();
124 }
125 
AsMutableNull()126 CPDF_Null* CPDF_Object::AsMutableNull() {
127   return nullptr;
128 }
129 
AsNull() const130 const CPDF_Null* CPDF_Object::AsNull() const {
131   return const_cast<CPDF_Object*>(this)->AsMutableNull();
132 }
133 
AsMutableNumber()134 CPDF_Number* CPDF_Object::AsMutableNumber() {
135   return nullptr;
136 }
137 
AsNumber() const138 const CPDF_Number* CPDF_Object::AsNumber() const {
139   return const_cast<CPDF_Object*>(this)->AsMutableNumber();
140 }
141 
AsMutableReference()142 CPDF_Reference* CPDF_Object::AsMutableReference() {
143   return nullptr;
144 }
145 
AsReference() const146 const CPDF_Reference* CPDF_Object::AsReference() const {
147   return const_cast<CPDF_Object*>(this)->AsMutableReference();
148 }
149 
AsMutableStream()150 CPDF_Stream* CPDF_Object::AsMutableStream() {
151   return nullptr;
152 }
153 
AsStream() const154 const CPDF_Stream* CPDF_Object::AsStream() const {
155   return const_cast<CPDF_Object*>(this)->AsMutableStream();
156 }
157 
AsMutableString()158 CPDF_String* CPDF_Object::AsMutableString() {
159   return nullptr;
160 }
161 
AsString() const162 const CPDF_String* CPDF_Object::AsString() const {
163   return const_cast<CPDF_Object*>(this)->AsMutableString();
164 }
165 
MakeReference(CPDF_IndirectObjectHolder * holder) const166 RetainPtr<CPDF_Reference> CPDF_Object::MakeReference(
167     CPDF_IndirectObjectHolder* holder) const {
168   if (IsInline()) {
169     NOTREACHED();
170     return nullptr;
171   }
172   return pdfium::MakeRetain<CPDF_Reference>(holder, GetObjNum());
173 }
174