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

An immutable linear range of bytes. More...

#include <Slice.h>

Collaboration diagram for xrpl::Slice:

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.
 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.
bool empty () const noexcept
 Return true if the byte range is empty.
std::uint8_t const * data () const noexcept
 Return a pointer to beginning of the storage.
std::uint8_t operator[] (std::size_t i) const noexcept
 Access raw bytes.
void removePrefix (std::size_t n)
 Shrinks the slice by moving its start forward by n characters.
void removeSuffix (std::size_t n)
 Shrinks the slice by moving its end backward by n characters.
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.
std::size_t size () const noexcept
 Returns the number of bytes in the storage.
std::size_t length () const noexcept
Sliceoperator+= (std::size_t n)
 Advance the buffer.
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 25 of file Slice.h.

Member Typedef Documentation

◆ value_type

Definition at line 32 of file Slice.h.

◆ const_iterator

Definition at line 33 of file Slice.h.

Constructor & Destructor Documentation

◆ Slice() [1/3]

xrpl::Slice::Slice ( )
defaultnoexcept

Default constructed Slice has length 0.

◆ Slice() [2/3]

xrpl::Slice::Slice ( Slice const & )
defaultnoexcept

◆ Slice() [3/3]

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

Create a slice pointing to existing memory.

Definition at line 43 of file Slice.h.

Member Function Documentation

◆ operator=()

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

◆ empty()

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

Return true if the byte range is empty.

Definition at line 50 of file Slice.h.

◆ size()

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

Returns the number of bytes in the storage.

This may be zero for an empty range.

Definition at line 61 of file Slice.h.

◆ length()

std::size_t xrpl::Slice::length ( ) const
nodiscardnoexcept

Definition at line 67 of file Slice.h.

◆ data()

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

◆ operator[]()

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

Access raw bytes.

Definition at line 85 of file Slice.h.

◆ operator+=()

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

Advance the buffer.

Definition at line 94 of file Slice.h.

◆ operator+()

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

Definition at line 104 of file Slice.h.

◆ removePrefix()

void xrpl::Slice::removePrefix ( std::size_t n)

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

Definition at line 113 of file Slice.h.

◆ removeSuffix()

void xrpl::Slice::removeSuffix ( std::size_t n)

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

Definition at line 121 of file Slice.h.

◆ begin()

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

Definition at line 127 of file Slice.h.

◆ cbegin()

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

Definition at line 133 of file Slice.h.

◆ end()

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

Definition at line 139 of file Slice.h.

◆ cend()

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

Definition at line 145 of file Slice.h.

◆ substr()

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

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 162 of file Slice.h.

Member Data Documentation

◆ data_

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

Definition at line 28 of file Slice.h.

◆ size_

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

Definition at line 29 of file Slice.h.