Spicy
Classes | Public Types | Public Member Functions | List of all members
hilti::rt::stream::View Class Reference

#include <stream.h>

Classes

struct  Block
 

Public Types

using Byte = stream::Byte
 
using Chain = stream::detail::Chain
 
using ChainPtr = stream::detail::ChainPtr
 
using Chunk = stream::detail::Chunk
 
using Offset = stream::Offset
 
using Size = stream::Size
 
using UnsafeConstIterator = stream::detail::UnsafeConstIterator
 

Public Member Functions

 View ()=default
 
virtual ~View ()
 
 View (SafeConstIterator begin, SafeConstIterator end)
 
 View (SafeConstIterator begin)
 
Offset offset () const
 
Size size () const
 
bool isEmpty () const
 
bool isFrozen () const
 
bool isOpenEnded () const
 
SafeConstIterator find (Byte b) const
 
SafeConstIterator find (Byte b, const SafeConstIterator &n) const
 
UnsafeConstIterator find (Byte b, UnsafeConstIterator n) const
 
std::tuple< bool, SafeConstIteratorfind (const View &v) const
 
std::tuple< bool, SafeConstIteratorfind (const View &v, const SafeConstIterator &n) const
 
std::tuple< bool, UnsafeConstIteratorfind (const View &v, UnsafeConstIterator n) const
 
std::tuple< bool, SafeConstIteratorfind (const Bytes &v, Direction d=Direction::Forward) const
 
std::tuple< bool, SafeConstIteratorfind (const Bytes &v, const SafeConstIterator &n, Direction d=Direction::Forward) const
 
std::tuple< bool, UnsafeConstIteratorfind (const Bytes &v, UnsafeConstIterator n, Direction d=Direction::Forward) const
 
View advance (SafeConstIterator i) const
 
View advance (integer::safe< uint64_t > i) const
 
View sub (SafeConstIterator from, SafeConstIterator to) const
 
View sub (SafeConstIterator to) const
 
View sub (Offset from, Offset to) const
 
View sub (Offset to) const
 
SafeConstIterator at (Offset offset) const
 
View trim (const SafeConstIterator &nbegin) const
 
View limit (Offset incr) const
 
template<int N>
View extract (Byte(&dst)[N]) const
 
void copyRaw (Byte *dst) const
 
Bytes data () const
 
detail::UnsafeConstIterator unsafeBegin () const
 
detail::UnsafeConstIterator unsafeEnd () const
 
const SafeConstIteratorbegin () const
 
SafeConstIterator end () const
 
std::optional< BlockfirstBlock () const
 
std::optional< BlocknextBlock (std::optional< Block > current) const
 
bool startsWith (const Bytes &b) const
 
bool operator== (const Bytes &other) const
 
bool operator== (const Stream &other) const
 
bool operator== (const View &other) const
 
bool operator!= (const Bytes &other) const
 
bool operator!= (const Stream &other) const
 
bool operator!= (const View &other) const
 
void debugPrint (std::ostream &out) const
 

Detailed Description

A subrange of a stream instance. The view is maintained through two safe iterators; no data is copied. That makes the view cheap to create and pass around. Because of the use of safe containers, it'll also be caught if the underlying stream instances goes away, or if accesses outside of currendtly valid range occur.

Constructor & Destructor Documentation

◆ View() [1/3]

hilti::rt::stream::View::View ( )
default

Constructor.

◆ ~View()

stream::View::~View ( )
virtualdefault

Destructor. Virtual to force creation of vtable for consistent RTTI.

◆ View() [2/3]

hilti::rt::stream::View::View ( SafeConstIterator  begin,
SafeConstIterator  end 
)
inlineexplicit

Constructor for static view bracketed through two iterators.

◆ View() [3/3]

hilti::rt::stream::View::View ( SafeConstIterator  begin)
inlineexplicit

Constructor for an expanding view that will always reflect a range up to the curent end of the underlying stream object, including when that expands.

Member Function Documentation

◆ advance() [1/2]

View hilti::rt::stream::View::advance ( SafeConstIterator  i) const
inline

Advances the view's starting position to a new place.

Parameters
ithe new position, which must be inside the current view
Returns
the modified view

