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

Side by Side Diff: core/fpdfapi/fpdf_parser/include/cpdf_stream.h

Issue 2347993002: Clean up CPDF_Stream. (Closed)
Patch Set: ctor Created 4 years, 3 months 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/fpdf_parser/cpdf_stream.cpp ('k') | core/fpdfdoc/cpvt_generateap.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_FPDF_PARSER_INCLUDE_CPDF_STREAM_H_ 7 #ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_H_
8 #define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_H_ 8 #define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_H_
9 9
10 #include <memory>
10 #include <set> 11 #include <set>
11 12
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
14 #include "core/fxcrt/include/fx_stream.h" 15 #include "core/fxcrt/include/fx_basic.h"
15 16
16 class CPDF_Stream : public CPDF_Object { 17 class CPDF_Stream : public CPDF_Object {
17 public: 18 public:
19 CPDF_Stream();
20
21 // Takes onwership of |pData| and |pDict|.
18 CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict); 22 CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict);
dsinclair 2016/09/19 13:12:18 Can we pass through a std::unique_ptr to make the
19 23
20 // CPDF_Object. 24 // CPDF_Object.
21 Type GetType() const override; 25 Type GetType() const override;
22 CPDF_Object* Clone() const override; 26 CPDF_Object* Clone() const override;
23 CPDF_Dictionary* GetDict() const override; 27 CPDF_Dictionary* GetDict() const override;
24 CFX_WideString GetUnicodeText() const override; 28 CFX_WideString GetUnicodeText() const override;
25 bool IsStream() const override; 29 bool IsStream() const override;
26 CPDF_Stream* AsStream() override; 30 CPDF_Stream* AsStream() override;
27 const CPDF_Stream* AsStream() const override; 31 const CPDF_Stream* AsStream() const override;
28 32
29 uint32_t GetRawSize() const { return m_dwSize; } 33 uint32_t GetRawSize() const { return m_dwSize; }
30 uint8_t* GetRawData() const { return m_pDataBuf; } 34 uint8_t* GetRawData() const { return m_pDataBuf.get(); }
31 35
32 void SetData(const uint8_t* pData, 36 // Does not takes onwership of |pData|, copies into internally-owned buffer.
33 uint32_t size, 37 void SetData(const uint8_t* pData, uint32_t size);
34 FX_BOOL bCompressed,
35 FX_BOOL bKeepBuf);
36 38
37 void InitStream(const uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict); 39 void InitStream(const uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict);
38 void InitStreamFromFile(IFX_FileRead* pFile, CPDF_Dictionary* pDict); 40 void InitStreamFromFile(IFX_FileRead* pFile, CPDF_Dictionary* pDict);
39 41
40 FX_BOOL ReadRawData(FX_FILESIZE start_pos, 42 FX_BOOL ReadRawData(FX_FILESIZE start_pos,
41 uint8_t* pBuf, 43 uint8_t* pBuf,
42 uint32_t buf_size) const; 44 uint32_t buf_size) const;
43 45
44 bool IsMemoryBased() const { return m_GenNum == kMemoryBasedGenNum; } 46 bool IsMemoryBased() const { return m_bMemoryBased; }
45 47
46 protected: 48 protected:
47 static const uint32_t kMemoryBasedGenNum = (uint32_t)-1;
48
49 ~CPDF_Stream() override; 49 ~CPDF_Stream() override;
50 CPDF_Object* CloneNonCyclic( 50 CPDF_Object* CloneNonCyclic(
51 bool bDirect, 51 bool bDirect,
52 std::set<const CPDF_Object*>* pVisited) const override; 52 std::set<const CPDF_Object*>* pVisited) const override;
53 53
54 void InitStreamInternal(CPDF_Dictionary* pDict); 54 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> m_pDict;
55 55 bool m_bMemoryBased = true;
56 CPDF_Dictionary* m_pDict; 56 uint32_t m_dwSize = 0;
57 uint32_t m_dwSize; 57 std::unique_ptr<uint8_t, FxFreeDeleter> m_pDataBuf;
58 uint32_t m_GenNum; 58 IFX_FileRead* m_pFile = nullptr;
59
60 union {
61 uint8_t* m_pDataBuf;
62 IFX_FileRead* m_pFile;
63 };
64 }; 59 };
65 60
66 #endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_H_ 61 #endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_STREAM_H_
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_stream.cpp ('k') | core/fpdfdoc/cpvt_generateap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698