struct stream

Scope: kodo_slide

In header: #include <kodo_slide/stream.hpp>

Member functions (public)

Type & at (uint64_t index)
const Type & at (uint64_t index) const
Type & back ()
const Type & back () const
bool in_stream (uint64_t index) const
uint64_t lower_bound () const
Type & operator[] (uint64_t index)
const Type & operator[] (uint64_t index) const
uint64_t pop_back ()
uint64_t push_front (Type && data)
uint64_t push_front (const Type & element)
void reset ()
uint64_t size () const
uint64_t upper_bound () 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 Description

Type & at (uint64_t index)

Parameter index:
Access the element in the stream with the corresponding index.

const Type & at (uint64_t index)

Parameter index:
Access the element in the stream with the corresponding index.

Type & back ()

Returns:
The element located at the back of the stream

const Type & back ()

Returns:
The element located at the back of the stream

bool in_stream (uint64_t index)

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.

uint64_t lower_bound ()

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

uint64_t i = values.lower_bound();

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

Type & operator[] (uint64_t index)

Parameter index:
Access the element in the stream with the corresponding index.

const Type & operator[] (uint64_t index)

Parameter index:
Access the element in the stream with the corresponding index.

uint64_t pop_back ()

Pop the “oldest” element from the stream

Returns:
The stream index assigned to the popped element.

uint64_t push_front (Type && data)

Parameter data:
Push element in the front of the stream.
Returns:
The stream index assigned to the element.

uint64_t push_front (const Type & element)

Parameter element:
Push element in the front of the stream.
Returns:
The stream index assigned to the element.

void reset ()

Reset the state of the stream.

uint64_t size ()

Returns:
The number of elements in the stream.

uint64_t upper_bound ()

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.