WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
wpi::util::MemoryBuffer Class Referenceabstract

This interface provides simple read-only access to a block of memory, and provides simple methods for reading files and standard input into a memory buffer. More...

#include <wpi/util/MemoryBuffer.hpp>

Inheritance diagram for wpi::util::MemoryBuffer:
wpi::util::SmallVectorMemoryBuffer wpi::util::WritableMemoryBuffer wpi::util::WriteThroughMemoryBuffer

Public Types

enum  BufferKind { MemoryBuffer_Malloc , MemoryBuffer_MMap }
 The kind of memory backing used to support the MemoryBuffer. More...

Public Member Functions

 MemoryBuffer (const MemoryBuffer &)=delete
MemoryBufferoperator= (const MemoryBuffer &)=delete
virtual ~MemoryBuffer ()
const uint8_t * begin () const
const uint8_t * end () const
size_t size () const
std::span< const uint8_t > GetBuffer () const
std::span< const char > GetCharBuffer () const
virtual std::string_view GetBufferIdentifier () const
 Return an identifier for this buffer, typically the filename it was read from.
virtual BufferKind GetBufferKind () const =0
 Return information on the memory mechanism used to support the MemoryBuffer.
MemoryBufferRef GetMemBufferRef () const

Static Public Member Functions

static wpi::util::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, otherwise returning null.
static std::unique_ptr< MemoryBufferGetFileAsStream (std::string_view filename, std::error_code &ec)
 Read all of the specified file into a MemoryBuffer as a stream (i.e.
static std::unique_ptr< MemoryBufferGetOpenFileSlice (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 std::unique_ptr< MemoryBufferGetOpenFile (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< MemoryBufferGetMemBuffer (std::span< const uint8_t > inputData, std::string_view bufferName="")
 Open the specified memory range as a MemoryBuffer.
static std::unique_ptr< MemoryBufferGetMemBuffer (MemoryBufferRef ref)
static std::unique_ptr< MemoryBufferGetMemBufferCopy (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.
static std::unique_ptr< MemoryBufferGetFileSlice (std::string_view filename, std::error_code &ec, uint64_t mapSize, uint64_t offset)
 Map a subrange of the specified file as a MemoryBuffer.

Protected Member Functions

 MemoryBuffer ()=default
void Init (const uint8_t *bufStart, const uint8_t *bufEnd)

Detailed Description

This interface provides simple read-only access to a block of memory, and provides simple methods for reading files and standard input into a memory buffer.

Member Enumeration Documentation

◆ BufferKind

The kind of memory backing used to support the MemoryBuffer.

Enumerator
MemoryBuffer_Malloc 
MemoryBuffer_MMap 

Constructor & Destructor Documentation

◆ MemoryBuffer() [1/2]

wpi::util::MemoryBuffer::MemoryBuffer ( )
protecteddefault

◆ MemoryBuffer() [2/2]

wpi::util::MemoryBuffer::MemoryBuffer ( const MemoryBuffer & )
delete

◆ ~MemoryBuffer()

virtual wpi::util::MemoryBuffer::~MemoryBuffer ( )
virtual

Member Function Documentation

◆ begin()

const uint8_t * wpi::util::MemoryBuffer::begin ( ) const
inline

◆ end()

const uint8_t * wpi::util::MemoryBuffer::end ( ) const
inline

◆ GetBuffer()

std::span< const uint8_t > wpi::util::MemoryBuffer::GetBuffer ( ) const
inline

◆ GetBufferIdentifier()

virtual std::string_view wpi::util::MemoryBuffer::GetBufferIdentifier ( ) const
inlinevirtual

Return an identifier for this buffer, typically the filename it was read from.

Reimplemented in wpi::util::SmallVectorMemoryBuffer.

◆ GetBufferKind()

virtual BufferKind wpi::util::MemoryBuffer::GetBufferKind ( ) const
pure virtual

Return information on the memory mechanism used to support the MemoryBuffer.

Implemented in wpi::util::SmallVectorMemoryBuffer.

◆ GetCharBuffer()

std::span< const char > wpi::util::MemoryBuffer::GetCharBuffer ( ) const
inline

◆ GetFile()

wpi::util::expected< std::unique_ptr< MemoryBuffer >, std::error_code > wpi::util::MemoryBuffer::GetFile ( std::string_view filename,
int64_t fileSize = -1 )
static

Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.

If FileSize is specified, this means that the client knows that the file exists and that it has the specified size.

◆ GetFileAsStream()

std::unique_ptr< MemoryBuffer > wpi::util::MemoryBuffer::GetFileAsStream ( std::string_view filename,
std::error_code & ec )
static

Read all of the specified file into a MemoryBuffer as a stream (i.e.

until EOF reached). This is useful for special files that look like a regular file but have 0 size (e.g. /proc/cpuinfo on Linux).

◆ GetFileSlice()

std::unique_ptr< MemoryBuffer > wpi::util::MemoryBuffer::GetFileSlice ( std::string_view filename,
std::error_code & ec,
uint64_t mapSize,
uint64_t offset )
static

Map a subrange of the specified file as a MemoryBuffer.

◆ GetMemBuffer() [1/2]

std::unique_ptr< MemoryBuffer > wpi::util::MemoryBuffer::GetMemBuffer ( MemoryBufferRef ref)
static

◆ GetMemBuffer() [2/2]

std::unique_ptr< MemoryBuffer > wpi::util::MemoryBuffer::GetMemBuffer ( std::span< const uint8_t > inputData,
std::string_view bufferName = "" )
static

Open the specified memory range as a MemoryBuffer.

◆ GetMemBufferCopy()

std::unique_ptr< MemoryBuffer > wpi::util::MemoryBuffer::GetMemBufferCopy ( std::span< const uint8_t > inputData,
std::string_view bufferName = "" )
static

Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.

◆ GetMemBufferRef()

MemoryBufferRef wpi::util::MemoryBuffer::GetMemBufferRef ( ) const

◆ GetOpenFile()

std::unique_ptr< MemoryBuffer > wpi::util::MemoryBuffer::GetOpenFile ( fs::file_t f,
std::string_view filename,
std::error_code & ec,
uint64_t fileSize )
static

Given an already-open file descriptor, read the file and return a MemoryBuffer.

◆ GetOpenFileSlice()

std::unique_ptr< MemoryBuffer > wpi::util::MemoryBuffer::GetOpenFileSlice ( fs::file_t f,
std::string_view filename,
std::error_code & ec,
uint64_t mapSize,
int64_t offset )
static

Given an already-open file descriptor, map some slice of it into a MemoryBuffer.

The slice is specified by an Offset and MapSize.

◆ Init()

void wpi::util::MemoryBuffer::Init ( const uint8_t * bufStart,
const uint8_t * bufEnd )
protected

◆ operator=()

MemoryBuffer & wpi::util::MemoryBuffer::operator= ( const MemoryBuffer & )
delete

◆ size()

size_t wpi::util::MemoryBuffer::size ( ) const
inline

The documentation for this class was generated from the following file: