]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Utility/DataBufferHeap.h
Upgrade Unbound to 1.6.8. More to follow.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Utility / 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 "lldb/Utility/DataBuffer.h"
14 #include "lldb/lldb-types.h"    // for offset_t
15 #include "llvm/ADT/StringRef.h" // for StringRef
16
17 #include <cstdint> // for uint8_t, uint64_t
18 #include <vector>
19
20 namespace lldb_private {
21
22 //----------------------------------------------------------------------
23 /// @class DataBufferHeap DataBufferHeap.h "lldb/Core/DataBufferHeap.h"
24 /// @brief A subclass of DataBuffer that stores a data buffer on the heap.
25 ///
26 /// This class keeps its data in a heap based buffer that is owned by
27 /// the object. This class is best used to store chunks of data that
28 /// are created or read from sources that can't intelligently and lazily
29 /// fault new data pages in. Large amounts of data that comes from files
30 /// should probably use DataBufferLLVM, which can intelligently determine
31 /// when memory mapping is optimal.
32 //----------------------------------------------------------------------
33 class DataBufferHeap : public DataBuffer {
34 public:
35   //------------------------------------------------------------------
36   /// Default constructor
37   ///
38   /// Initializes the heap based buffer with no bytes.
39   //------------------------------------------------------------------
40   DataBufferHeap();
41
42   //------------------------------------------------------------------
43   /// Construct with size \a n and fill with \a ch.
44   ///
45   /// Initialize this class with \a n bytes and fills the buffer with
46   /// \a ch.
47   ///
48   /// @param[in] n
49   ///     The number of bytes that heap based buffer should contain.
50   ///
51   /// @param[in] ch
52   ///     The character to use when filling the buffer initially.
53   //------------------------------------------------------------------
54   DataBufferHeap(lldb::offset_t n, uint8_t ch);
55
56   //------------------------------------------------------------------
57   /// Construct by making a copy of \a src_len bytes from \a src.
58   ///
59   /// @param[in] src
60   ///     A pointer to the data to copy.
61   ///
62   /// @param[in] src_len
63   ///     The number of bytes in \a src to copy.
64   //------------------------------------------------------------------
65   DataBufferHeap(const void *src, lldb::offset_t src_len);
66
67   //------------------------------------------------------------------
68   /// Destructor.
69   ///
70   /// Virtual destructor since this class inherits from a pure virtual
71   /// base class #DataBuffer.
72   //------------------------------------------------------------------
73   ~DataBufferHeap() override;
74
75   //------------------------------------------------------------------
76   /// @copydoc DataBuffer::GetBytes()
77   //------------------------------------------------------------------
78   uint8_t *GetBytes() override;
79
80   //------------------------------------------------------------------
81   /// @copydoc DataBuffer::GetBytes() const
82   //------------------------------------------------------------------
83   const uint8_t *GetBytes() const override;
84
85   //------------------------------------------------------------------
86   /// @copydoc DataBuffer::GetByteSize() const
87   //------------------------------------------------------------------
88   lldb::offset_t GetByteSize() const override;
89
90   //------------------------------------------------------------------
91   /// Set the number of bytes in the data buffer.
92   ///
93   /// Sets the number of bytes that this object should be able to
94   /// contain. This can be used prior to copying data into the buffer.
95   ///
96   /// @param[in] byte_size
97   ///     The new size in bytes that this data buffer should attempt
98   ///     to resize itself to.
99   ///
100   /// @return
101   ///     The size in bytes after that this heap buffer was
102   ///     successfully resized to.
103   //------------------------------------------------------------------
104   lldb::offset_t SetByteSize(lldb::offset_t byte_size);
105
106   //------------------------------------------------------------------
107   /// Makes a copy of the \a src_len bytes in \a src.
108   ///
109   /// Copies the data in \a src into an internal buffer.
110   ///
111   /// @param[in] src
112   ///     A pointer to the data to copy.
113   ///
114   /// @param[in] src_len
115   ///     The number of bytes in \a src to copy.
116   //------------------------------------------------------------------
117   void CopyData(const void *src, lldb::offset_t src_len);
118   void CopyData(llvm::StringRef src) { CopyData(src.data(), src.size()); }
119
120   void AppendData(const void *src, uint64_t src_len);
121
122   void Clear();
123
124 private:
125   //------------------------------------------------------------------
126   // This object uses a std::vector<uint8_t> to store its data. This
127   // takes care of free the data when the object is deleted.
128   //------------------------------------------------------------------
129   typedef std::vector<uint8_t> buffer_t; ///< Buffer type
130   buffer_t m_data; ///< The heap based buffer where data is stored
131 };
132
133 } // namespace lldb_private
134
135 #endif // liblldb_DataBufferHeap_h_