• 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_MEMORYSTREAM_H_
8 #define CORE_FXCRT_CFX_MEMORYSTREAM_H_
9 
10 #include <memory>
11 
12 #include "core/fxcrt/fx_memory_wrappers.h"
13 #include "core/fxcrt/fx_stream.h"
14 #include "core/fxcrt/retain_ptr.h"
15 
16 class CFX_MemoryStream final : public IFX_SeekableStream {
17  public:
18   template <typename T, typename... Args>
19   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
20 
21   // IFX_SeekableStream
22   FX_FILESIZE GetSize() override;
23   FX_FILESIZE GetPosition() override;
24   bool IsEOF() override;
25   bool ReadBlockAtOffset(void* buffer,
26                          FX_FILESIZE offset,
27                          size_t size) override;
28   size_t ReadBlock(void* buffer, size_t size) override;
29   bool WriteBlockAtOffset(const void* buffer,
30                           FX_FILESIZE offset,
31                           size_t size) override;
32   bool Flush() override;
33 
GetBuffer()34   const uint8_t* GetBuffer() const { return m_data.get(); }
35 
36  private:
37   CFX_MemoryStream();
38   CFX_MemoryStream(std::unique_ptr<uint8_t, FxFreeDeleter> pBuffer,
39                    size_t nSize);
40   ~CFX_MemoryStream() override;
41 
42   std::unique_ptr<uint8_t, FxFreeDeleter> m_data;
43   size_t m_nTotalSize;
44   size_t m_nCurSize;
45   size_t m_nCurPos = 0;
46 };
47 
48 #endif  // CORE_FXCRT_CFX_MEMORYSTREAM_H_
49