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 (Bytes d)
 
 Stream (const char *d, Size n)
 
 Stream (const char *d, Size n, stream::NonOwning)
 
 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 append (const char *data, size_t len, stream::NonOwning)
 
void trim (const SafeConstIterator &i)
 
void freeze ()
 
void unfreeze ()
 
bool isFrozen () const
 
void reset ()
 
void makeOwning ()
 
SafeConstIterator begin () const
 
SafeConstIterator cbegin () const
 
SafeConstIterator end () const
 
SafeConstIterator cend () 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
 
const auto & statistics () 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/8]

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

Constructor.

◆ Stream() [2/8]

Stream::Stream ( Bytes  d)
explicit

Creates an instance from a bytes instance.

Parameters
dBytes instance to the create the stream from

◆ Stream() [3/8]

hilti::rt::Stream::Stream ( const char *  d,
Size  n 
)
inline

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

◆ Stream() [4/8]

hilti::rt::Stream::Stream ( const char *  d,
Size  n,
stream::NonOwning   
)
inline

Creates an instance from an existing memory block. The data will not be copied and hence must remain valid until the stream ether is destroyed or makeOwning() gets called, whatever comes first. Passing a nullptr for the data records a gap.

◆ Stream() [5/8]

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() [6/8]

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() [7/8]

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

Constructs a stream from another stream instance.

Parameters
otherinstance to create this stream from

◆ Stream() [8/8]

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/5]

void Stream::append ( Bytes &&  data)

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

Parameters
dataBytes to append

◆ append() [2/5]

void Stream::append ( const Bytes data)

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

Parameters
dataBytes to append

◆ append() [3/5]

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

◆ append() [4/5]

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

Appends the content of a raw memory area, not copying the data. This function does not invalidate iterators. Because the data will not be copied, it must remain valid until the stream is either destroyed or makeOwning() gets called.

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

◆ append() [5/5]

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

◆ 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.

◆ makeOwning()

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

Ensure the stream fully owns all its data.

◆ 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= ( const Stream other)
inline

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= ( Stream &&  other)
inlinenoexcept

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

Parameters
otherthe stream instance to assign from

◆ reset()

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

Returns the stream into a freshly initialized state, as if it was just created. (This concerns only externally visible state, it retains any potentially cached resources for reuse.)

◆ 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: