xrpld
Loading...
Searching...
No Matches
xrpl::Buffer Class Reference

Like std::vector<char> but better. More...

#include <Buffer.h>

Collaboration diagram for xrpl::Buffer:

Public Types

using const_iterator = std::uint8_t const*

Public Member Functions

 Buffer ()=default
 Buffer (std::size_t size)
 Create an uninitialized buffer with the given size.
 Buffer (void const *data, std::size_t size)
 Create a buffer as a copy of existing memory.
 Buffer (Buffer const &other)
 Copy-construct.
Bufferoperator= (Buffer const &other)
 Copy assign.
 Buffer (Buffer &&other) noexcept
 Move-construct.
Bufferoperator= (Buffer &&other) noexcept
 Move-assign.
 Buffer (Slice s)
 Construct from a slice.
Bufferoperator= (Slice s)
 Assign from slice.
std::size_t size () const noexcept
 Returns the number of bytes in the buffer.
bool empty () const noexcept
 operator Slice () const noexcept
void fill (std::uint8_t value) noexcept
 Set every byte in the buffer to the given value.
void clear () noexcept
 Reset the buffer.
std::uint8_talloc (std::size_t n)
 Reallocate the storage.
void * operator() (std::size_t n)
const_iterator begin () const noexcept
const_iterator cbegin () const noexcept
const_iterator end () const noexcept
const_iterator cend () const noexcept
std::uint8_t const * data () const noexcept
 Return a pointer to beginning of the storage.
std::uint8_tdata () noexcept

Private Attributes

std::unique_ptr< std::uint8_t[]> p_
std::size_t size_ = 0

Detailed Description

Like std::vector<char> but better.

Meets the requirements of BufferFactory.

Definition at line 18 of file Buffer.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 25 of file Buffer.h.

Constructor & Destructor Documentation

◆ Buffer() [1/6]

xrpl::Buffer::Buffer ( )
default

◆ Buffer() [2/6]

xrpl::Buffer::Buffer ( std::size_t size)
explicit

Create an uninitialized buffer with the given size.

Definition at line 32 of file Buffer.h.

◆ Buffer() [3/6]

xrpl::Buffer::Buffer ( void const * data,
std::size_t size )

Create a buffer as a copy of existing memory.

Parameters
dataa pointer to the existing memory. If size is non-zero, it must not be null.
sizesize of the existing memory block.

Definition at line 44 of file Buffer.h.

◆ Buffer() [4/6]

xrpl::Buffer::Buffer ( Buffer const & other)

Copy-construct.

Definition at line 53 of file Buffer.h.

◆ Buffer() [5/6]

xrpl::Buffer::Buffer ( Buffer && other)
noexcept

Move-construct.

The other buffer is reset.

Definition at line 75 of file Buffer.h.

◆ Buffer() [6/6]

xrpl::Buffer::Buffer ( Slice s)
explicit

Construct from a slice.

Definition at line 99 of file Buffer.h.

Member Function Documentation

◆ operator=() [1/3]

Buffer & xrpl::Buffer::operator= ( Buffer const & other)

Copy assign.

Definition at line 61 of file Buffer.h.

◆ operator=() [2/3]

Buffer & xrpl::Buffer::operator= ( Buffer && other)
noexcept

Move-assign.

The other buffer is reset.

Definition at line 85 of file Buffer.h.

◆ operator=() [3/3]

Buffer & xrpl::Buffer::operator= ( Slice s)

Assign from slice.

Definition at line 107 of file Buffer.h.

◆ size()

std::size_t xrpl::Buffer::size ( ) const
nodiscardnoexcept

Returns the number of bytes in the buffer.

Definition at line 123 of file Buffer.h.

◆ empty()

bool xrpl::Buffer::empty ( ) const
nodiscardnoexcept

Definition at line 129 of file Buffer.h.

◆ operator Slice()

xrpl::Buffer::operator Slice ( ) const
noexcept

Definition at line 134 of file Buffer.h.

◆ data() [1/2]

std::uint8_t const * xrpl::Buffer::data ( ) const
nodiscardnoexcept

Return a pointer to beginning of the storage.

Note
The return type is guaranteed to be a pointer to a single byte, to facilitate pointer arithmetic.

Definition at line 148 of file Buffer.h.

◆ data() [2/2]

std::uint8_t * xrpl::Buffer::data ( )
noexcept

Definition at line 154 of file Buffer.h.

◆ fill()

void xrpl::Buffer::fill ( std::uint8_t value)
noexcept

Set every byte in the buffer to the given value.

The size is unchanged, and this is a no-op on an empty buffer.

Parameters
valuethe byte to write to every position.

Definition at line 168 of file Buffer.h.

◆ clear()

void xrpl::Buffer::clear ( )
noexcept

Reset the buffer.

All memory is deallocated. The resulting size is 0.

Definition at line 178 of file Buffer.h.

◆ alloc()

std::uint8_t * xrpl::Buffer::alloc ( std::size_t n)

Reallocate the storage.

Existing data, if any, is discarded.

Definition at line 189 of file Buffer.h.

◆ operator()()

void * xrpl::Buffer::operator() ( std::size_t n)

Definition at line 201 of file Buffer.h.

◆ begin()

const_iterator xrpl::Buffer::begin ( ) const
nodiscardnoexcept

Definition at line 207 of file Buffer.h.

◆ cbegin()

const_iterator xrpl::Buffer::cbegin ( ) const
nodiscardnoexcept

Definition at line 213 of file Buffer.h.

◆ end()

const_iterator xrpl::Buffer::end ( ) const
nodiscardnoexcept

Definition at line 219 of file Buffer.h.

◆ cend()

const_iterator xrpl::Buffer::cend ( ) const
nodiscardnoexcept

Definition at line 225 of file Buffer.h.

Member Data Documentation

◆ p_

std::unique_ptr<std::uint8_t[]> xrpl::Buffer::p_
private

Definition at line 21 of file Buffer.h.

◆ size_

std::size_t xrpl::Buffer::size_ = 0
private

Definition at line 22 of file Buffer.h.