blob: a93427ff8580d02eb78f08b63d86b7aa9267af63 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- DataBufferHeap.cpp --------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/DataBufferHeap.h"
11
12using namespace lldb_private;
13
14//----------------------------------------------------------------------
15// Default constructor
16//----------------------------------------------------------------------
17DataBufferHeap::DataBufferHeap () :
18 m_data()
19{
20}
21
22//----------------------------------------------------------------------
23// Initialize this class with "n" characters and fill the buffer
24// with "ch".
25//----------------------------------------------------------------------
26DataBufferHeap::DataBufferHeap (size_t n, uint8_t ch) :
27 m_data(n, ch)
28{
29}
30
31//----------------------------------------------------------------------
32// Initialize this class with a copy of the "n" bytes from the "bytes"
33// buffer.
34//----------------------------------------------------------------------
35DataBufferHeap::DataBufferHeap (const void *src, size_t src_len) :
36 m_data()
37{
38 CopyData (src, src_len);
39}
40
41//----------------------------------------------------------------------
42// Virtual destructor since this class inherits from a pure virtual
43// base class.
44//----------------------------------------------------------------------
45DataBufferHeap::~DataBufferHeap ()
46{
47}
48
49//----------------------------------------------------------------------
50// Return a pointer to the bytes owned by this object, or NULL if
51// the object contains no bytes.
52//----------------------------------------------------------------------
53uint8_t *
54DataBufferHeap::GetBytes ()
55{
56 if (m_data.empty())
57 return NULL;
58 return &m_data[0];
59}
60
61//----------------------------------------------------------------------
62// Return a const pointer to the bytes owned by this object, or NULL
63// if the object contains no bytes.
64//----------------------------------------------------------------------
65const uint8_t *
66DataBufferHeap::GetBytes () const
67{
68 if (m_data.empty())
69 return NULL;
70 return &m_data[0];
71}
72
73//----------------------------------------------------------------------
74// Return the number of bytes this object currently contains.
75//----------------------------------------------------------------------
76size_t
77DataBufferHeap::GetByteSize () const
78{
79 return m_data.size();
80}
81
82
83//----------------------------------------------------------------------
84// Sets the number of bytes that this object should be able to
85// contain. This can be used prior to copying data into the buffer.
86//----------------------------------------------------------------------
87size_t
88DataBufferHeap::SetByteSize (size_t new_size)
89{
90 m_data.resize(new_size);
91 return m_data.size();
92}
93
94void
95DataBufferHeap::CopyData (const void *src, size_t src_len)
96{
97 const uint8_t *src_u8 = (const uint8_t *)src;
98 if (src && src_len > 0)
99 m_data.assign (src_u8, src_u8 + src_len);
100 else
101 m_data.clear();
102}
103
104
105