Represents a mutable view of a contiguous block of bytes.
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 | |
| Buf & | operator= (Buf &&other) noexcept |
| Move assignment operator. | |
| Buf & | operator= (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. | |
| Deallocator * | deallocator () 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) |
|
inlineexplicitconstexpr |
Constructs an owned Buf from a raw buffer, offset, size, and deallocator.
Allocates a new owned Buf of the specified allocation size, shifted to offset, with the specified size.
Asserts if allocation fails.
Allocates a new owned Buf of the specified size.
Asserts if allocation fails.
|
inline |
Returns a pointer to the deallocator if this buffer owns the underlying memory allocation, or nullptr if the buffer is unowned.
Reclaims up to prefix_count bytes at the beginning and suffix_count bytes at the end of the buffer.