Skip to content

iox::cxx::VariantQueue🔗

wrapper of multiple fifo's More...

#include <iceoryx_hoofs/cxx/variant_queue.hpp>

Public Types🔗

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

Public Functions🔗

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

Detailed Description🔗

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

wrapper of multiple fifo's

Parameters:

  • ValueType type which should be stored
  • Capacity capacity 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";
}

Public Types Documentation🔗

using fifo_t🔗

using iox::cxx::VariantQueue< ValueType, Capacity >::fifo_t =  variant<concurrent::FiFo<ValueType, Capacity>, concurrent::SoFi<ValueType, Capacity>, concurrent::ResizeableLockFreeQueue<ValueType, Capacity>, concurrent::ResizeableLockFreeQueue<ValueType, Capacity> >;

Public Functions Documentation🔗

function VariantQueue🔗

VariantQueue(
    const VariantQueueTypes type
)

Constructor of a VariantQueue.

Parameters:

  • type type of the underlying queue

function push🔗

optional< ValueType > push(
    const ValueType & value
)

pushs an element into the fifo

Parameters:

  • value value which should be added in the fifo

Return: 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

function pop🔗

optional< ValueType > pop()

pops an element from the fifo

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

function empty🔗

bool empty() const

returns true if empty otherwise true

function size🔗

uint64_t size()

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

Return: queue size

function setCapacity🔗

bool setCapacity(
    const uint64_t newCapacity
)

set the capacity of the queue

Parameters:

  • newCapacity valid values are 0 < newCapacity < MAX_SUBSCRIBER_QUEUE_CAPACITY

Return: true if setting the new capacity succeeded, false otherwise

Note: depending on the internal queue used, concurrent pushes and pops are possible (for FiFo_MultiProducerSingleConsumer and SoFi_MultiProducerSingleConsumer)

Precondition: it is important that no pop or push calls occur during this call

function capacity🔗

uint64_t capacity() const

get the capacity of the queue.

Return: queue size

function getUnderlyingFiFo🔗

fifo_t & getUnderlyingFiFo()

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();

Updated on 2 April 2022 at 16:37:47 CEST