Warning: This is a development version. The latest stable version is Version 11.0.1.

struct stream

Scope: kodo_slide

Template parameters

template <class Type>
struct stream

Member functions (public)

std::size_t size () const
bool is_empty () const
std::size_t lower_bound () const
std::size_t upper_bound () const
void set_lower_bound (std::size_t lower_bound)
std::size_t push_front (const Type & element)
std::size_t push_front (Type && data)
std::size_t pop_back ()
void reset ()
Type & back ()
const Type & back () const
Type & at (std::size_t index)
const Type & at (std::size_t index) const
const Type & operator[] (std::size_t index) const
Type & operator[] (std::size_t index)
bool in_stream (std::size_t index) const

Description

Stream container - implemented as an adapter around a std::deque.

The stream elements are pushed and popped from the stream. Each element has a specific absolute stream index.

Example:

Pushing to the stream will increase the size and popping will move the offset.

stream<bool> example;

example.push_front(true); // size = 1, offset = 0
example.push_front(false); // size = 2, offset = 0
example.push_front(true); // size = 3, offset = 0
example.pop_back();       // size = 2, offset = 1
example.push_front(false); // size = 3, offset = 1

Element access uses absolute indexing.

bool b0 = example[0]; // ILLEGAL! The element at index 0 was popped
bool b1 = example[1]; // OK! The element at index 1
bool b2 = example[2]; // OK! The element at index 2
bool b3 = example[3]; // OK! The element at index 3

Member Function Descriptions

std::size_t size () const
Returns:
The number of elements in the stream.

bool is_empty () const
Returns:
True if the stream is empty, otherwise false.

std::size_t lower_bound () const
Returns:

This is the index of the “oldest” element in the stream. I.e. to iterate over all elements in the stream:

stream<bool> values;

/// ... some code pushing and popping

std::size_t i = values.lower_bound();

while (i < values.upper_bound())
{
    std::cout << i << " " << values[i] << "\n";
    ++i;
}

std::size_t upper_bound () const
Returns:
The non-inclusive index of the newest symbol in the stream. Non inclusive means that the newest symbol has index indicies non-inclusive are elegance you can find more information on this by looking at the Python’s range(…) function is non inclusive.

void set_lower_bound (std::size_t lower_bound)

Set the stream lower bound. The stream must be empty before calling this function.

Parameter lower_bound:
The new lower bound.

std::size_t push_front (const Type & element)
Parameter element:
Push element in the front of the stream.
Returns:
The stream index assigned to the element.

std::size_t push_front (Type && data)
Parameter data:
Push element in the front of the stream.
Returns:
The stream index assigned to the element.

std::size_t pop_back ()

Pop the “oldest” element from the stream

Returns:
The stream index assigned to the popped element.

void reset ()
Reset the state of the stream.

Type & back ()
Returns:
The element located at the back of the stream

const Type & back () const
Returns:
The element located at the back of the stream

Type & at (std::size_t index)
Parameter index:
Access the element in the stream with the corresponding index.

const Type & at (std::size_t index) const
Parameter index:
Access the element in the stream with the corresponding index.

const Type & operator[] (std::size_t index) const
Parameter index:
Access the element in the stream with the corresponding index.

Type & operator[] (std::size_t index)
Parameter index:
Access the element in the stream with the corresponding index.

bool in_stream (std::size_t index) const
Parameter index:
Check if index is a valid index in the stream
Returns:
True if an element with index is in the stream otherwise false.