LibQuicR
quicr::DataStorage< Allocator > Class Template Reference

Shared, segmented byte storage with a flattened bidirectional iterator. More...

#include <data_storage.h>

Inheritance diagram for quicr::DataStorage< Allocator >:

Public Types

using iterator = Iterator< typename BufferType::iterator, typename SliceType::element_type::iterator >
 Mutable flattened byte iterator type. More...
 
using const_iterator = Iterator< typename BufferType::const_iterator, typename SliceType::element_type::const_iterator >
 Read-only flattened byte iterator type. More...
 

Public Member Functions

bool Empty () const noexcept
 
const SliceType & First () const noexcept
 
const SliceType & Last () const noexcept
 
const SliceType GetLast () const noexcept
 
void Push (std::span< const uint8_t > bytes)
 Copies bytes into a new owned slice at the back. More...
 
void Push (SliceType slice)
 Appends a shared slice without copying its bytes. More...
 
std::size_t size () const noexcept
 
std::size_t EraseFront (std::size_t len) noexcept
 Removes complete slices from the front whose cumulative size does not exceed len. More...
 
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 

Static Public Member Functions

static std::shared_ptr< DataStorage > Create () noexcept
 
static std::shared_ptr< DataStorage > Create (SliceType slice) noexcept
 

Protected Types

using SliceType = std::shared_ptr< std::vector< uint8_t, Allocator > >
 Shared ownership of one contiguous byte slice. More...
 
using BufferType = std::deque< SliceType >
 Sequence of shared slices. More...
 

Protected Member Functions

 DataStorage ()=default
 Constructs empty storage; use Create() from callers. More...
 
 DataStorage (SliceType slice)
 Constructs storage containing one shared slice. More...
 

Detailed Description

template<class Allocator = std::allocator<std::uint8_t>>
class quicr::DataStorage< Allocator >

Shared, segmented byte storage with a flattened bidirectional iterator.

Template Parameters
AllocatorAllocator used by each owned byte-vector slice.

The container and its iterators are not thread-safe. Slices are shared, so retained SliceType instances can outlive their membership in the storage.

Member Typedef Documentation

◆ BufferType

template<class Allocator = std::allocator<std::uint8_t>>
using quicr::DataStorage< Allocator >::BufferType = std::deque<SliceType>
protected

Sequence of shared slices.

◆ const_iterator

template<class Allocator = std::allocator<std::uint8_t>>
using quicr::DataStorage< Allocator >::const_iterator = Iterator<typename BufferType::const_iterator, typename SliceType::element_type::const_iterator>

Read-only flattened byte iterator type.

◆ iterator

template<class Allocator = std::allocator<std::uint8_t>>
using quicr::DataStorage< Allocator >::iterator = Iterator<typename BufferType::iterator, typename SliceType::element_type::iterator>

Mutable flattened byte iterator type.

◆ SliceType

template<class Allocator = std::allocator<std::uint8_t>>
using quicr::DataStorage< Allocator >::SliceType = std::shared_ptr<std::vector<uint8_t, Allocator> >
protected

Shared ownership of one contiguous byte slice.

Constructor & Destructor Documentation

◆ DataStorage() [1/2]

template<class Allocator = std::allocator<std::uint8_t>>
quicr::DataStorage< Allocator >::DataStorage ( )
protecteddefault

Constructs empty storage; use Create() from callers.

◆ DataStorage() [2/2]

template<class Allocator = std::allocator<std::uint8_t>>
quicr::DataStorage< Allocator >::DataStorage ( SliceType  slice)
inlineprotected

Constructs storage containing one shared slice.

Parameters
sliceSlice to retain.
Precondition
slice is non-null and nonempty before any flattened iteration or first/last access.

Member Function Documentation

◆ begin() [1/2]

template<class Allocator = std::allocator<std::uint8_t>>
const_iterator quicr::DataStorage< Allocator >::begin ( ) const
inlinenoexcept
Returns
Const iterator to the first byte, or end() when there are no slices.

◆ begin() [2/2]

template<class Allocator = std::allocator<std::uint8_t>>
iterator quicr::DataStorage< Allocator >::begin ( )
inlinenoexcept
Returns
Iterator to the first byte, or end() when there are no slices.

◆ cbegin()

