A BufferView references a mutable range of memory. It consists of a pointer bytes and an integer numBytes. A BufferView does not own the memory it points to, and no heap memory is freed when the BufferView is destroyed.

BufferView is similar to ConstBufferView except that the memory referenced by BufferView is mutable (not const), so it's legal to modify its contents. BufferView is used as the sole argument to InPipe::read() and InStream::read().

BufferView is implicitly convertible to ConstBufferView and can be passed as an argument to any function that expects a ConstBufferView.

Header File

#include <ply-runtime/container/BufferView.h>

Also included from <ply-runtime/Base.h>.

Data Members

u8* bytes [code]

The first byte in the mutable memory range.

u32 numBytes [code]

The number of bytes in the mutable memory range.

Member Functions

BufferView() [code]

Constructs an empty BufferView.

BufferView(void* bytes, u32 numBytes) [code]

Constructs a BufferView from an explicit pointer and number of bytes.

template <u32 N>
BufferView(u8& bytes[]) [code]

FIXME: Make this show up Constructs a ConstBufferView from a string literal. (?)

static BufferView fromRange(u8* startByte, u8* endByte) [code]

Returns a BufferView referencing a mutable range of memory between two pointers. The number of bytes in the memory range is given by endByte - startByte, and endByte is considered a pointer to the first byte after the memory range.

operator const ConstBufferView&() const [code]

Conversion operator. Makes BufferView implicitly convertible to ConstBufferView.

u8& operator[](u32 ofs) const [code]

Subscript operator with runtime bounds checking.

void offsetHead(u32 ofs) [code]

Advances the start of the memory range by ofs bytes while keeping the end of the memory range unchanged.

void offsetBack(s32 ofs) [code]

Advances the end of the memory range by ofs bytes while keeping the start of the memory range unchanged.

BufferView subView(u32 start) const [code]
BufferView subView(u32 start, u32 numBytes) const [code]

Returns a new, smaller BufferView that references a subrange of this BufferView, with runtime bounds checking. start is the offset of the new BufferView relative to the start of this one, and numBytes is the number of bytes in the new BufferView. If numBytes is not specified, the subview continues to the end of the BufferView.

bool contains(const u8* curByte) const [code]

Returns true if curByte points to a byte inside the memory range.