LLDB  mainline
DataBufferHeap.cpp
Go to the documentation of this file.
1 //===-- DataBufferHeap.cpp --------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 
12 using namespace lldb_private;
13 
14 // Default constructor
16 
17 // Initialize this class with "n" characters and fill the buffer with "ch".
19  if (n < m_data.max_size())
20  m_data.assign(n, ch);
21 }
22 
23 // Initialize this class with a copy of the "n" bytes from the "bytes" buffer.
25  : m_data() {
26  CopyData(src, src_len);
27 }
28 
29 // Virtual destructor since this class inherits from a pure virtual base class.
31 
32 // Return a pointer to the bytes owned by this object, or nullptr if the object
33 // contains no bytes.
35  return (m_data.empty() ? nullptr : m_data.data());
36 }
37 
38 // Return a const pointer to the bytes owned by this object, or nullptr if the
39 // object contains no bytes.
40 const uint8_t *DataBufferHeap::GetBytes() const {
41  return (m_data.empty() ? nullptr : m_data.data());
42 }
43 
44 // Return the number of bytes this object currently contains.
45 uint64_t DataBufferHeap::GetByteSize() const { return m_data.size(); }
46 
47 // Sets the number of bytes that this object should be able to contain. This
48 // can be used prior to copying data into the buffer.
49 uint64_t DataBufferHeap::SetByteSize(uint64_t new_size) {
50  m_data.resize(new_size);
51  return m_data.size();
52 }
53 
54 void DataBufferHeap::CopyData(const void *src, uint64_t src_len) {
55  const uint8_t *src_u8 = (const uint8_t *)src;
56  if (src && src_len > 0)
57  m_data.assign(src_u8, src_u8 + src_len);
58  else
59  m_data.clear();
60 }
61 
62 void DataBufferHeap::AppendData(const void *src, uint64_t src_len) {
63  m_data.insert(m_data.end(), (const uint8_t *)src,
64  (const uint8_t *)src + src_len);
65 }
66 
68  buffer_t empty;
69  m_data.swap(empty);
70 }
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
lldb::offset_t SetByteSize(lldb::offset_t byte_size)
Set the number of bytes in the data buffer.
void AppendData(const void *src, uint64_t src_len)
uint64_t offset_t
Definition: lldb-types.h:87
DataBufferHeap()
Default constructor.
~DataBufferHeap() override
Destructor.
uint8_t * GetBytes() override
lldb::offset_t GetByteSize() const override
void CopyData(const void *src, lldb::offset_t src_len)
Makes a copy of the src_len bytes in src.