rippled
Public Types | Public Member Functions | Private Attributes | List of all members
ripple::Slice Class Reference

An immutable linear range of bytes. More...

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

Public Types

using value_type = std::uint8_t
 
using const_iterator = value_type const *
 

Public Member Functions

 Slice () noexcept=default
 Default constructed Slice has length 0. More...
 
 Slice (Slice const &) noexcept=default
 
Sliceoperator= (Slice const &) noexcept=default
 
 Slice (void const *data, std::size_t size) noexcept
 Create a slice pointing to existing memory. More...
 
bool empty () const noexcept
 Return true if the byte range is empty. More...
 
std::uint8_t const * data () const noexcept
 Return a pointer to beginning of the storage. More...
 
std::uint8_t operator[] (std::size_t i) const noexcept
 Access raw bytes. More...
 
void remove_prefix (std::size_t n)
 Shrinks the slice by moving its start forward by n characters. More...
 
void remove_suffix (std::size_t n)
 Shrinks the slice by moving its end backward by n characters. More...
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
Slice substr (std::size_t pos, std::size_t count=std::numeric_limits< std::size_t >::max()) const
 Return a "sub slice" of given length starting at the given position. More...
 
std::size_t size () const noexcept
 Returns the number of bytes in the storage. More...
 
std::size_t length () const noexcept
 
Sliceoperator+= (std::size_t n)
 Advance the buffer. More...
 
Slice operator+ (std::size_t n) const
 

Private Attributes

std::uint8_t const * data_ = nullptr
 
std::size_t size_ = 0
 

Detailed Description

An immutable linear range of bytes.

A fully constructed Slice is guaranteed to be in a valid state. A Slice is lightweight and copyable, it retains no ownership of the underlying memory.

Definition at line 44 of file Slice.h.

Member Typedef Documentation

◆ value_type

Definition at line 51 of file Slice.h.

◆ const_iterator

Definition at line 52 of file Slice.h.

Constructor & Destructor Documentation

◆ Slice() [1/3]

ripple::Slice::Slice ( )
defaultnoexcept

Default constructed Slice has length 0.

◆ Slice() [2/3]

ripple::Slice::Slice ( Slice const &  )
defaultnoexcept

◆ Slice() [3/3]

ripple::Slice::Slice ( void const *  data,
std::size_t  size 
)
noexcept

Create a slice pointing to existing memory.

Definition at line 62 of file Slice.h.

Member Function Documentation

◆ operator=()

Slice& ripple::Slice::operator= ( Slice const &  )
defaultnoexcept

◆ empty()

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

Return true if the byte range is empty.

Definition at line 69 of file Slice.h.

◆ size()

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

Returns the number of bytes in the storage.

This may be zero for an empty range.

Definition at line 80 of file Slice.h.

◆ length()

std::size_t ripple::Slice::length ( ) const
noexcept

Definition at line 86 of file Slice.h.

◆ data()

std::uint8_t const* ripple::Slice::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 97 of file Slice.h.

◆ operator[]()

std::uint8_t ripple::Slice::operator[] ( std::size_t  i) const
noexcept

Access raw bytes.

Definition at line 104 of file Slice.h.

◆ operator+=()

Slice& ripple::Slice::operator+= ( std::size_t  n)

Advance the buffer.

Definition at line 113 of file Slice.h.

◆ operator+()

Slice ripple::Slice::operator+ ( std::size_t  n) const

Definition at line 123 of file Slice.h.

◆ remove_prefix()

void ripple::Slice::remove_prefix ( std::size_t  n)

Shrinks the slice by moving its start forward by n characters.

Definition at line 132 of file Slice.h.

◆ remove_suffix()

void ripple::Slice::remove_suffix ( std::size_t  n)

Shrinks the slice by moving its end backward by n characters.

Definition at line 140 of file Slice.h.

◆ begin()

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

Definition at line 146 of file Slice.h.

◆ cbegin()

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

Definition at line 152 of file Slice.h.

◆ end()

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

Definition at line 158 of file Slice.h.

◆ cend()

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

Definition at line 164 of file Slice.h.

◆ substr()

Slice ripple::Slice::substr ( std::size_t  pos,
std::size_t  count = std::numeric_limits<std::size_t>::max() 
) const

Return a "sub slice" of given length starting at the given position.

Note that the subslice encompasses the range [pos, pos + rcount), where rcount is the smaller of count and size() - pos.

Parameters
posposition of the first character @count requested length
Returns
The requested subslice, if the request is valid.
Exceptions
std::out_of_rangeif pos > size()

Definition at line 181 of file Slice.h.

Member Data Documentation

◆ data_

std::uint8_t const* ripple::Slice::data_ = nullptr
private

Definition at line 47 of file Slice.h.

◆ size_

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

Definition at line 48 of file Slice.h.