Uniot Core
0.8.1
Loading...
Searching...
No Matches
LimitedQueue< T > Class Template Reference

#include <LimitedQueue.h>

Inheritance diagram for LimitedQueue< T >:
[legend]

Public Member Functions

 LimitedQueue ()
 Construct a new LimitedQueue with default settings.
 
size_t limit () const
 Get the current size limit of the queue.
 
size_t size () const
 Get the current number of elements in the queue.
 
void limit (size_t limit)
 Set the maximum size limit for the queue.
 
bool isFull () const
 Check if the queue has reached its size limit.
 
void applyLimit ()
 Enforce the size limit by removing oldest elements if necessary.
 
void pushLimited (const T &value)
 Add an element to the queue while respecting the size limit.
 
popLimited (const T &errorCode)
 Remove and return the oldest element from the queue.
 
size_t calcSize () const
 Recalculate the size by traversing the queue.
 
void clean ()
 Remove all elements from the queue.
 
- Public Member Functions inherited from ClearQueue< T >
 ClearQueue (ClearQueue const &)=delete
 Deleted copy constructor to prevent copying.
 
void operator= (ClearQueue const &)=delete
 Deleted assignment operator to prevent copying.
 
 ClearQueue ()
 Constructs an empty queue.
 
virtual ~ClearQueue ()
 Destroys the queue and releases all allocated memory.
 
void push (const T &value)
 Adds an element to the end of the queue.
 
bool pushUnique (const T &value)
 Adds an element to the queue only if it doesn't already exist.
 
hardPop ()
 Removes and returns the element at the front of the queue.
 
const T & hardPeek () const
 Returns the element at the front of the queue without removing it.
 
pop (const T &errorCode)
 Safely removes and returns the element at the front of the queue.
 
const T & peek (const T &errorCode) const
 Safely returns the element at the front of the queue without removing it.
 
bool removeOne (const T &value)
 Removes the first occurrence of a specific value from the queue.
 
bool contains (const T &value) const
 Checks if the queue contains a specific value.
 
T * find (const T &value) const
 Finds and returns a pointer to the first occurrence of a value.
 
bool isEmpty () const
 Checks if the queue is empty.
 
size_t calcSize () const
 Calculate the number of elements in the queue by traversal.
 
void clean ()
 Removes all elements from the queue.
 
void forEach (VoidCallback callback) const
 Executes a callback function on each element in the queue.
 

Additional Inherited Members

- Public Types inherited from ClearQueue< T >
typedef std::function< void(const T &)> VoidCallback
 Callback function type for forEach operations.
 
- Protected Types inherited from ClearQueue< T >
typedef struct ClearQueue::nodepnode
 Node structure for the linked list implementation.
 
- Protected Attributes inherited from ClearQueue< T >
pnode mHead
 Pointer to the first node in the queue.
 
pnode mTail
 Pointer to the last node in the queue.
 

Constructor & Destructor Documentation

◆ LimitedQueue()

template<typename T>
LimitedQueue< T >::LimitedQueue ( )
inline

Construct a new LimitedQueue with default settings.

Creates an empty queue with a size limit of 0 (unlimited by default)

Member Function Documentation

◆ applyLimit()

template<typename T>
void LimitedQueue< T >::applyLimit ( )
inline

Enforce the size limit by removing oldest elements if necessary.

Removes elements from the front of the queue until the size is within limits

◆ calcSize()

template<typename T>
size_t LimitedQueue< T >::calcSize ( ) const
inline

Recalculate the size by traversing the queue.

This method should be used if the size tracking may have become inconsistent

Return values
size_tThe actual number of elements in the queue

◆ clean()

template<typename T>
void LimitedQueue< T >::clean ( )
inline

Remove all elements from the queue.

Resets the queue to its initial empty state

◆ isFull()

template<typename T>
bool LimitedQueue< T >::isFull ( ) const
inline

Check if the queue has reached its size limit.

Return values
trueIf the queue is full (size >= limit)
falseIf the queue has space for more elements

◆ limit() [1/2]

template<typename T>
size_t LimitedQueue< T >::limit ( ) const
inline

Get the current size limit of the queue.

Return values
size_tThe maximum number of elements the queue can hold

◆ limit() [2/2]

template<typename T>
void LimitedQueue< T >::limit ( size_t limit)
inline

Set the maximum size limit for the queue.

If the new limit is smaller than the current size, oldest elements are automatically removed.

Parameters
limitThe maximum number of elements the queue can hold

◆ popLimited()

template<typename T>
T LimitedQueue< T >::popLimited ( const T & errorCode)
inline

Remove and return the oldest element from the queue.

Parameters
errorCodeValue to return if the queue is empty
Return values
TThe removed element
errorCodeThe value to return if the queue is empty

◆ pushLimited()

template<typename T>
void LimitedQueue< T >::pushLimited ( const T & value)
inline

Add an element to the queue while respecting the size limit.

If adding the element would exceed the size limit, the oldest element is removed first

Parameters
valueThe element to add to the queue

◆ size()

template<typename T>
size_t LimitedQueue< T >::size ( ) const
inline

Get the current number of elements in the queue.

Return values
size_tThe current number of elements

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