Spicy
Public Member Functions | Static Public Member Functions | List of all members
hilti::rt::Stream Class Reference

#include <stream.h>

Public Member Functions

 Stream ()
 
 Stream (std::vector< Byte > d)
 
 Stream (const Bytes &d)
 
 Stream (const char *d)
 
 Stream (const char *d, const Size &n)
 
 Stream (const stream::View &d)
 
template<int N>
 Stream (std::vector< std::array< Byte, N >> d)
 
 Stream (const Stream &other)
 
 Stream (Stream &&other) noexcept
 
Streamoperator= (Stream &&other) noexcept
 
Streamoperator= (const Stream &other)
 
 ~Stream ()
 
Size size () const
 
bool isEmpty () const
 
void append (const Bytes &data)
 
void append (Bytes &&data)
 
void append (std::unique_ptr< const Byte *> data)
 
void append (const char *data, size_t len)
 
void trim (const SafeConstIterator &i)
 
void freeze ()
 
void unfreeze ()
 
bool isFrozen () const
 
SafeConstIterator begin () const
 
SafeConstIterator end () const
 
UnsafeConstIterator unsafeBegin () const
 
UnsafeConstIterator unsafeEnd () const
 
SafeConstIterator at (const Offset &offset) const
 
Offset endOffset () const
 
View view (bool expanding=true) const
 
bool operator== (const Bytes &other) const
 
bool operator== (const Stream &other) const
 
bool operator== (const stream::View &other) const
 
bool operator!= (const Bytes &other) const
 
bool operator!= (const Stream &other) const
 
bool operator!= (const stream::View &other) const
 
int numberOfChunks () const
 
void debugPrint (std::ostream &out) const
 

Static Public Member Functions

static void debugPrint (std::ostream &out, const stream::detail::Chain *chain)
 

Detailed Description

Container for raw binary data that's going to be processed in streaming mode. The underlying data storage is optimized for cheap append operations even with large instances, but does not allow for any modifications to existing data. It also ensures that iterators bound to an instance can reliably detect if the instance gets deleted.

Internally, almost all functionality is delegated to a Chain instance, which resides on the heap.

Constructor & Destructor Documentation

◆ Stream() [1/9]

hilti::rt::Stream::Stream ( )
inline

Constructor.

◆ Stream() [2/9]

hilti::rt::Stream::Stream ( std::vector< Byte >  d)
inlineexplicit

Creates an instance from a vector of Bytes.

Parameters
dvector to create the stream from

◆ Stream() [3/9]

Stream::Stream ( const Bytes d)
explicit

Creates an instance from a bytes instance.

Parameters
dBytes instance to the create the stream from

◆ Stream() [4/9]

hilti::rt::Stream::Stream ( const char *  d)
inlineexplicit

Creates an instance for C-style ASCII string, not including the final null byte. The data will be copied.

Parameters
dnull-terminated string to create the stream from

◆ Stream() [5/9]

Stream::Stream ( const char *  d,
const Size &  n 
)

Creates an instance from an existing memory block. The data will be copied if set, otherwise a gap will be recorded.

◆ Stream() [6/9]

hilti::rt::Stream::Stream ( const stream::View d)
inline

Creates an instance from an existing stream view.

Parameters
dView to create the stream from

◆ Stream() [7/9]

template<int N>
hilti::rt::Stream::Stream ( std::vector< std::array< Byte, N >>  d)
inline

Creates an instance from a series of static-sized blocks.

Parameters
da vector of N-sized arrays to create the stream from

◆ Stream() [8/9]

hilti::rt::Stream::Stream ( const Stream other)
inline

Constructs a stream from another stream instance.

Parameters
otherinstance to create this stream from

◆ Stream() [9/9]

hilti::rt::Stream::Stream ( Stream &&  other)
inlinenoexcept

Constructs a stream from another stream instance.

Parameters
otherinstance to create this stream from

◆ ~Stream()

