Simple-Log  alpha-v0.7
sl::log::RecordQueue< TRecord > Class Template Reference

Storage for Record s. More...

#include <RecordQueue.hpp>

Public Types

using Record_t = std::remove_cvref_t< TRecord >
 

Public Member Functions

void push (Record_t record)
 Pushes Record s to the internal queue. More...
 
std::optional< Record_ttake (std::optional< std::chrono::milliseconds > waitingDuration=std::nullopt)
 Takes the first Record from the queue. More...
 
bool empty () const noexcept
 Checks if the internal queue is empty. More...
 
std::size_t size () const noexcept
 Checks size of the internal queue. More...
 

Detailed Description

template<Record TRecord>
class sl::log::RecordQueue< TRecord >

Storage for Record s.

Template Parameters
TRecordUsed Record type.

This class is a simple representation of a blocking queue. Its take() function blocks until an element is present in the internal queue or the duration exceeded. Each function is thread-safe by design.

Member Typedef Documentation

◆ Record_t

template<Record TRecord>
using sl::log::RecordQueue< TRecord >::Record_t = std::remove_cvref_t<TRecord>

Member Function Documentation

◆ empty()

template<Record TRecord>
bool sl::log::RecordQueue< TRecord >::empty ( ) const
inlinenoexcept

Checks if the internal queue is empty.

Thread-safe

Returns
Returns true if is empty.

◆ push()

template<Record TRecord>
void sl::log::RecordQueue< TRecord >::push ( Record_t  record)
inline

Pushes Record s to the internal queue.

Thread-safe

Parameters
recordThe queued Record object.

◆ size()

template<Record TRecord>
std::size_t sl::log::RecordQueue< TRecord >::size ( ) const
inlinenoexcept

Checks size of the internal queue.

Thread-safe

Returns
Returns size

◆ take()

template<Record TRecord>
std::optional<Record_t> sl::log::RecordQueue< TRecord >::take ( std::optional< std::chrono::milliseconds >  waitingDuration = std::nullopt)
inline

Takes the first Record from the queue.

Thread-safe If the internal queue is not empty, this functions takes the first element and returns it. If the queue is empty, this function will block until a new Record gets pushed into the queue or the duration exceeds.

Parameters
waitingDurationThe max waiting duration for an element.
Returns
Returns an element as optional. Might be nullopt.

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