iceoryx_hoofs 2.0.3
Public Types | Public Member Functions | List of all members
iox::cxx::VariantQueue< ValueType, Capacity > Class Template Reference

wrapper of multiple fifo's More...

#include <iceoryx_hoofs/cxx/variant_queue.hpp>

Public Types

using fifo_t = variant< concurrent::FiFo< ValueType, Capacity >, concurrent::SoFi< ValueType, Capacity >, concurrent::ResizeableLockFreeQueue< ValueType, Capacity >, concurrent::ResizeableLockFreeQueue< ValueType, Capacity > >
 

Public Member Functions

 VariantQueue (const VariantQueueTypes type) noexcept
 Constructor of a VariantQueue. More...
 
optional< ValueType > push (const ValueType &value) noexcept
 pushs an element into the fifo More...
 
optional< ValueType > pop () noexcept
 pops an element from the fifo More...
 
bool empty () const noexcept
 returns true if empty otherwise true
 
uint64_t size () noexcept
 get the current size of the queue. Caution, another thread can have changed the size just after reading it More...
 
bool setCapacity (const uint64_t newCapacity) noexcept
 set the capacity of the queue More...
 
uint64_t capacity () const noexcept
 get the capacity of the queue. More...
 
fifo_tgetUnderlyingFiFo () noexcept
 returns reference to the underlying fifo More...
 

Detailed Description

template<typename ValueType, uint64_t Capacity>
class iox::cxx::VariantQueue< ValueType, Capacity >

wrapper of multiple fifo's

Parameters
[in]ValueTypetype which should be stored
[in]Capacitycapacity of the underlying fifo
cxx::VariantQueue<int, 5> nonOverflowingQueue(cxx::VariantQueueTypes::FiFo_SingleProducerSingleConsumer);
cxx::VariantQueue<int, 5> overflowingQueue(cxx::VariantQueueTypes::SoFi_SingleProducerSingleConsumer);
// overflow case
auto status = nonOverflowingQueue.push(123);
if ( !status ) {
std::cout << "queue is full" << std::endl;
}
auto overriddenElement = overflowingQueue.push(123);
if ( overriddenElement->has_value() ) {
std::cout << "element " << overriddenElement->value() << " was overridden\n";
}
wrapper of multiple fifo's
Definition: variant_queue.hpp:71

Constructor & Destructor Documentation

◆ VariantQueue()

template<typename ValueType , uint64_t Capacity>
iox::cxx::VariantQueue< ValueType, Capacity >::VariantQueue ( const VariantQueueTypes  type)
noexcept

Constructor of a VariantQueue.

Parameters
[in]typetype of the underlying queue

Member Function Documentation

◆ capacity()

template<typename ValueType , uint64_t Capacity>
uint64_t iox::cxx::VariantQueue< ValueType, Capacity >::capacity ( ) const
noexcept

get the capacity of the queue.

Returns
queue size

◆ getUnderlyingFiFo()

template<typename ValueType , uint64_t Capacity>
fifo_t & iox::cxx::VariantQueue< ValueType, Capacity >::getUnderlyingFiFo ( )
noexcept

returns reference to the underlying fifo

VariantQueueTypes<int, 10> myFifo(VariantQueueTypes::FiFo_SingleProducerSingleConsumer);
// access the underlying fifo directly and call empty on it
myFifo.getUnderlyingFiFo().template
get_at_index<VariantQueueTypes::FiFo_SingleProducerSingleConsumer>()->empty();

◆ pop()

template<typename ValueType , uint64_t Capacity>
optional< ValueType > iox::cxx::VariantQueue< ValueType, Capacity >::pop ( )
noexcept

pops an element from the fifo

Returns
if the fifo did contain an element it is returned inside the optional otherwise the optional contains nullopt_t

◆ push()

template<typename ValueType , uint64_t Capacity>
optional< ValueType > iox::cxx::VariantQueue< ValueType, Capacity >::push ( const ValueType &  value)
noexcept

pushs an element into the fifo

Parameters
[in]valuevalue which should be added in the fifo
Returns
if the underlying queue has an overflow the optional will contain the value which was overridden (SOFI) or which was dropped (FIFO) otherwise the optional contains nullopt_t

◆ setCapacity()

template<typename ValueType , uint64_t Capacity>
bool iox::cxx::VariantQueue< ValueType, Capacity >::setCapacity ( const uint64_t  newCapacity)
noexcept

set the capacity of the queue

Parameters
[in]newCapacityvalid values are 0 < newCapacity < MAX_SUBSCRIBER_QUEUE_CAPACITY
Returns
true if setting the new capacity succeeded, false otherwise
Precondition
it is important that no pop or push calls occur during this call
Note
depending on the internal queue used, concurrent pushes and pops are possible (for FiFo_MultiProducerSingleConsumer and SoFi_MultiProducerSingleConsumer)
Concurrent:
not thread safe

◆ size()

template<typename ValueType , uint64_t Capacity>
uint64_t iox::cxx::VariantQueue< ValueType, Capacity >::size ( )
noexcept

get the current size of the queue. Caution, another thread can have changed the size just after reading it

Returns
queue size

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