hilti::rt::Stream::~Stream ( )
inline

Destructor.

Member Function Documentation

◆ append() [1/4]

void Stream::append ( const Bytes data)

Appends the content of a bytes instance. This function does not invalidate iterators.

Parameters
dataBytes to append

◆ append() [2/4]

void Stream::append ( Bytes &&  data)

Appends the content of a bytes instance. This function does not invalidate iterators.

Parameters
dataBytes to append

◆ append() [3/4]

void hilti::rt::Stream::append ( std::unique_ptr< const Byte *>  data)

Appends the content of a raw memory area, taking ownership. This function does not invalidate iterators.

Parameters
datapointer to Bytes to append

◆ append() [4/4]

void Stream::append ( const char *  data,
size_t  len 
)

Appends the content of a raw memory area, copying the data. This function does not invalidate iterators.

Parameters
datapointer to the data to append. If this is nullptr and gap will be appended instead.
lenlength of the data to append

◆ at()

SafeConstIterator hilti::rt::Stream::at ( const Offset &  offset) const
inline

Returns an iterator representing a specific offset.

Parameters
offsetoffset to use for the created iterator

◆ begin()

SafeConstIterator hilti::rt::Stream::begin ( ) const
inline

Returns a safe iterator representing the first byte of the instance.

◆ debugPrint() [1/2]

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

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

◆ debugPrint() [2/2]

void Stream::debugPrint ( std::ostream &  out,
const stream::detail::Chain chain 
)
static

Prints out a debug rendering to a stream's internal representation.

◆ end()

SafeConstIterator hilti::rt::Stream::end ( ) const
inline

Returns a safe iterator representing the end of the instance.

◆ endOffset()

Offset hilti::rt::Stream::endOffset ( ) const
inline

Returns the offset of the position one after the stream's last byte.

◆ freeze()

void hilti::rt::Stream::freeze ( )
inline

Freezes the instance. When frozen, no further data can be appended.

◆ isEmpty()

bool hilti::rt::Stream::isEmpty ( ) const
inline

Returns true if the instance's size is zero.

◆ isFrozen()

bool hilti::rt::Stream::isFrozen ( ) const
inline

Returns true if the instance is currently frozen.

◆ numberOfChunks()

int hilti::rt::Stream::numberOfChunks ( ) const
inline

For internal debugging: Returns the number of dynamic chunks allocated.

◆ operator=() [1/2]

Stream& hilti::rt::Stream::operator= ( Stream &&  other)
inlinenoexcept

Assigns from another stream instance. This invalidates all existing iterators.

Parameters
otherthe stream instance to assign from

◆ operator=() [2/2]

Stream& hilti::rt::Stream::operator= ( const Stream other)
inline

Assigns from another stream instance. This invalidates all existing iterators.

Parameters
otherthe stream instance to assign from

◆ size()

Size hilti::rt::Stream::size ( ) const
inline

Returns the number of stream characters the instance contains.

◆ trim()

void hilti::rt::Stream::trim ( const SafeConstIterator i)
inline

Cuts off the beginning of the data up to, but excluding, a given iterator. All existing iterators pointing beyond that point will remain valid and keep their offsets the same. Trimming is permitted even on frozen instances.

Parameters
iiterator one past the last data element to trim

◆ unfreeze()

void hilti::rt::Stream::unfreeze ( )
inline

Unfreezes the instance so that more data can be appended again.

◆ unsafeBegin()

UnsafeConstIterator hilti::rt::Stream::unsafeBegin ( ) const
inline

Returns an unsafe iterator representing the first byte of the instance.

◆ unsafeEnd()

UnsafeConstIterator hilti::rt::Stream::unsafeEnd ( ) const
inline

Returns an unsafe iterator representing the end of the instance.

◆ view()

View hilti::rt::Stream::view ( bool  expanding = true) const
inline

Returns a view representing the entire instance.

Parameters
expandingif true, the returned view will automatically grow along with the stream object if more data gets added.

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