Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: core/fpdfapi/parser/cpdf_stream.h

Issue 2384883003: Remove CPDF_Object::Release() in favor of direct delete (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/parser/cpdf_parser.cpp ('k') | core/fpdfapi/parser/cpdf_stream.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_PARSER_CPDF_STREAM_H_ 7 #ifndef CORE_FPDFAPI_PARSER_CPDF_STREAM_H_
8 #define CORE_FPDFAPI_PARSER_CPDF_STREAM_H_ 8 #define CORE_FPDFAPI_PARSER_CPDF_STREAM_H_
9 9
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 12
13 #include "core/fpdfapi/parser/cpdf_dictionary.h" 13 #include "core/fpdfapi/parser/cpdf_dictionary.h"
14 #include "core/fpdfapi/parser/cpdf_object.h" 14 #include "core/fpdfapi/parser/cpdf_object.h"
15 #include "core/fxcrt/fx_basic.h" 15 #include "core/fxcrt/fx_basic.h"
16 16
17 class CPDF_Stream : public CPDF_Object { 17 class CPDF_Stream : public CPDF_Object {
18 public: 18 public:
19 CPDF_Stream(); 19 CPDF_Stream();
20 20
21 // Takes ownership of |pData| and |pDict|. 21 // Takes ownership of |pData| and |pDict|.
22 CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict); 22 CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict);
23 ~CPDF_Stream() override;
23 24
24 // CPDF_Object. 25 // CPDF_Object.
25 Type GetType() const override; 26 Type GetType() const override;
26 CPDF_Object* Clone() const override; 27 CPDF_Object* Clone() const override;
27 CPDF_Dictionary* GetDict() const override; 28 CPDF_Dictionary* GetDict() const override;
28 CFX_WideString GetUnicodeText() const override; 29 CFX_WideString GetUnicodeText() const override;
29 bool IsStream() const override; 30 bool IsStream() const override;
30 CPDF_Stream* AsStream() override; 31 CPDF_Stream* AsStream() override;
31 const CPDF_Stream* AsStream() const override; 32 const CPDF_Stream* AsStream() const override;
32 33
33 uint32_t GetRawSize() const { return m_dwSize; } 34 uint32_t GetRawSize() const { return m_dwSize; }
34 uint8_t* GetRawData() const { return m_pDataBuf.get(); } 35 uint8_t* GetRawData() const { return m_pDataBuf.get(); }
35 36
36 // Does not takes onwership of |pData|, copies into internally-owned buffer. 37 // Does not takes onwership of |pData|, copies into internally-owned buffer.
37 void SetData(const uint8_t* pData, uint32_t size); 38 void SetData(const uint8_t* pData, uint32_t size);
38 39
39 void InitStream(const uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict); 40 void InitStream(const uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict);
40 void InitStreamFromFile(IFX_SeekableReadStream* pFile, 41 void InitStreamFromFile(IFX_SeekableReadStream* pFile,
41 CPDF_Dictionary* pDict); 42 CPDF_Dictionary* pDict);
42 43
43 bool ReadRawData(FX_FILESIZE start_pos, 44 bool ReadRawData(FX_FILESIZE start_pos,
44 uint8_t* pBuf, 45 uint8_t* pBuf,
45 uint32_t buf_size) const; 46 uint32_t buf_size) const;
46 47
47 bool IsMemoryBased() const { return m_bMemoryBased; } 48 bool IsMemoryBased() const { return m_bMemoryBased; }
48 49
49 protected: 50 protected:
50 ~CPDF_Stream() override;
51 CPDF_Object* CloneNonCyclic( 51 CPDF_Object* CloneNonCyclic(
52 bool bDirect, 52 bool bDirect,
53 std::set<const CPDF_Object*>* pVisited) const override; 53 std::set<const CPDF_Object*>* pVisited) const override;
54 54
55 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> m_pDict;
56 bool m_bMemoryBased = true; 55 bool m_bMemoryBased = true;
57 uint32_t m_dwSize = 0; 56 uint32_t m_dwSize = 0;
57 std::unique_ptr<CPDF_Dictionary> m_pDict;
58 std::unique_ptr<uint8_t, FxFreeDeleter> m_pDataBuf; 58 std::unique_ptr<uint8_t, FxFreeDeleter> m_pDataBuf;
59 IFX_SeekableReadStream* m_pFile = nullptr; 59 IFX_SeekableReadStream* m_pFile = nullptr;
60 }; 60 };
61 61
62 using UniqueStream = std::unique_ptr<CPDF_Stream, ReleaseDeleter<CPDF_Object>>;
63
64 inline CPDF_Stream* ToStream(CPDF_Object* obj) { 62 inline CPDF_Stream* ToStream(CPDF_Object* obj) {
65 return obj ? obj->AsStream() : nullptr; 63 return obj ? obj->AsStream() : nullptr;
66 } 64 }
67 65
68 inline const CPDF_Stream* ToStream(const CPDF_Object* obj) { 66 inline const CPDF_Stream* ToStream(const CPDF_Object* obj) {
69 return obj ? obj->AsStream() : nullptr; 67 return obj ? obj->AsStream() : nullptr;
70 } 68 }
71 69
72 inline UniqueStream ToStream(UniqueObject obj) { 70 inline std::unique_ptr<CPDF_Stream> ToStream(std::unique_ptr<CPDF_Object> obj) {
73 CPDF_Stream* pStream = ToStream(obj.get()); 71 CPDF_Stream* pStream = ToStream(obj.get());
74 if (!pStream) 72 if (!pStream)
75 return nullptr; 73 return nullptr;
76 obj.release(); 74 obj.release();
77 return UniqueStream(pStream); 75 return std::unique_ptr<CPDF_Stream>(pStream);
78 } 76 }
79 77
80 #endif // CORE_FPDFAPI_PARSER_CPDF_STREAM_H_ 78 #endif // CORE_FPDFAPI_PARSER_CPDF_STREAM_H_
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_parser.cpp ('k') | core/fpdfapi/parser/cpdf_stream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698