◆ advance() [2/2]

View hilti::rt::stream::View::advance ( integer::safe< uint64_t >  i) const
inline

Advances the view's starting position by a given number of stream.

Parameters
ithe number of stream to advance.

◆ at()

SafeConstIterator hilti::rt::stream::View::at ( Offset  offset) const
inline

Returns an iterator representing an offset inside the view's data

◆ begin()

const SafeConstIterator& hilti::rt::stream::View::begin ( ) const
inline

Returns an safe iterator pointint to the beginning of the view.

◆ copyRaw()

void View::copyRaw ( Byte *  dst) const

Copies the view into raw memory.

Parameters
dstdestination to write to, which must have at least size() stream available().

◆ data()

Bytes stream::View::data ( ) const

Returns a copy of the data the view refers to.

◆ debugPrint()

void View::debugPrint ( std::ostream &  out) const

Prints out a debug rendering to the view's internal representation.

◆ end()

SafeConstIterator hilti::rt::stream::View::end ( ) const
inline

Returns a safe iterator representing the end of the instance.

◆ extract()

template<int N>
View hilti::rt::stream::View::extract ( Byte(&)  dst[N]) const
inline

Extracts a fixed number of stream from the view.

Template Parameters
Nnumber of stream to extract
Parameters
dsttarget array to write stream data into
Returns
new view that has it's starting position advanced by N

◆ find() [1/9]

SafeConstIterator hilti::rt::stream::View::find ( Byte  b) const
inline

Returns the position of the first occurrence of a byte inside the view. Will return end() if not found.

Parameters
bbyte to search

◆ find() [2/9]

SafeConstIterator hilti::rt::stream::View::find ( Byte  b,
const SafeConstIterator n 
) const
inline

Returns the position of the first occurrence of a byte inside the view. Will return end() if not found.

Parameters
bbyte to search
nstarting point, which must be inside the view

◆ find() [3/9]

UnsafeConstIterator View::find ( Byte  b,
UnsafeConstIterator  n 
) const

Returns the position of the first occurrence of a byte inside the view. Will return unsafeEnd() if not found.

Parameters
bbyte to search
nstarting point, which must be inside the view

◆ find() [4/9]

std::tuple<bool, SafeConstIterator> hilti::rt::stream::View::find ( const View v) const
inline

Searches for the first occurrence of another view's data.

Parameters
vdata to search for
Returns
tuple where the 1st element is a boolean indicating whether v has been found; if yes, the 2nd element points to the 1st occurrence; if no, the 2nd element points to the first byte so that no earlier position has even a partial match of v.

◆ find() [5/9]

std::tuple<bool, SafeConstIterator> hilti::rt::stream::View::find ( const View v,
const SafeConstIterator n 
) const
inline

Searches for the first occurrence of another view's data.

Parameters
vdata to search for
nstarting point, which must be inside this view
Returns
tuple where the 1st element is a boolean indicating whether v has been found; if yes, the 2nd element points to the 1st occurrence; if no, the 2nd element points to the first byte so that no earlier position has even a partial match of v.

◆ find() [6/9]

std::tuple< bool, UnsafeConstIterator > View::find ( const View v,
UnsafeConstIterator  n 
) const

Searches for the first occurrence of another view's data.

Parameters
vdata to search for
nstarting point, which must be inside this view
Returns
tuple where the 1st element is a boolean indicating whether v has been found; if yes, the 2nd element points to the 1st occurrence; if no, the 2nd element points to the first byte so that no earlier position has even a partial match of v.

◆ find() [7/9]

std::tuple<bool, SafeConstIterator> hilti::rt::stream::View::find ( const Bytes v,
Direction  d = Direction::Forward 
) const
inline

Searches for the first occurrence of data, either forward or backward.

Parameters
vdata to search for
ddirection to search: forward searches from the beginning, backward from the end of the view
Returns
tuple where the 1st element is a boolean indicating whether v has been found; if yes, the 2nd element points to the 1st byte; if no, then with forward searching, the 2nd element points to the first byte so that no earlier position has even a partial match of v

◆ find() [8/9]

