• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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_READONLYMEMORYSTREAM_H_
8 #define CORE_FXCRT_CFX_READONLYMEMORYSTREAM_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 #include "third_party/base/span.h"
16 
17 class CFX_ReadOnlyMemoryStream final : public IFX_SeekableReadStream {
18  public:
19   template <typename T, typename... Args>
20   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
21 
22   // IFX_SeekableReadStream:
23   FX_FILESIZE GetSize() override;
24   bool ReadBlockAtOffset(void* buffer,
25                          FX_FILESIZE offset,
26                          size_t size) override;
27 
28  private:
29   CFX_ReadOnlyMemoryStream(std::unique_ptr<uint8_t, FxFreeDeleter> data,
30                            size_t size);
31   explicit CFX_ReadOnlyMemoryStream(pdfium::span<const uint8_t> span);
32   ~CFX_ReadOnlyMemoryStream() override;
33 
34   std::unique_ptr<uint8_t, FxFreeDeleter> m_data;
35   const pdfium::span<const uint8_t> m_span;
36 };
37 
38 #endif  // CORE_FXCRT_CFX_READONLYMEMORYSTREAM_H_
39