C++ Channel
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
msd::blocking_iterator< Channel > Class Template Reference

An iterator that blocks the current thread, waiting to fetch elements from the channel. More...

#include <blocking_iterator.hpp>

Public Types

using value_type = typename Channel::value_type
 The type of the elements stored in the channel.
 
using reference = const typename Channel::value_type &
 Constant reference to the type of the elements stored in the channel.
 
using iterator_category = std::input_iterator_tag
 Supporting single-pass reading of elements.
 
using difference_type = std::ptrdiff_t
 Signed integral type for iterator difference.
 
using pointer = const value_type *
 Pointer type to the value_type.
 

Public Member Functions

 blocking_iterator (Channel &chan, bool is_end=false)
 Constructs a blocking iterator from a channel reference.
 
blocking_iterator< Channel > & operator++ () noexcept
 Retrieves the next element from the channel.
 
reference operator* ()
 Returns the latest element retrieved from the channel.
 
bool operator!= (const blocking_iterator &other)
 Makes iteration continue until the channel is closed and empty.
 

Detailed Description

template<typename Channel>
class msd::blocking_iterator< Channel >

An iterator that blocks the current thread, waiting to fetch elements from the channel.

Used to implement channel range-based for loop.

Template Parameters
ChannelType of channel being iterated.

Constructor & Destructor Documentation

◆ blocking_iterator()

template<typename Channel >
msd::blocking_iterator< Channel >::blocking_iterator ( Channel chan,
bool  is_end = false 
)
inlineexplicit

Constructs a blocking iterator from a channel reference.

Parameters
chanReference to the channel this iterator will iterate over.
is_endIf true, the iterator is in an end state (no elements to read).

Member Function Documentation

◆ operator!=()

template<typename Channel >
bool msd::blocking_iterator< Channel >::operator!= ( const blocking_iterator< Channel > &  other)
inline

Makes iteration continue until the channel is closed and empty.

Parameters
otherAnother blocking_iterator to compare with.
Returns
true if the channel is not closed or not empty (continue iterating).
false if the channel is closed and empty (stop iterating).

◆ operator*()

template<typename Channel >
reference msd::blocking_iterator< Channel >::operator* ( )
inline

Returns the latest element retrieved from the channel.

Returns
A const reference to the element.

◆ operator++()

template<typename Channel >
blocking_iterator< Channel > & msd::blocking_iterator< Channel >::operator++ ( )
inlinenoexcept

Retrieves the next element from the channel.

Returns
The iterator itself.

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