Template Class VariantQueue
Defined in File variant_queue.hpp
Class Documentation
-
template<typename ValueType, uint64_t Capacity>
class VariantQueue wrapper of multiple fifo’s
- Param ValueType:
[in] type which should be stored
- Param Capacity:
[in] 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
Public Functions
-
VariantQueue(const VariantQueueTypes type) noexcept
Constructor of a VariantQueue.
- Parameters:
type – [in] type of the underlying queue
-
optional<ValueType> push(const ValueType &value) noexcept
pushs an element into the fifo
- Parameters:
value – [in] value 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
-
optional<ValueType> 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
-
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
- Returns:
queue size
-
bool setCapacity(const uint64_t newCapacity) noexcept
set the capacity of the queue
Note
depending on the internal queue used, concurrent pushes and pops are possible (for FiFo_MultiProducerSingleConsumer and SoFi_MultiProducerSingleConsumer) @concurrent not thread safe
- Parameters:
newCapacity – [in] valid values are 0 < newCapacity < MAX_SUBSCRIBER_QUEUE_CAPACITY
- Returns:
true if setting the new capacity succeeded, false otherwise
- Pre:
it is important that no pop or push calls occur during this call
-
uint64_t capacity() const noexcept
get the capacity of the queue.
- Returns:
queue size
-
fifo_t &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();