Thread-safe container for sharing data between threads.
More...
#include <channel.hpp>
|
|
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.
|
|
| 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(std::is_nothrow_default_constructible< T >::value &&std::is_nothrow_move_assignable< T >::value) |
| | Returns an iterator to the beginning of the channel.
|
| iterator | end () noexcept(std::is_nothrow_default_constructible< T >::value &&std::is_nothrow_move_assignable< T >::value) |
| | 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 |
|
| 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.
|
template<typename T, typename Storage = default_storage<T>>
class msd::channel< T, Storage >
Thread-safe container for sharing data between threads.
- Not movable, not copyable.
- Includes a blocking input iterator.
- Template Parameters
-
| T | The type of the elements. |
| Storage | The storage type used to hold the elements. Default: msd::queue_storage. |
◆ channel() [1/2]
template<typename T, typename Storage = default_storage<T>>
template<typename S = Storage, typename std::enable_if<
is_static_storage< S >::value, int >::type = 0>
Creates a buffered channel if Storage is static (has static capacity member).
- Note
- Uses Storage::capacity as number of elements the channel can store before blocking.
◆ channel() [2/2]
template<typename T, typename Storage = default_storage<T>>
template<typename S = Storage, typename std::enable_if<!
is_static_storage< S >::value, int >::type = 0>
Creates a buffered channel if Storage is not static (does not have static capacity member).
- Parameters
-
| capacity | Number of elements the channel can store before blocking. |
◆ begin()
template<typename T, typename Storage = default_storage<T>>
Returns an iterator to the beginning of the channel.
- Returns
- A blocking iterator pointing to the start of the channel.
◆ closed()
template<typename T, typename Storage = default_storage<T>>
Checks if the channel has been closed.
- Returns
- true If no more elements can be added to the channel.
-
false Otherwise.
◆ drained()
template<typename T, typename Storage = default_storage<T>>
Checks if the channel has been closed and is empty.
- Returns
- true If nothing can be read anymore from the channel.
-
false Otherwise.
◆ empty()
template<typename T, typename Storage = default_storage<T>>
Checks if the channel is empty.
- Returns
- true If the channel contains no elements.
-
false Otherwise.
◆ end()
template<typename T, typename Storage = default_storage<T>>
Returns an iterator representing the end of the channel.
- Returns
- A blocking iterator representing the end condition.
◆ read()
template<typename T, typename Storage = default_storage<T>>
Pops an element from the channel.
- Parameters
-
| out | Reference to the variable where the popped element will be stored. |
- Returns
- true If an element was successfully read from the channel.
-
false If the channel is closed and empty.
◆ size()
template<typename T, typename Storage = default_storage<T>>
Returns the current size of the channel.
- Returns
- The number of elements in the channel.
◆ write()
template<typename T, typename Storage = default_storage<T>>
template<typename Type>
Pushes an element into the channel.
- Template Parameters
-
| Type | The type of the elements. |
- Parameters
-
| value | The element to be pushed into the channel. |
- Returns
- true If an element was successfully pushed into the channel.
-
false If the channel is closed.
◆ operator<<
template<typename T, typename Storage = default_storage<T>>
template<typename Type, typename Store>
| channel< typename std::decay< Type >::type, Store > & operator<< |
( |
channel< typename std::decay< Type >::type, Store > & | chan, |
|
|
Type && | value ) |
|
friend |
Pushes an element into the channel.
- Parameters
-
| chan | Channel to write to. |
| value | Value to write. |
- Returns
- Instance of channel.
- Exceptions
-
◆ operator>>
template<typename T, typename Storage = default_storage<T>>
template<typename Type, typename Store>
| channel< Type, Store > & operator>> |
( |
channel< Type, Store > & | chan, |
|
|
Type & | out ) |
|
friend |
Pops an element from the channel.
- Parameters
-
| chan | Channel to read from. |
| out | Where to write read value. |
- Returns
- Instance of channel.
The documentation for this class was generated from the following file: