26#include <system_error>
47 const uint8_t* m_bufferStart;
48 const uint8_t* m_bufferEnd;
53 void Init(
const uint8_t* bufStart,
const uint8_t* bufEnd);
60 const uint8_t*
begin()
const {
return m_bufferStart; }
61 const uint8_t*
end()
const {
return m_bufferEnd; }
62 size_t size()
const {
return m_bufferEnd - m_bufferStart; }
67 return {
reinterpret_cast<const char*
>(
begin()),
68 reinterpret_cast<const char*
>(
end())};
74 return "Unknown buffer";
82 GetFile(std::string_view filename, int64_t fileSize = -1);
88 std::string_view filename, std::error_code& ec);
93 fs::file_t f, std::string_view filename, std::error_code& ec,
94 uint64_t mapSize, int64_t offset);
99 std::string_view filename,
105 std::span<const uint8_t> inputData, std::string_view bufferName =
"");
112 std::span<const uint8_t> inputData, std::string_view bufferName =
"");
115 static std::unique_ptr<MemoryBuffer>
GetFileSlice(std::string_view filename,
154 return {
reinterpret_cast<char*
>(
const_cast<uint8_t*
>(
begin())),
155 reinterpret_cast<char*
>(
const_cast<uint8_t*
>(
end()))};
158 static std::unique_ptr<WritableMemoryBuffer>
GetFile(
159 std::string_view filename, std::error_code& ec, int64_t fileSize = -1);
163 std::string_view filename, std::error_code& ec, uint64_t mapSize,
170 size_t size, std::string_view bufferName =
"");
176 size_t size, std::string_view bufferName =
"");
209 return {
reinterpret_cast<char*
>(
const_cast<uint8_t*
>(
begin())),
210 reinterpret_cast<char*
>(
const_cast<uint8_t*
>(
end()))};
213 static std::unique_ptr<WriteThroughMemoryBuffer>
GetFile(
214 std::string_view filename, std::error_code& ec, int64_t fileSize = -1);
218 std::string_view filename, std::error_code& ec, uint64_t mapSize,
233 std::span<const uint8_t> m_buffer;
234 std::string_view m_id;
241 : m_buffer(buffer), m_id(id) {}
243 std::span<const uint8_t>
GetBuffer()
const {
return m_buffer; }
247 const uint8_t*
begin()
const {
return &*m_buffer.begin(); }
248 const uint8_t*
end()
const {
return &*m_buffer.end(); }
249 size_t size()
const {
return m_buffer.size(); }
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition MemoryBuffer.h:46
static std::unique_ptr< MemoryBuffer > GetOpenFileSlice(fs::file_t f, std::string_view filename, std::error_code &ec, uint64_t mapSize, int64_t offset)
Given an already-open file descriptor, map some slice of it into a MemoryBuffer.
static wpi::expected< std::unique_ptr< MemoryBuffer >, std::error_code > GetFile(std::string_view filename, int64_t fileSize=-1)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
BufferKind
The kind of memory backing used to support the MemoryBuffer.
Definition MemoryBuffer.h:125
@ MemoryBuffer_Malloc
Definition MemoryBuffer.h:125
@ MemoryBuffer_MMap
Definition MemoryBuffer.h:125
virtual std::string_view GetBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition MemoryBuffer.h:73
static std::unique_ptr< MemoryBuffer > GetOpenFile(fs::file_t f, std::string_view filename, std::error_code &ec, uint64_t fileSize)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > GetMemBuffer(std::span< const uint8_t > inputData, std::string_view bufferName="")
Open the specified memory range as a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > GetMemBufferCopy(std::span< const uint8_t > inputData, std::string_view bufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
const uint8_t * begin() const
Definition MemoryBuffer.h:60
std::span< const uint8_t > GetBuffer() const
Definition MemoryBuffer.h:64
virtual BufferKind GetBufferKind() const =0
Return information on the memory mechanism used to support the MemoryBuffer.
static std::unique_ptr< MemoryBuffer > GetFileSlice(std::string_view filename, std::error_code &ec, uint64_t mapSize, uint64_t offset)
Map a subrange of the specified file as a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > GetFileAsStream(std::string_view filename, std::error_code &ec)
Read all of the specified file into a MemoryBuffer as a stream (i.e.
MemoryBuffer(const MemoryBuffer &)=delete
MemoryBuffer & operator=(const MemoryBuffer &)=delete
const uint8_t * end() const
Definition MemoryBuffer.h:61
void Init(const uint8_t *bufStart, const uint8_t *bufEnd)
MemoryBufferRef GetMemBufferRef() const
static std::unique_ptr< MemoryBuffer > GetMemBuffer(MemoryBufferRef ref)
std::span< const char > GetCharBuffer() const
Definition MemoryBuffer.h:66
size_t size() const
Definition MemoryBuffer.h:62
Definition MemoryBuffer.h:232
std::string_view GetBufferIdentifier() const
Definition MemoryBuffer.h:245
MemoryBufferRef(MemoryBuffer &buffer)
Definition MemoryBuffer.h:238
std::span< const uint8_t > GetBuffer() const
Definition MemoryBuffer.h:243
MemoryBufferRef(std::span< const uint8_t > buffer, std::string_view id)
Definition MemoryBuffer.h:240
const uint8_t * begin() const
Definition MemoryBuffer.h:247
MemoryBufferRef()=default
size_t size() const
Definition MemoryBuffer.h:249
const uint8_t * end() const
Definition MemoryBuffer.h:248
This class is an extension of MemoryBuffer, which allows copy-on-write access to the underlying conte...
Definition MemoryBuffer.h:138
WritableMemoryBuffer()=default
static std::unique_ptr< WritableMemoryBuffer > GetFile(std::string_view filename, std::error_code &ec, int64_t fileSize=-1)
static std::unique_ptr< WritableMemoryBuffer > GetFileSlice(std::string_view filename, std::error_code &ec, uint64_t mapSize, uint64_t offset)
Map a subrange of the specified file as a WritableMemoryBuffer.
uint8_t * end()
Definition MemoryBuffer.h:151
std::span< uint8_t > GetBuffer()
Definition MemoryBuffer.h:152
uint8_t * begin()
Definition MemoryBuffer.h:150
static std::unique_ptr< WritableMemoryBuffer > GetNewMemBuffer(size_t size, std::string_view bufferName="")
Allocate a new zero-initialized MemoryBuffer of the specified size.
static std::unique_ptr< WritableMemoryBuffer > GetNewUninitMemBuffer(size_t size, std::string_view bufferName="")
Allocate a new MemoryBuffer of the specified size that is not initialized.
std::span< char > GetCharBuffer() const
Definition MemoryBuffer.h:153
This class is an extension of MemoryBuffer, which allows write access to the underlying contents and ...
Definition MemoryBuffer.h:193
static std::unique_ptr< WriteThroughMemoryBuffer > GetFileSlice(std::string_view filename, std::error_code &ec, uint64_t mapSize, uint64_t offset)
Map a subrange of the specified file as a ReadWriteMemoryBuffer.
WriteThroughMemoryBuffer()=default
static std::unique_ptr< WriteThroughMemoryBuffer > GetFile(std::string_view filename, std::error_code &ec, int64_t fileSize=-1)
std::span< char > GetCharBuffer() const
Definition MemoryBuffer.h:208
std::span< uint8_t > GetBuffer()
Definition MemoryBuffer.h:207
uint8_t * begin()
Definition MemoryBuffer.h:205
uint8_t * end()
Definition MemoryBuffer.h:206
An expected<T, E> object is an object that contains the storage for another object and manages the li...
Definition expected:1250
Definition MappedFileRegion.h:12
int file_t
Definition MappedFileRegion.h:17
Foonathan namespace.
Definition ntcore_cpp.h:26