CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
Channel< T > Class Template Reference

Thread communication channel More...

#include <cc/Channel>

Public Types

using Item = T
 Item type.
 

Public Member Functions

 Channel ()=default
 Create a new channel.
 
bool pushBack (const T &item)
 Add a new item to the end.
 
bool pushFront (const T &item)
 Add a new item to the front.
 
bool pushExclusive (const T &item)
 Add a new item after removing all existing items.
 
template<class... Args>
bool emplaceBack (Args... args)
 Add a new item to the end.
 
template<class... Args>
bool emplaceFront (Args... args)
 Add a new item to the front.
 
template<class... Args>
bool emplaceExclusive (Args... args)
 Add a new item after replacing all existing items.
 
bool popBack (Out< T > item=None{})
 Remove an item from the end.
 
bool popFront (Out< T > item=None{})
 Remove an item from the front.
 
bool read (Out< T > item)
 Remove an item from the front.
 
bool write (const T &item)
 Add a new item to the end.
 
Channeloperator<< (const Item &item)
 Add a new item to the end.
 
Channeloperator>> (Item &item)
 Remove an item from the front.
 
bool wait ()
 Wait for the channel to become ready to read.
 
bool waitUntil (double time)
 Wait for the channel to become ready to read for a limited time.
 
bool popBackBefore (double time, Out< T > item=None{})
 Remove an item from the end of the queue before given time.
 
bool popFrontBefore (double time, Out< T > item=None{})
 Remove an item from the head of the queue before given time.
 
long count () const
 Get the number of queued items.
 
void close ()
 Close for writing.
 
void shutdown ()
 Shutdown communication: close for reading and writing and discard all intermediate data.
 
SourceIterator< Channelbegin ()
 Iteration start.
 
SourceIterator< Channelend ()
 Iteration end.
 

Detailed Description

template<class T>
class cc::Channel< T >

Thread communication channel

Template Parameters
TItem type

Member Typedef Documentation

◆ Item

template<class T >
using Item = T

Item type.

Constructor & Destructor Documentation

◆ Channel()

template<class T >
Channel ( )
default

Create a new channel.

Member Function Documentation

◆ pushBack()

template<class T >
bool pushBack ( const T & item)

Add a new item to the end.

Parameters
itemItem value
Returns
True if successful

◆ pushFront()

template<class T >
bool pushFront ( const T & item)

Add a new item to the front.

Parameters
itemItem value
Returns
True if successful

◆ pushExclusive()

template<class T >
bool pushExclusive ( const T & item)

Add a new item after removing all existing items.

Parameters
itemItem value
Returns
True if successful

◆ emplaceBack()

template<class T >
template<class... Args>
bool emplaceBack ( Args... args)

Add a new item to the end.

Template Parameters
ArgsConstruction argument types
Parameters
argsConstruction arguments
Returns
True if successful

◆ emplaceFront()

template<class T >
template<class... Args>
bool emplaceFront ( Args... args)

Add a new item to the front.

Template Parameters
ArgsConstruction argument types
Parameters
argsConstruction arguments
Returns
True if successful

◆ emplaceExclusive()

template<class T >
template<class... Args>
bool emplaceExclusive ( Args... args)

Add a new item after replacing all existing items.

Template Parameters
ArgsConstruction argument types
Parameters
argsConstruction arguments
Returns
True if successful

◆ popBack()

template<class T >
bool popBack ( Out< T > item = None{})

Remove an item from the end.

Parameters
itemReturns the item value
Returns
True if successful

◆ popFront()

template<class T >
bool popFront ( Out< T > item = None{})

Remove an item from the front.

Parameters
itemReturns the item value
Returns
True if successful

◆ read()

template<class T >
bool read ( Out< T > item)

Remove an item from the front.

Parameters
itemReturns the item value
Returns
True if successful

◆ write()

template<class T >
bool write ( const T & item)

Add a new item to the end.

Parameters
itemItem value
Returns
True if successful

◆ operator<<()

template<class T >
Channel & operator<< ( const Item & item)

Add a new item to the end.

Parameters
itemItem value
Returns
True if successful

◆ operator>>()

template<class T >
Channel & operator>> ( Item & item)

Remove an item from the front.

Parameters
itemReturns the item value
Returns
True if successful

◆ wait()

template<class T >
bool wait ( )

Wait for the channel to become ready to read.

Returns
True if successful

◆ waitUntil()

template<class T >
bool waitUntil ( double time)

Wait for the channel to become ready to read for a limited time.

Parameters
timeSeconds elapsed since the begin of Epoch
Returns
True if successful
See also
System::now()

◆ popBackBefore()

template<class T >
bool popBackBefore ( double time,
Out< T > item = None{} )

Remove an item from the end of the queue before given time.

Parameters
timeSeconds elapsed since the begin of Epoch
itemReturns the item value
Returns
True if successful
See also
System::now()

◆ popFrontBefore()

template<class T >
bool popFrontBefore ( double time,
Out< T > item = None{} )

Remove an item from the head of the queue before given time.

Parameters
timeSeconds elapsed since the begin of Epoch
itemReturns the item value
Returns
True if successful
See also
System::now()

◆ count()

template<class T >
long count ( ) const

Get the number of queued items.

◆ close()

template<class T >
void close ( )

Close for writing.

◆ shutdown()

template<class T >
void shutdown ( )

Shutdown communication: close for reading and writing and discard all intermediate data.

◆ begin()

template<class T >
SourceIterator< Channel > begin ( )

Iteration start.

◆ end()

template<class T >
SourceIterator< Channel > end ( )

Iteration end.