Health-GPS  1.2.2.0
Global Health Policy Simulation model (Health-GPS)
hgps::Channel< T > Class Template Reference

Thread-safe communication channel data type. More...

#include <channel.h>

Public Types

using value_type = T
 
using size_type = std::size_t
 

Public Member Functions

 Channel (size_type capacity=0)
 Initialises a new instance of the Channel class. More...
 
 Channel (const Channel &)=delete
 
Channeloperator= (const Channel &)=delete
 
 Channel (Channel &&)=delete
 
Channeloperator= (Channel &&)=delete
 
virtual ~Channel ()=default
 Destroys a Channel instance. More...
 
bool send (const value_type &message)
 Sends a new message through the channel by reference. More...
 
bool send (value_type &&message)
 Sends a new message through the channel. More...
 
std::optional< value_typetry_receive (int timeout_millis=0)
 Try to receive a message from the channel. More...
 
constexpr size_type size () const noexcept
 Gets the current channel size, number of messages. More...
 
constexpr bool empty () const noexcept
 Determine whether the channel is empty. More...
 
void close () noexcept
 Close the channel, no new messages are accepted. More...
 
bool closed () const noexcept
 Determine whether the channel is closed. More...
 

Detailed Description

template<typename T>
class hgps::Channel< T >

Thread-safe communication channel data type.

This channel has been designed specific to enable in-memory communication from the baseline to the intervention scenarios simulations. This is a hard modelling requirement, non-memory communication such as data streaming might offer more scalable alternative, including the option of running a single baseline and multiple interventions in parallel.

Note
Messages in the channel are kept in a FIFO queue to guarantee receive order for the intervention algorithm.
Template Parameters
TThe channel data type

Member Typedef Documentation

◆ size_type

template<typename T >
using hgps::Channel< T >::size_type = std::size_t

◆ value_type

template<typename T >
using hgps::Channel< T >::value_type = T

Constructor & Destructor Documentation

◆ Channel() [1/3]

template<typename T >
hgps::Channel< T >::Channel ( size_type  capacity = 0)
inlineexplicit

Initialises a new instance of the Channel class.

Parameters
capacityThe channel capacity, if fixed; otherwise, unlimited

◆ Channel() [2/3]

template<typename T >
hgps::Channel< T >::Channel ( const Channel< T > &  )
delete

◆ Channel() [3/3]

template<typename T >
hgps::Channel< T >::Channel ( Channel< T > &&  )
delete

◆ ~Channel()

template<typename T >
virtual hgps::Channel< T >::~Channel ( )
virtualdefault

Destroys a Channel instance.

Member Function Documentation

◆ close()

template<typename T >
void hgps::Channel< T >::close ( )
inlinenoexcept

Close the channel, no new messages are accepted.

◆ closed()

template<typename T >
bool hgps::Channel< T >::closed ( ) const
inlinenoexcept

Determine whether the channel is closed.

Returns
true, if the channel is closed; otherwise, false.
Here is the caller graph for this function:

◆ empty()

template<typename T >
constexpr bool hgps::Channel< T >::empty ( ) const
inlineconstexprnoexcept

Determine whether the channel is empty.

Returns
true, if there are no messages; otherwise, false.

◆ operator=() [1/2]

template<typename T >
Channel& hgps::Channel< T >::operator= ( Channel< T > &&  )
delete

◆ operator=() [2/2]

template<typename T >
Channel& hgps::Channel< T >::operator= ( const Channel< T > &  )
delete

◆ send() [1/2]

template<typename T >
bool hgps::Channel< T >::send ( const value_type message)
inline

Sends a new message through the channel by reference.

Parameters
messageThe message instance to send
Returns
true, the operation succeeded; otherwise false

◆ send() [2/2]

template<typename T >
bool hgps::Channel< T >::send ( value_type &&  message)
inline

Sends a new message through the channel.

Parameters
messageThe message instance to send
Returns
true, the operation succeeded; otherwise false

◆ size()

template<typename T >
constexpr size_type hgps::Channel< T >::size ( ) const
inlineconstexprnoexcept

Gets the current channel size, number of messages.

Returns
The channel size

◆ try_receive()

template<typename T >
std::optional<value_type> hgps::Channel< T >::try_receive ( int  timeout_millis = 0)
inline

Try to receive a message from the channel.

Parameters
timeout_millisMax wait timeout, or zero for infinity
Returns
The received message, if arrived; otherwise empty.
Here is the call graph for this function:

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