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

Thread-safe container for sharing data between threads. More...

#include <channel.hpp>

Public Types

using value_type = T
 The type of elements stored in the channel.
 
using iterator = blocking_iterator< channel< T > >
 The iterator type used to traverse the channel.
 
using size_type = std::size_t
 The type used to represent sizes and counts.
 

Public Member Functions

constexpr channel ()=default
 Creates an unbuffered channel.
 
constexpr channel (const size_type capacity)
 Creates a buffered channel.
 
NODISCARD size_type constexpr size () const noexcept
 Returns the current size of the channel.
 
NODISCARD bool constexpr empty () const noexcept
 Checks if the channel is empty.
 
void close () noexcept
 Closes the channel.
 
NODISCARD bool closed () const noexcept
 Checks if the channel has been closed.
 
iterator begin () noexcept
 Returns an iterator to the beginning of the channel.
 
iterator end () noexcept
 Returns an iterator representing the end of the channel.
 
 channel (const channel &)=delete
 
channeloperator= (const channel &)=delete
 
 channel (channel &&)=delete
 
channeloperator= (channel &&)=delete
 

Friends

class blocking_iterator< channel >
 
template<typename Type >
channel< typename std::decay< Type >::type > & operator<< (channel< typename std::decay< Type >::type > &, Type &&)
 Pushes an element into the channel.
 
template<typename Type >
channel< Type > & operator>> (channel< Type > &, Type &)
 Pops an element from the channel.
 

Detailed Description

template<typename T>
class msd::channel< T >

Thread-safe container for sharing data between threads.

Implements a blocking input iterator.

Template Parameters
TThe type of the elements.

Constructor & Destructor Documentation

◆ channel() [1/2]

template<typename T >
constexpr msd::channel< T >::channel ( const size_type  capacity)
inlineexplicitconstexpr

Creates a buffered channel.

Parameters
capacityNumber of elements the channel can store before blocking.

◆ channel() [2/2]

template<typename T >
msd::channel< T >::channel ( const channel< T > &  )
delete

Channel cannot be copied or moved.

Member Function Documentation

◆ begin()

template<typename T >
iterator msd::channel< T >::begin ( )
inlinenoexcept

Returns an iterator to the beginning of the channel.

Returns
A blocking iterator pointing to the start of the channel.

◆ closed()

template<typename T >
NODISCARD bool msd::channel< T >::closed ( ) const
inlinenoexcept

Checks if the channel has been closed.

Returns
true If no more elements can be added to the channel.
false Otherwise.

◆ empty()

template<typename T >
NODISCARD bool constexpr msd::channel< T >::empty ( ) const
inlineconstexprnoexcept

Checks if the channel is empty.

Returns
true If the channel contains no elements.
false Otherwise.

◆ end()

template<typename T >
iterator msd::channel< T >::end ( )
inlinenoexcept

Returns an iterator representing the end of the channel.

Returns
A blocking iterator representing the end condition.

◆ size()

template<typename T >
NODISCARD size_type constexpr msd::channel< T >::size ( ) const
inlineconstexprnoexcept

Returns the current size of the channel.

Returns
The number of elements in the channel.

Friends And Related Symbol Documentation

◆ operator<<

template<typename T >
template<typename Type >
channel< typename std::decay< Type >::type > & operator<< ( channel< typename std::decay< Type >::type > &  ,
Type &&   
)
friend

Pushes an element into the channel.

Exceptions
closed_channelif channel is closed.

◆ operator>>

template<typename T >
template<typename Type >
channel< Type > & operator>> ( channel< Type > &  ,
Type  
)
friend

Pops an element from the channel.

Template Parameters
TypeThe type of the elements

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