rippled
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Attributes | List of all members
ripple::Buffer Class Reference

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

#include <Buffer.h>

Collaboration diagram for ripple::Buffer:
Collaboration graph
[legend]

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

Member Typedef Documentation

◆ const_iterator

Definition at line 42 of file Buffer.h.

Constructor & Destructor Documentation

◆ Buffer() [1/6]

ripple::Buffer::Buffer ( )
default

◆ Buffer() [2/6]

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

Create an uninitialized buffer with the given size.

Definition at line 47 of file Buffer.h.

◆ Buffer() [3/6]

ripple::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 58 of file Buffer.h.

◆ Buffer() [4/6]

ripple::Buffer::Buffer ( Buffer const &  other)

Copy-construct.

Definition at line 65 of file Buffer.h.

◆ Buffer() [5/6]

ripple::Buffer::Buffer ( Buffer &&  other)
noexcept

Move-construct.

The other buffer is reset.

Definition at line 84 of file Buffer.h.

◆ Buffer() [6/6]

ripple::Buffer::Buffer ( Slice  s)
explicit

Construct from a slice.

Definition at line 106 of file Buffer.h.

Member Function Documentation

◆ operator=() [1/3]

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

Copy assign.

Definition at line 71 of file Buffer.h.

◆ operator=() [2/3]

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

Move-assign.

The other buffer is reset.

Definition at line 94 of file Buffer.h.

◆ operator=() [3/3]

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

Assign from slice.

Definition at line 112 of file Buffer.h.

◆ size()

std::size_t ripple::Buffer::size ( ) const
noexcept

Returns the number of bytes in the buffer.

Definition at line 127 of file Buffer.h.

◆ empty()

bool ripple::Buffer::empty ( ) const
noexcept

Definition at line 133 of file Buffer.h.

◆ operator Slice()

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

Definition at line 138 of file Buffer.h.

◆ data() [1/2]

std::uint8_t const * ripple::Buffer::data ( ) const
noexcept

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

◆ data() [2/2]

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

Definition at line 157 of file Buffer.h.

◆ clear()

void ripple::Buffer::clear ( )
noexcept

Reset the buffer.

All memory is deallocated. The resulting size is 0.

Definition at line 167 of file Buffer.h.

◆ alloc()

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

Reallocate the storage.

Existing data, if any, is discarded.

Definition at line 177 of file Buffer.h.

◆ operator()()

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

Definition at line 189 of file Buffer.h.

◆ begin()

const_iterator ripple::Buffer::begin ( ) const
noexcept

Definition at line 195 of file Buffer.h.

◆ cbegin()

const_iterator ripple::Buffer::cbegin ( ) const
noexcept

Definition at line 201 of file Buffer.h.

◆ end()

const_iterator ripple::Buffer::end ( ) const
noexcept

Definition at line 207 of file Buffer.h.

◆ cend()

const_iterator ripple::Buffer::cend ( ) const
noexcept

Definition at line 213 of file Buffer.h.

Member Data Documentation

◆ p_

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

Definition at line 38 of file Buffer.h.

◆ size_

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

Definition at line 39 of file Buffer.h.