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_
15 #include "lldb/lldb-private.h"
16 #include "lldb/Core/DataBuffer.h"
18 namespace lldb_private {
20 //----------------------------------------------------------------------
21 /// @class DataBufferHeap DataBufferHeap.h "lldb/Core/DataBufferHeap.h"
22 /// @brief A subclass of DataBuffer that stores a data buffer on the heap.
24 /// This class keeps its data in a heap based buffer that is owned by
25 /// the object. This class is best used to store chunks of data that
26 /// are created or read from sources that can't intelligently and lazily
27 /// fault new data pages in. Large amounts of data that comes from files
28 /// should probably use the DataBufferMemoryMap class.
29 //----------------------------------------------------------------------
30 class DataBufferHeap : public DataBuffer
33 //------------------------------------------------------------------
34 /// Default constructor
36 /// Initializes the heap based buffer with no bytes.
37 //------------------------------------------------------------------
40 //------------------------------------------------------------------
41 /// Construct with size \a n and fill with \a ch.
43 /// Initialize this class with \a n bytes and fills the buffer with
47 /// The number of bytes that heap based buffer should contain.
50 /// The character to use when filling the buffer initially.
51 //------------------------------------------------------------------
52 DataBufferHeap (lldb::offset_t n, uint8_t ch);
54 //------------------------------------------------------------------
55 /// Construct by making a copy of \a src_len bytes from \a src.
58 /// A pointer to the data to copy.
60 /// @param[in] src_len
61 /// The number of bytes in \a src to copy.
62 //------------------------------------------------------------------
63 DataBufferHeap (const void *src, lldb::offset_t src_len);
65 //------------------------------------------------------------------
68 /// Virtual destructor since this class inherits from a pure virtual
69 /// base class #DataBuffer.
70 //------------------------------------------------------------------
71 ~DataBufferHeap() override;
73 //------------------------------------------------------------------
74 /// @copydoc DataBuffer::GetBytes()
75 //------------------------------------------------------------------
79 //------------------------------------------------------------------
80 /// @copydoc DataBuffer::GetBytes() const
81 //------------------------------------------------------------------
83 GetBytes () const override;
85 //------------------------------------------------------------------
86 /// @copydoc DataBuffer::GetByteSize() const
87 //------------------------------------------------------------------
89 GetByteSize () const override;
91 //------------------------------------------------------------------
92 /// Set the number of bytes in the data buffer.
94 /// Sets the number of bytes that this object should be able to
95 /// contain. This can be used prior to copying data into the buffer.
97 /// @param[in] byte_size
98 /// The new size in bytes that this data buffer should attempt
99 /// to resize itself to.
102 /// The size in bytes after that this heap buffer was
103 /// successfully resized to.
104 //------------------------------------------------------------------
106 SetByteSize (lldb::offset_t byte_size);
108 //------------------------------------------------------------------
109 /// Makes a copy of the \a src_len bytes in \a src.
111 /// Copies the data in \a src into an internal buffer.
114 /// A pointer to the data to copy.
116 /// @param[in] src_len
117 /// The number of bytes in \a src to copy.
118 //------------------------------------------------------------------
120 CopyData (const void *src, lldb::offset_t src_len);
123 AppendData (const void *src, uint64_t src_len);
129 //------------------------------------------------------------------
130 // This object uses a std::vector<uint8_t> to store its data. This
131 // takes care of free the data when the object is deleted.
132 //------------------------------------------------------------------
133 typedef std::vector<uint8_t> buffer_t; ///< Buffer type
134 buffer_t m_data; ///< The heap based buffer where data is stored
137 } // namespace lldb_private
139 #endif // liblldb_DataBufferHeap_h_