|
|
|||
File indexing completed on 2026-05-10 08:42:57
0001 //===-- DataBufferHeap.h ----------------------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLDB_UTILITY_DATABUFFERHEAP_H 0010 #define LLDB_UTILITY_DATABUFFERHEAP_H 0011 0012 #include "lldb/Utility/DataBuffer.h" 0013 #include "lldb/lldb-types.h" 0014 #include "llvm/ADT/StringRef.h" 0015 0016 #include <cstdint> 0017 #include <vector> 0018 0019 namespace lldb_private { 0020 0021 /// \class DataBufferHeap DataBufferHeap.h "lldb/Core/DataBufferHeap.h" 0022 /// A subclass of DataBuffer that stores a data buffer on the heap. 0023 /// 0024 /// This class keeps its data in a heap based buffer that is owned by the 0025 /// object. This class is best used to store chunks of data that are created 0026 /// or read from sources that can't intelligently and lazily fault new data 0027 /// pages in. Large amounts of data that comes from files should probably use 0028 /// DataBufferLLVM, which can intelligently determine when memory mapping is 0029 /// optimal. 0030 class DataBufferHeap : public WritableDataBuffer { 0031 public: 0032 /// Default constructor 0033 /// 0034 /// Initializes the heap based buffer with no bytes. 0035 DataBufferHeap(); 0036 0037 /// Construct with size \a n and fill with \a ch. 0038 /// 0039 /// Initialize this class with \a n bytes and fills the buffer with \a ch. 0040 /// 0041 /// \param[in] n 0042 /// The number of bytes that heap based buffer should contain. 0043 /// 0044 /// \param[in] ch 0045 /// The character to use when filling the buffer initially. 0046 DataBufferHeap(lldb::offset_t n, uint8_t ch); 0047 0048 /// Construct by making a copy of \a src_len bytes from \a src. 0049 /// 0050 /// \param[in] src 0051 /// A pointer to the data to copy. 0052 /// 0053 /// \param[in] src_len 0054 /// The number of bytes in \a src to copy. 0055 DataBufferHeap(const void *src, lldb::offset_t src_len); 0056 0057 /// Construct by making a copy of a DataBuffer. 0058 /// 0059 /// \param[in] data_buffer 0060 /// A read only data buffer to copy. 0061 DataBufferHeap(const DataBuffer &data_buffer); 0062 0063 /// Destructor. 0064 /// 0065 /// Virtual destructor since this class inherits from a pure virtual base 0066 /// class #DataBuffer. 0067 ~DataBufferHeap() override; 0068 0069 /// \copydoc DataBuffer::GetBytes() const 0070 const uint8_t *GetBytesImpl() const override; 0071 0072 /// \copydoc DataBuffer::GetByteSize() const 0073 lldb::offset_t GetByteSize() const override; 0074 0075 /// Set the number of bytes in the data buffer. 0076 /// 0077 /// Sets the number of bytes that this object should be able to contain. 0078 /// This can be used prior to copying data into the buffer. Note that this 0079 /// zero-initializes up to \p byte_size bytes. 0080 /// 0081 /// \param[in] byte_size 0082 /// The new size in bytes that this data buffer should attempt 0083 /// to resize itself to. 0084 /// 0085 /// \return 0086 /// The size in bytes after this heap buffer was resized. If 0087 /// the resize failed the size will remain unchanged. 0088 lldb::offset_t SetByteSize(lldb::offset_t byte_size); 0089 0090 /// Makes a copy of the \a src_len bytes in \a src. 0091 /// 0092 /// Copies the data in \a src into an internal buffer. 0093 /// 0094 /// \param[in] src 0095 /// A pointer to the data to copy. 0096 /// 0097 /// \param[in] src_len 0098 /// The number of bytes in \a src to copy. 0099 void CopyData(const void *src, lldb::offset_t src_len); 0100 void CopyData(llvm::StringRef src) { CopyData(src.data(), src.size()); } 0101 0102 void AppendData(const void *src, uint64_t src_len); 0103 0104 void Clear(); 0105 0106 /// LLVM RTTI support. 0107 /// { 0108 static char ID; 0109 bool isA(const void *ClassID) const override { 0110 return ClassID == &ID || WritableDataBuffer::isA(ClassID); 0111 } 0112 static bool classof(const DataBuffer *data_buffer) { 0113 return data_buffer->isA(&ID); 0114 } 0115 /// } 0116 0117 private: 0118 // This object uses a std::vector<uint8_t> to store its data. This takes care 0119 // of free the data when the object is deleted. 0120 typedef std::vector<uint8_t> buffer_t; ///< Buffer type 0121 buffer_t m_data; ///< The heap based buffer where data is stored 0122 }; 0123 0124 } // namespace lldb_private 0125 0126 #endif // LLDB_UTILITY_DATABUFFERHEAP_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|