• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
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_FXCRT_CFX_SEEKABLESTREAMPROXY_H_
8 #define CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_
9 
10 #include <algorithm>
11 
12 #include "core/fxcrt/fx_stream.h"
13 #include "core/fxcrt/fx_system.h"
14 #include "core/fxcrt/retain_ptr.h"
15 
16 class CFX_SeekableStreamProxy : public Retainable {
17  public:
18   enum class From {
19     Begin = 0,
20     Current,
21   };
22 
23   template <typename T, typename... Args>
24   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
25 
GetLength()26   FX_FILESIZE GetLength() const { return m_pStream->GetSize(); }
GetPosition()27   FX_FILESIZE GetPosition() { return m_iPosition; }
GetBOMLength()28   size_t GetBOMLength() const { return m_wBOMLength; }
IsEOF()29   bool IsEOF() const { return m_iPosition >= GetLength(); }
30 
31   void Seek(From eSeek, FX_FILESIZE iOffset);
32   size_t ReadString(wchar_t* pStr, size_t iMaxLength, bool* bEOS);
33 
34   void WriteString(const WideStringView& str);
35 
GetCodePage()36   uint16_t GetCodePage() const { return m_wCodePage; }
37   void SetCodePage(uint16_t wCodePage);
38 
39  private:
40   CFX_SeekableStreamProxy(const RetainPtr<IFX_SeekableStream>& stream,
41                           bool isWriteSteam);
42   CFX_SeekableStreamProxy(uint8_t* data, size_t size);
43   ~CFX_SeekableStreamProxy() override;
44 
45   size_t ReadData(uint8_t* pBuffer, size_t iBufferSize);
46 
47   bool m_IsWriteStream;
48   uint16_t m_wCodePage;
49   size_t m_wBOMLength;
50   FX_FILESIZE m_iPosition;
51   RetainPtr<IFX_SeekableStream> m_pStream;
52 };
53 
54 #endif  // CORE_FXCRT_CFX_SEEKABLESTREAMPROXY_H_
55