std::tuple<bool, SafeConstIterator> hilti::rt::stream::View::find ( const Bytes v,
const SafeConstIterator n,
Direction  d = Direction::Forward 
) const
inline

Searches for the first occurrence of data, either forward or backward.

Parameters
vdata to search for
nstarting point, which must be inside this view
ddirection to search from starting point
Returns
tuple where the 1st element is a boolean indicating whether v has been found; if yes, the 2nd element points to the 1st byte; if no, then with forward searching, the 2nd element points to the first byte so that no earlier position has even a partial match of v

◆ find() [9/9]

std::tuple<bool, UnsafeConstIterator> hilti::rt::stream::View::find ( const Bytes v,
UnsafeConstIterator  n,
Direction  d = Direction::Forward 
) const
inline

Searches for the first occurrence of data, either forward or backward.

Parameters
vdata to search for
nstarting point, which must be inside this view
ddirection to search from starting point
Returns
tuple where the 1st element is a boolean indicating whether v has been found; if yes, the 2nd element points to the 1st byte; if no, then with forward searching, the 2nd element points to the first byte so that no earlier position has even a partial match of v

◆ firstBlock()

std::optional< View::Block > View::firstBlock ( ) const

Initialization method for block-wise iteration over raw data.

◆ isEmpty()

bool hilti::rt::stream::View::isEmpty ( ) const
inline

Returns true if the view's size is zero.

◆ isFrozen()

bool hilti::rt::stream::View::isFrozen ( ) const
inline

Returns true if the instance is currently frozen.

◆ isOpenEnded()

bool hilti::rt::stream::View::isOpenEnded ( ) const
inline

Returns true if the view was constructed without a fixed end offset, meaning it will expand as more data gets addedd to the underlying stream.

◆ limit()

View hilti::rt::stream::View::limit ( Offset  incr) const
inline

Returns a new view that keeps the current start but cuts off the end at a specified offset from that beginning. The returned view will not be able to expand any further.

◆ nextBlock()

std::optional< View::Block > View::nextBlock ( std::optional< Block current) const

Iterates to next block during block-wise iteration over raw data.

◆ offset()

Offset hilti::rt::stream::View::offset ( ) const
inline

Returns the offset of the view's starting location within the associated stream instance.

◆ size()

Size View::size ( ) const

Returns the number of actual bytes available inside the view. If the view's end position is beyong the current end offset of the underlying stream, those missing bytes are not counted.

◆ startsWith()

bool View::startsWith ( const Bytes b) const

Returns true if the view's data begins with a given, other stream instance.

◆ sub() [1/4]

View hilti::rt::stream::View::sub ( SafeConstIterator  from,
SafeConstIterator  to 
) const
inline

Extracts a subrange of bytes from the view, returned as a new view.

Parameters
fromiterator pointing to start of subrange
toiterator pointing to just beyond subrange

◆ sub() [2/4]

View hilti::rt::stream::View::sub ( SafeConstIterator  to) const
inline

Extracts subrange of bytes from the beginning of the view, returned as a new view.

Parameters
toiterator pointing to just beyond subrange

◆ sub() [3/4]

View hilti::rt::stream::View::sub ( Offset  from,
Offset  to 
) const
inline

Extracts subrange of bytes from the view, returned as a new view.

Parameters
fromoffset of start of subrange, relative to beginning of view
tooffset of one beyond end of subrange, relative to beginning of view

◆ sub() [4/4]

View hilti::rt::stream::View::sub ( Offset  to) const
inline

Extracts subrange of stream from the beginning of the view, returned as a new view.

Parameters
toof one beyond end of subrange, relative to beginning of view

◆ trim()

View hilti::rt::stream::View::trim ( const SafeConstIterator nbegin) const
inline

Returns a new view moves the beginning to a subsequent iterator while not changing the end. In particular, this maintains a view capability to expand to an underlying data instance's growth.

◆ unsafeBegin()

detail::UnsafeConstIterator hilti::rt::stream::View::unsafeBegin ( ) const
inline

Returns an unsafe iterator pointing to the beginning of the view.

◆ unsafeEnd()

detail::UnsafeConstIterator hilti::rt::stream::View::unsafeEnd ( ) const
inline

Returns an unsafe iterator representing the end of the instance.


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