From cd07123993c2f6cfd2d08929e6ad27cab3ac74e9 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 30 Aug 2017 16:21:36 -0400 Subject: Move CFX_BinaryBuf out of fx_basic This CL splits the CFX_BinaryBuf out of fx_basic into its own files. The various includes have been updated. Change-Id: I0fa616eeb4df6dd229c02dc3a0597b3dced59425 Reviewed-on: https://pdfium-review.googlesource.com/12412 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- core/fxcrt/cfx_binarybuf.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 core/fxcrt/cfx_binarybuf.h (limited to 'core/fxcrt/cfx_binarybuf.h') diff --git a/core/fxcrt/cfx_binarybuf.h b/core/fxcrt/cfx_binarybuf.h new file mode 100644 index 0000000000..3081d02902 --- /dev/null +++ b/core/fxcrt/cfx_binarybuf.h @@ -0,0 +1,52 @@ +// 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_BINARYBUF_H_ +#define CORE_FXCRT_CFX_BINARYBUF_H_ + +#include + +#include "core/fxcrt/fx_memory.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxcrt/fx_system.h" + +class CFX_BinaryBuf { + public: + CFX_BinaryBuf(); + explicit CFX_BinaryBuf(FX_STRSIZE size); + ~CFX_BinaryBuf(); + + uint8_t* GetBuffer() const { return m_pBuffer.get(); } + FX_STRSIZE GetSize() const { return m_DataSize; } + + void Clear(); + void EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0); + void AppendBlock(const void* pBuf, FX_STRSIZE size); + void AppendString(const CFX_ByteString& str) { + AppendBlock(str.c_str(), str.GetLength()); + } + + void AppendByte(uint8_t byte) { + ExpandBuf(1); + m_pBuffer.get()[m_DataSize++] = byte; + } + + void InsertBlock(FX_STRSIZE pos, const void* pBuf, FX_STRSIZE size); + void Delete(FX_STRSIZE start_index, FX_STRSIZE count); + + // Releases ownership of |m_pBuffer| and returns it. + std::unique_ptr DetachBuffer(); + + protected: + void ExpandBuf(FX_STRSIZE size); + + FX_STRSIZE m_AllocStep; + FX_STRSIZE m_AllocSize; + FX_STRSIZE m_DataSize; + std::unique_ptr m_pBuffer; +}; + +#endif // CORE_FXCRT_CFX_BINARYBUF_H_ -- cgit v1.2.3