ark::core::CircularBuffer

Defined in header “ark/core/circular_buffer.hh”.


Forward declare for the iterator.

A simple implementation of an STL-like circular buffer. If you prefer a FIFO-style queue, and know the upper limits of how many items will be in that queue, this can save some expansions/memory allocations.

Typedefs

Methods

  • CircularBuffer(std::size_t max_capacity, bool allow_overwrite)
    Constructs the circular buffer, which can store the given number of items at maximum.

  • CircularBuffer(CircularBuffer && other)
    Move constructor.

  • CircularBuffer(const CircularBuffer & other)
    Copy constructor.

  • ~CircularBuffer()
    Destructor. Cleans up memory.

  • CircularBuffer & operator=(CircularBuffer && other)
    Move operator.

  • CircularBuffer & operator=(const CircularBuffer & other)
    Copy operator.

  • void push(Type type)
    Copies the given item into the circular buffer, if there is room. Throws if there is not room.

  • void emplace(Args &&… args)
    Emplaces the given item into the circular buffer, if there is room. Throws if there is not room.

  • Type pop()
    Pops an item off the front of the buffer, if there are any items.

  • void pop_back()
    Pops an item off the rear of the buffer, if there are items.

  • const Type & front()
    Peeks at an item from the front of the buffer, if there are any items. This would be the item that you receive when calling pop().

    The reference will become invalid if you push anything else onto this buffer.

  • const Type & back()
    Peeks at an item from the back of the buffer, if there are any items. This is the last item in the buffer (most recently inserted).

    The reference will become invalid if you push anything else onto this buffer.

  • constexpr iterator begin()
    Returns an iterator to the beginning of the data in the buffer.

  • constexpr const_iterator cbegin()
    Returns an const_iterator to the beginning of the data in the buffer.

  • constexpr iterator end()
    Returns an iterator to the end of the data in the buffer.

  • constexpr const_iterator cend()
    Returns an const_iterator to the end of the data in the buffer.

  • iterator erase(iterator pos)
    Erase an element from the buffer.

    See std::vector::erase for behaviour.

  • std::size_t size()
    Returns the size (number of elements) in the buffer.

  • bool empty()
    Returns true if this buffer is empty or not.

  • std::size_t capacity()
    Returns the capacity of this buffer.

  • void clear()
    Clears the entire buffer.

  • uint64_t items_added()

  • uint64_t items_dropped()