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