C/C++ API Reference
Loading...
Searching...
No Matches
pw::Buf Class Reference

Overview

Represents a mutable view of a contiguous block of bytes.

Public Types

using value_type = std::byte
 
using size_type = size_t
 
using difference_type = ptrdiff_t
 
using pointer = std::byte *
 
using reference = std::byte &
 
using const_pointer = const std::byte *
 
using const_reference = const std::byte &
 

Public Member Functions

constexpr Buf ()=default
 Constructs an empty Buf.
 
constexpr Buf (Buf &&other) noexcept
 Move constructor.
 
 Buf (UniquePtr< std::byte[]> &&buffer)
 Constructs an owned Buf from a UniquePtr.
 
 Buf (UniquePtr< std::byte[]> &&buffer, size_t offset)
 
 Buf (UniquePtr< std::byte[]> &&buffer, size_t offset, size_t size)
 Constructs an owned Buf from a UniquePtr, offset, and size.
 
constexpr Buf (std::byte *allocation, size_t size, Deallocator &deallocator)
 Constructs an owned Buf from a raw buffer, size, and deallocator.
 
constexpr Buf (std::byte *allocation, size_t offset, size_t size, Deallocator &deallocator)
 
 Buf (const Buf &)=delete
 
Bufoperator= (Buf &&other) noexcept
 Move assignment operator.
 
Bufoperator= (const Buf &)=delete
 
 operator ConstBuf & () &
 Implicit conversion operators to ConstBuf reference types.
 
 operator const ConstBuf & () const &
 
 operator ConstBuf && () &&
 
 operator const ConstBuf && () const &&
 
const_reference operator[] (size_t index) const
 Accesses the byte at the specified index as read-only.
 
reference operator[] (size_t index)
 Accesses the byte at the specified index as mutable.
 
const_pointer data () const
 Returns a pointer to the read-only data.
 
pointer data ()
 Returns a pointer to the mutable data.
 
size_t size () const
 Returns the size of the buffer.
 
bool empty () const
 Returns true if the buffer is empty.
 
Deallocatordeallocator () const
 
const_iterator begin () const
 Returns a read-only iterator pointing to the beginning of the data.
 
const_iterator end () const
 Returns a read-only iterator pointing past the end of the data.
 
const_iterator cbegin () const
 Returns a read-only iterator pointing to the beginning of the data.
 
const_iterator cend () const
 Returns a read-only iterator pointing past the end of the data.
 
iterator begin ()
 Returns a mutable iterator pointing to the beginning of the data.
 
iterator end ()
 Returns a mutable iterator pointing past the end of the data.
 
void reset ()
 Frees the owned memory, leaving the buffer empty.
 

Static Public Member Functions

static Buf Unowned (ByteSpan span, size_t offset, size_t size)
 Creates an unowned Buf from a ByteSpan, offset, and size.
 
static Buf Unowned (ByteSpan span, size_t offset=0)
 
static Buf Unowned (std::byte *allocation, size_t offset, size_t size)
 Creates an unowned Buf from a pointer, offset, and size.
 
static Buf Unowned (std::byte *allocation, size_t size)
 Creates an unowned Buf from a pointer and size.
 
static Buf Allocate (Allocator &allocator, size_t size)
 
static Buf Allocate (Allocator &allocator, size_t offset, size_t size)
 
static Buf TryAllocate (Allocator &allocator, size_t size)
 
static Buf TryAllocate (Allocator &allocator, size_t offset, size_t size)
 

Friends

class ConstBuf
 
class multibuf::v2::internal::GenericMultiBuf
 
Buf Slice (Buf &&buf, size_t offset, size_t length)
 Slices a mutable Buf by shifting its start address and setting its size.
 
Buf Reclaim (Buf &&buf, size_t prefix_count, size_t suffix_count)
 

Constructor & Destructor Documentation

◆ Buf()

constexpr pw::Buf::Buf ( std::byte *  allocation,
size_t  offset,
size_t  size,
Deallocator deallocator 
)
inlineexplicitconstexpr

Constructs an owned Buf from a raw buffer, offset, size, and deallocator.

Member Function Documentation

◆ Allocate() [1/2]

static Buf pw::Buf::Allocate ( Allocator allocator,
size_t  offset,
size_t  size 
)
static

Allocates a new owned Buf of the specified allocation size, shifted to offset, with the specified size.

Asserts if allocation fails.

◆ Allocate() [2/2]

static Buf pw::Buf::Allocate ( Allocator allocator,
size_t  size 
)
inlinestatic

Allocates a new owned Buf of the specified size.

Asserts if allocation fails.

◆ deallocator()

Deallocator * pw::Buf::deallocator ( ) const
inline

Returns a pointer to the deallocator if this buffer owns the underlying memory allocation, or nullptr if the buffer is unowned.

◆ TryAllocate() [1/2]

static Buf pw::Buf::TryAllocate ( Allocator allocator,
size_t  offset,
size_t  size 
)
static

Allocates a new owned Buf of the specified allocation size, shifted to offset, with the specified size.

Returns an empty Buf if allocation fails.

◆ TryAllocate() [2/2]

static Buf pw::Buf::TryAllocate ( Allocator allocator,
size_t  size 
)
inlinestatic

Allocates a new owned Buf of the specified size.

Returns an empty Buf if allocation fails.

Friends And Related Function Documentation

◆ Reclaim

Buf Reclaim ( Buf &&  buf,
size_t  prefix_count,
size_t  suffix_count 
)
friend

Reclaims up to prefix_count bytes at the beginning and suffix_count bytes at the end of the buffer.


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