diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-20 14:11:21 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-20 18:38:55 +0000 |
commit | 283a0433b081f88275b2f7e8c04d3c41b9187ca6 (patch) | |
tree | 4f6ff921e8a7de9b7922369c97731e54f647ea33 /core/fxcrt/cfx_memorystream.h | |
parent | 03f5bab415cda066855e2672154358056649c584 (diff) | |
download | pdfium-283a0433b081f88275b2f7e8c04d3c41b9187ca6.tar.xz |
Convert IFX_MemoryStream to CFX_MemoryStream
The CFX_MemoryStream is the only implementation of IFX_MemoryStream.
This CL removes the interfaces and uses CFX_MemoryStream directly.
Change-Id: I2f43fa39e82dafa7673517d214ae15fd2d0df331
Reviewed-on: https://pdfium-review.googlesource.com/4391
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_memorystream.h')
-rw-r--r-- | core/fxcrt/cfx_memorystream.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_memorystream.h b/core/fxcrt/cfx_memorystream.h new file mode 100644 index 0000000000..2112280237 --- /dev/null +++ b/core/fxcrt/cfx_memorystream.h @@ -0,0 +1,56 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXCRT_CFX_MEMORYSTREAM_H_ +#define CORE_FXCRT_CFX_MEMORYSTREAM_H_ + +#include <vector> + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_stream.h" + +class CFX_MemoryStream : public IFX_SeekableStream { + public: + enum Type { kConsecutive = 1 << 0, kTakeOver = 1 << 1 }; + + template <typename T, typename... Args> + friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); + + // IFX_SeekableStream + FX_FILESIZE GetSize() override; + FX_FILESIZE GetPosition() override; + bool IsEOF() override; + bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; + size_t ReadBlock(void* buffer, size_t size) override; + bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; + bool Flush() override; + + bool IsConsecutive() const { return !!(m_dwFlags & Type::kConsecutive); } + + uint8_t* GetBuffer() const { + return !m_Blocks.empty() ? m_Blocks.front() : nullptr; + } + + void EstimateSize(size_t nInitSize, size_t nGrowSize); + void AttachBuffer(uint8_t* pBuffer, size_t nSize); + void DetachBuffer(); + + private: + explicit CFX_MemoryStream(bool bConsecutive); + CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, bool bTakeOver); + ~CFX_MemoryStream() override; + + bool ExpandBlocks(size_t size); + + std::vector<uint8_t*> m_Blocks; + size_t m_nTotalSize; + size_t m_nCurSize; + size_t m_nCurPos; + size_t m_nGrowSize; + uint32_t m_dwFlags; +}; + +#endif // CORE_FXCRT_CFX_MEMORYSTREAM_H_ |