|
C++ Channel
|
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, Storage > > |
| 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 | |
| template<typename S = Storage, typename std::enable_if< is_static_storage< S >::value, int >::type = 0> | |
| constexpr | channel () |
| Creates a buffered channel if Storage is static (has static capacity member) | |
| template<typename S = Storage, typename std::enable_if<!is_static_storage< S >::value, int >::type = 0> | |
| constexpr | channel () |
| Creates an unbuffered channel if Storage is not static (does not have static capacity member). | |
| template<typename S = Storage, typename std::enable_if<!is_static_storage< S >::value, int >::type = 0> | |
| constexpr | channel (const size_type capacity) |
| Creates a buffered channel if Storage is not static (does not have static capacity member). | |
| template<typename Type > | |
| bool | write (Type &&value) |
| Pushes an element into the channel. | |
| bool | read (T &out) |
| Pops an element from the channel. | |
| NODISCARD size_type | size () const noexcept |
| Returns the current size of the channel. | |
| NODISCARD bool | empty () const noexcept |
| Checks if the channel is empty. | |
| void | close () noexcept |
| Closes the channel, no longer accepting new elements. | |
| NODISCARD bool | closed () const noexcept |
| Checks if the channel has been closed. | |
| NODISCARD bool | drained () noexcept |
| Checks if the channel has been closed and is empty. | |
| 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 | |
| channel & | operator= (const channel &)=delete |
| channel (channel &&)=delete | |
| channel & | operator= (channel &&)=delete |
Friends | |
| template<typename Type , typename Store > | |
| channel< typename std::decay< Type >::type, Store > & | operator<< (channel< typename std::decay< Type >::type, Store > &chan, Type &&value) |
| Pushes an element into the channel. | |
| template<typename Type , typename Store > | |
| channel< Type, Store > & | operator>> (channel< Type, Store > &chan, Type &out) |
| Pops an element from the channel. | |
Thread-safe container for sharing data between threads.
| T | The type of the elements. |
| Storage | The storage type used to hold the elements. Default: msd::queue_storage. |
|
inlineconstexpr |
Creates a buffered channel if Storage is static (has static capacity member)
|
inlineexplicitconstexpr |
Creates a buffered channel if Storage is not static (does not have static capacity member).
| capacity | Number of elements the channel can store before blocking. |
|
inlinenoexcept |
Returns an iterator to the beginning of the channel.
|
inlinenoexcept |
Checks if the channel has been closed.
|
inlinenoexcept |
Checks if the channel has been closed and is empty.
|
inlinenoexcept |
Checks if the channel is empty.
|
inlinenoexcept |
Returns an iterator representing the end of the channel.
|
inline |
Pops an element from the channel.
| out | Reference to the variable where the popped element will be stored. |
|
inlinenoexcept |
Returns the current size of the channel.
|
inline |
Pushes an element into the channel.
| Type | The type of the elements. |
| value | The element to be pushed into the channel. |
|
friend |
Pushes an element into the channel.
| chan | Channel to write to. |
| value | Value to write. |
| closed_channel | if channel is closed. |
Pops an element from the channel.
| chan | Channel to read from. |
| out | Where to write read value. |