• 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_BLOCKBUFFER_H_
8 #define CORE_FXCRT_CFX_BLOCKBUFFER_H_
9 
10 #include <stdint.h>
11 
12 #include <memory>
13 #include <utility>
14 #include <vector>
15 
16 #include "core/fxcrt/fx_string.h"
17 
18 class CFX_BlockBuffer {
19  public:
20   CFX_BlockBuffer();
21   ~CFX_BlockBuffer();
22 
23   bool InitBuffer();
IsInitialized()24   bool IsInitialized() { return m_BufferSize / GetAllocStep() >= 1; }
25 
26   std::pair<wchar_t*, size_t> GetAvailableBlock();
27   size_t GetAllocStep() const;
GetDataLength()28   size_t GetDataLength() const { return m_DataLength; }
IncrementDataLength()29   void IncrementDataLength() { m_DataLength++; }
IsEmpty()30   bool IsEmpty() const { return m_DataLength == 0; }
31 
Reset(bool bReserveData)32   void Reset(bool bReserveData) {
33     if (!bReserveData)
34       m_StartPosition = 0;
35     m_DataLength = 0;
36   }
37 
38   void SetTextChar(size_t iIndex, wchar_t ch);
39   void DeleteTextChars(size_t iCount);
40   WideString GetTextData(size_t iStart, size_t iLength) const;
41 
42  private:
43   std::pair<size_t, size_t> TextDataIndex2BufIndex(const size_t iIndex) const;
44 
45   std::vector<std::unique_ptr<wchar_t, FxFreeDeleter>> m_BlockArray;
46   size_t m_DataLength;
47   size_t m_BufferSize;
48   size_t m_StartPosition;
49 };
50 
51 #endif  // CORE_FXCRT_CFX_BLOCKBUFFER_H_
52