1 //===-- DataBufferHeap.cpp --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/DataBufferHeap.h"
12 using namespace lldb_private;
14 //----------------------------------------------------------------------
15 // Default constructor
16 //----------------------------------------------------------------------
17 DataBufferHeap::DataBufferHeap () :
22 //----------------------------------------------------------------------
23 // Initialize this class with "n" characters and fill the buffer
25 //----------------------------------------------------------------------
26 DataBufferHeap::DataBufferHeap (lldb::offset_t n, uint8_t ch) :
29 if (n < m_data.max_size())
30 m_data.assign (n, ch);
33 //----------------------------------------------------------------------
34 // Initialize this class with a copy of the "n" bytes from the "bytes"
36 //----------------------------------------------------------------------
37 DataBufferHeap::DataBufferHeap (const void *src, lldb::offset_t src_len) :
40 CopyData (src, src_len);
43 //----------------------------------------------------------------------
44 // Virtual destructor since this class inherits from a pure virtual
46 //----------------------------------------------------------------------
47 DataBufferHeap::~DataBufferHeap ()
51 //----------------------------------------------------------------------
52 // Return a pointer to the bytes owned by this object, or NULL if
53 // the object contains no bytes.
54 //----------------------------------------------------------------------
56 DataBufferHeap::GetBytes ()
63 //----------------------------------------------------------------------
64 // Return a const pointer to the bytes owned by this object, or NULL
65 // if the object contains no bytes.
66 //----------------------------------------------------------------------
68 DataBufferHeap::GetBytes () const
75 //----------------------------------------------------------------------
76 // Return the number of bytes this object currently contains.
77 //----------------------------------------------------------------------
79 DataBufferHeap::GetByteSize () const
85 //----------------------------------------------------------------------
86 // Sets the number of bytes that this object should be able to
87 // contain. This can be used prior to copying data into the buffer.
88 //----------------------------------------------------------------------
90 DataBufferHeap::SetByteSize (uint64_t new_size)
92 m_data.resize(new_size);
97 DataBufferHeap::CopyData (const void *src, uint64_t src_len)
99 const uint8_t *src_u8 = (const uint8_t *)src;
100 if (src && src_len > 0)
101 m_data.assign (src_u8, src_u8 + src_len);
107 DataBufferHeap::Clear()