template<class Allocator = std::allocator<std::uint8_t>>
const_iterator quicr::DataStorage< Allocator >::cbegin ( ) const
inlinenoexcept
Returns
Const iterator to the first byte, or cend() when there are no slices.

◆ cend()

template<class Allocator = std::allocator<std::uint8_t>>
const_iterator quicr::DataStorage< Allocator >::cend ( ) const
inlinenoexcept
Returns
Const end iterator.

◆ Create() [1/2]

template<class Allocator = std::allocator<std::uint8_t>>
static std::shared_ptr<DataStorage> quicr::DataStorage< Allocator >::Create ( )
inlinestaticnoexcept
Returns
Shared ownership of newly allocated empty storage, or terminates on allocation failure.

◆ Create() [2/2]

template<class Allocator = std::allocator<std::uint8_t>>
static std::shared_ptr<DataStorage> quicr::DataStorage< Allocator >::Create ( SliceType  slice)
inlinestaticnoexcept
Parameters
sliceInitial shared slice.
Returns
Shared ownership of newly allocated storage, or terminates on allocation failure.
Precondition
slice is non-null and nonempty before iteration or first/last access.

◆ Empty()

template<class Allocator = std::allocator<std::uint8_t>>
bool quicr::DataStorage< Allocator >::Empty ( ) const
inlinenoexcept
Returns
true if there are no slices; zero-length slices still make this false.

◆ end() [1/2]

template<class Allocator = std::allocator<std::uint8_t>>
const_iterator quicr::DataStorage< Allocator >::end ( ) const
inlinenoexcept
Returns
Const end iterator.

◆ end() [2/2]

template<class Allocator = std::allocator<std::uint8_t>>
iterator quicr::DataStorage< Allocator >::end ( )
inlinenoexcept
Returns
End iterator.

◆ EraseFront()

template<class Allocator = std::allocator<std::uint8_t>>
std::size_t quicr::DataStorage< Allocator >::EraseFront ( std::size_t  len)
inlinenoexcept

Removes complete slices from the front whose cumulative size does not exceed len.

Parameters
lenMaximum byte count considered for removal.
Returns
Remaining byte count when the next slice is only partially covered; zero when all requested bytes were consumed or a null slice is encountered. Slices are never partially erased.
Warning
Any storage iterator or view position at/after removed slices may be invalidated.

◆ First()

template<class Allocator = std::allocator<std::uint8_t>>
const SliceType& quicr::DataStorage< Allocator >::First ( ) const
inlinenoexcept
Returns
Intended to return the first shared slice.
Warning
The current definition dereferences the flattened byte iterator and is ill-formed if instantiated.

◆ GetLast()

template<class Allocator = std::allocator<std::uint8_t>>
const SliceType quicr::DataStorage< Allocator >::GetLast ( ) const
inlinenoexcept
Returns
Intended to return a shared-ownership copy of the last slice.
Warning
The current definition dereferences the flattened byte iterator and is ill-formed if instantiated.

◆ Last()

template<class Allocator = std::allocator<std::uint8_t>>
const SliceType& quicr::DataStorage< Allocator >::Last ( ) const
inlinenoexcept
Returns
Intended to return the last shared slice.
Warning
The current definition dereferences the flattened byte iterator and is ill-formed if instantiated.

◆ Push() [1/2]

template<class Allocator = std::allocator<std::uint8_t>>
void quicr::DataStorage< Allocator >::Push ( SliceType  slice)
inline

Appends a shared slice without copying its bytes.

Parameters
sliceSlice whose ownership is moved into the storage.
Precondition
slice is non-null and nonempty before flattened iteration.

◆ Push() [2/2]

template<class Allocator = std::allocator<std::uint8_t>>
void quicr::DataStorage< Allocator >::Push ( std::span< const uint8_t >  bytes)
inline

Copies bytes into a new owned slice at the back.

Parameters
bytesSource view, valid for the duration of the call.
Exceptions
Anyallocation exception.
Note
An empty span creates an empty slice, which flattened iteration does not support.

◆ size()

template<class Allocator = std::allocator<std::uint8_t>>
std::size_t quicr::DataStorage< Allocator >::size ( ) const
inlinenoexcept
Returns
Total byte count across all slices.
Precondition
Every slice is non-null.

The documentation for this class was generated from the following file: