1 //===-- DataBufferHeap.h ----------------------------------------*- 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 #ifndef liblldb_DataBufferHeap_h_
11 #define liblldb_DataBufferHeap_h_
12 #if defined(__cplusplus)
16 #include "lldb/lldb-private.h"
17 #include "lldb/Core/DataBuffer.h"
19 namespace lldb_private {
21 //----------------------------------------------------------------------
22 /// @class DataBufferHeap DataBufferHeap.h "lldb/Core/DataBufferHeap.h"
23 /// @brief A subclass of DataBuffer that stores a data buffer on the heap.
25 /// This class keeps its data in a heap based buffer that is owned by
26 /// the object. This class is best used to store chunks of data that
27 /// are created or read from sources that can't intelligently and lazily
28 /// fault new data pages in. Large amounts of data that comes from files
29 /// should probably use the DataBufferMemoryMap class.
30 //----------------------------------------------------------------------
31 class DataBufferHeap : public DataBuffer
34 //------------------------------------------------------------------
35 /// Default constructor
37 /// Initializes the heap based buffer with no bytes.
38 //------------------------------------------------------------------
41 //------------------------------------------------------------------
42 /// Construct with size \a n and fill with \a ch.
44 /// Initialize this class with \a n bytes and fills the buffer with
48 /// The number of bytes that heap based buffer should contain.
51 /// The character to use when filling the buffer initially.
52 //------------------------------------------------------------------
53 DataBufferHeap (lldb::offset_t n, uint8_t ch);
55 //------------------------------------------------------------------
56 /// Construct by making a copy of \a src_len bytes from \a src.
59 /// A pointer to the data to copy.
61 /// @param[in] src_len
62 /// The number of bytes in \a src to copy.
63 //------------------------------------------------------------------
64 DataBufferHeap (const void *src, lldb::offset_t src_len);
66 //------------------------------------------------------------------
69 /// Virtual destructor since this class inherits from a pure virtual
70 /// base class #DataBuffer.
71 //------------------------------------------------------------------
75 //------------------------------------------------------------------
76 /// @copydoc DataBuffer::GetBytes()
77 //------------------------------------------------------------------
81 //------------------------------------------------------------------
82 /// @copydoc DataBuffer::GetBytes() const
83 //------------------------------------------------------------------
84 virtual const uint8_t *
87 //------------------------------------------------------------------
88 /// @copydoc DataBuffer::GetByteSize() const
89 //------------------------------------------------------------------
90 virtual lldb::offset_t
93 //------------------------------------------------------------------
94 /// Set the number of bytes in the data buffer.
96 /// Sets the number of bytes that this object should be able to
97 /// contain. This can be used prior to copying data into the buffer.
99 /// @param[in] byte_size
100 /// The new size in bytes that this data buffer should attempt
101 /// to resize itself to.
104 /// The size in bytes after that this heap buffer was
105 /// successfully resized to.
106 //------------------------------------------------------------------
108 SetByteSize (lldb::offset_t byte_size);
110 //------------------------------------------------------------------
111 /// Makes a copy of the \a src_len bytes in \a src.
113 /// Copies the data in \a src into an internal buffer.
116 /// A pointer to the data to copy.
118 /// @param[in] src_len
119 /// The number of bytes in \a src to copy.
120 //------------------------------------------------------------------
122 CopyData (const void *src, lldb::offset_t src_len);
125 AppendData (const void *src, uint64_t src_len);
131 //------------------------------------------------------------------
132 // This object uses a std::vector<uint8_t> to store its data. This
133 // takes care of free the data when the object is deleted.
134 //------------------------------------------------------------------
135 typedef std::vector<uint8_t> buffer_t; ///< Buffer type
136 buffer_t m_data; ///< The heap based buffer where data is stored
139 } // namespace lldb_private
141 #endif // #if defined(__cplusplus)
142 #endif // liblldb_DataBufferHeap_h_