]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/DataBufferHeap.h
Merge ^/head r293036 through r293174.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / DataBufferHeap.h
1 //===-- DataBufferHeap.h ----------------------------------------*- 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 #ifndef liblldb_DataBufferHeap_h_
11 #define liblldb_DataBufferHeap_h_
12
13 #include <vector>
14
15 #include "lldb/lldb-private.h"
16 #include "lldb/Core/DataBuffer.h"
17
18 namespace lldb_private {
19
20 //----------------------------------------------------------------------
21 /// @class DataBufferHeap DataBufferHeap.h "lldb/Core/DataBufferHeap.h"
22 /// @brief A subclass of DataBuffer that stores a data buffer on the heap.
23 ///
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
31 {
32 public:
33     //------------------------------------------------------------------
34     /// Default constructor
35     ///
36     /// Initializes the heap based buffer with no bytes.
37     //------------------------------------------------------------------
38     DataBufferHeap ();
39
40     //------------------------------------------------------------------
41     /// Construct with size \a n and fill with \a ch.
42     ///
43     /// Initialize this class with \a n bytes and fills the buffer with
44     /// \a ch.
45     ///
46     /// @param[in] n
47     ///     The number of bytes that heap based buffer should contain.
48     ///
49     /// @param[in] ch
50     ///     The character to use when filling the buffer initially.
51     //------------------------------------------------------------------
52     DataBufferHeap (lldb::offset_t n, uint8_t ch);
53
54     //------------------------------------------------------------------
55     /// Construct by making a copy of \a src_len bytes from \a src.
56     ///
57     /// @param[in] src
58     ///     A pointer to the data to copy.
59     ///
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);
64
65     //------------------------------------------------------------------
66     /// Destructor.
67     ///
68     /// Virtual destructor since this class inherits from a pure virtual
69     /// base class #DataBuffer.
70     //------------------------------------------------------------------
71     ~DataBufferHeap() override;
72
73     //------------------------------------------------------------------
74     /// @copydoc DataBuffer::GetBytes()
75     //------------------------------------------------------------------
76     uint8_t *
77     GetBytes () override;
78
79     //------------------------------------------------------------------
80     /// @copydoc DataBuffer::GetBytes() const
81     //------------------------------------------------------------------
82     const uint8_t *
83     GetBytes () const override;
84
85     //------------------------------------------------------------------
86     /// @copydoc DataBuffer::GetByteSize() const
87     //------------------------------------------------------------------
88     lldb::offset_t
89     GetByteSize () const override;
90
91     //------------------------------------------------------------------
92     /// Set the number of bytes in the data buffer.
93     ///
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.
96     ///
97     /// @param[in] byte_size
98     ///     The new size in bytes that this data buffer should attempt
99     ///     to resize itself to.
100     ///
101     /// @return
102     ///     The size in bytes after that this heap buffer was
103     ///     successfully resized to.
104     //------------------------------------------------------------------
105     lldb::offset_t
106     SetByteSize (lldb::offset_t byte_size);
107
108     //------------------------------------------------------------------
109     /// Makes a copy of the \a src_len bytes in \a src.
110     ///
111     /// Copies the data in \a src into an internal buffer.
112     ///
113     /// @param[in] src
114     ///     A pointer to the data to copy.
115     ///
116     /// @param[in] src_len
117     ///     The number of bytes in \a src to copy.
118     //------------------------------------------------------------------
119     void
120     CopyData (const void *src, lldb::offset_t src_len);
121
122     void
123     AppendData (const void *src, uint64_t src_len);
124
125     void
126     Clear();
127
128 private:
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
135 };
136
137 } // namespace lldb_private
138
139 #endif // liblldb_DataBufferHeap_h_