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 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 15 of file Buffer.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 22 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 27 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 38 of file Buffer.h.

◆ Buffer() [4/6]

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

Copy-construct.

Definition at line 45 of file Buffer.h.

◆ Buffer() [5/6]

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

Move-construct.

The other buffer is reset.

Definition at line 64 of file Buffer.h.

◆ Buffer() [6/6]

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

Construct from a slice.

Definition at line 85 of file Buffer.h.

Member Function Documentation

◆ operator=() [1/3]

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

Copy assign.

Definition at line 51 of file Buffer.h.

◆ operator=() [2/3]

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

Move-assign.

The other buffer is reset.

Definition at line 73 of file Buffer.h.

◆ operator=() [3/3]

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

Assign from slice.

Definition at line 91 of file Buffer.h.

◆ size()

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

Returns the number of bytes in the buffer.

Definition at line 105 of file Buffer.h.

◆ empty()

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

Definition at line 111 of file Buffer.h.

◆ operator Slice()

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

Definition at line 116 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 129 of file Buffer.h.

◆ data() [2/2]

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

Definition at line 135 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 145 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 155 of file Buffer.h.

◆ operator()()

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

Definition at line 167 of file Buffer.h.

◆ begin()

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

Definition at line 173 of file Buffer.h.

◆ cbegin()

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

Definition at line 179 of file Buffer.h.

◆ end()

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

Definition at line 185 of file Buffer.h.

◆ cend()

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

Definition at line 191 of file Buffer.h.

Member Data Documentation

◆ p_

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

Definition at line 18 of file Buffer.h.

◆ size_

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

Definition at line 19 of file Buffer.h.