Chatterino
Public Member Functions | List of all members
chatterino::LimitedQueue< T > Class Template Reference

#include <LimitedQueue.hpp>

Public Member Functions

 LimitedQueue (size_t limit=1000)
 
bool empty () const
 Return true if the buffer is empty. More...
 
boost::optional< T > get (size_t index) const
 Value Accessors. More...
 
boost::optional< T > first () const
 Get the first item from the queue. More...
 
boost::optional< T > last () const
 Get the last item from the queue. More...
 
void clear ()
 Modifiers. More...
 
bool pushBack (const T &item, T &deleted)
 Push an item to the end of the queue. More...
 
bool pushBack (const T &item)
 Push an item to the end of the queue. More...
 
std::vector< T > pushFront (const std::vector< T > &items)
 Push items into beginning of queue. More...
 
template<typename Equals = std::equal_to<T>>
int replaceItem (const T &needle, const T &replacement)
 Replace the needle with the given item. More...
 
bool replaceItem (size_t index, const T &replacement)
 Replace the item at index with the given item. More...
 
template<typename Equals = std::equal_to<T>>
bool insertBefore (const T &needle, const T &item)
 Inserts the given item before another item. More...
 
template<typename Equals = std::equal_to<T>>
bool insertAfter (const T &needle, const T &item)
 Inserts the given item after another item. More...
 
LimitedQueueSnapshot< T > getSnapshot () const
 
template<typename Predicate >
boost::optional< T > find (Predicate pred) const
 Returns the first item matching a predicate. More...
 
template<typename Predicate >
boost::optional< T > rfind (Predicate pred) const
 Returns the first item matching a predicate, checking in reverse. More...
 

Constructor & Destructor Documentation

◆ LimitedQueue()

template<typename T>
chatterino::LimitedQueue< T >::LimitedQueue ( size_t  limit = 1000)
inline

Member Function Documentation

◆ clear()

template<typename T>
void chatterino::LimitedQueue< T >::clear ( )
inline

Modifiers.

Here is the caller graph for this function:

◆ empty()

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

Return true if the buffer is empty.

Here is the caller graph for this function:

◆ find()

template<typename T>
template<typename Predicate >
boost::optional<T> chatterino::LimitedQueue< T >::find ( Predicate  pred) const
inline

Returns the first item matching a predicate.

The contents of the LimitedQueue are iterated over from front to back until the first element that satisfies pred(item). If no item satisfies the predicate, or if the queue is empty, then boost::none is returned.

Parameters
[in]predpredicate that will be applied to items
Returns
the first item found or boost::none
Here is the caller graph for this function:

◆ first()

template<typename T>
boost::optional<T> chatterino::LimitedQueue< T >::first ( ) const
inline

Get the first item from the queue.

Returns
the item at the front of the queue if it's populated, or none the queue is empty

◆ get()

template<typename T>
boost::optional<T> chatterino::LimitedQueue< T >::get ( size_t  index) const
inline

Value Accessors.

Get the item at the given index safely

Parameters
[in]indexthe index of the item to fetch
Returns
the item at the index if it's populated, or none if it's not

◆ getSnapshot()

template<typename T>
LimitedQueueSnapshot<T> chatterino::LimitedQueue< T >::getSnapshot ( ) const
inline
Here is the caller graph for this function:

◆ insertAfter()

template<typename T>
template<typename Equals = std::equal_to<T>>
bool chatterino::LimitedQueue< T >::insertAfter ( const T &  needle,
const T &  item 
)
inline

Inserts the given item after another item.

Parameters
[in]needlethe item to use as positional reference
[in]itemthe item to insert after needle
Template Parameters
Equalityfunction object to use for comparison
Returns
true if an insertion took place
Here is the caller graph for this function:

◆ insertBefore()

template<typename T>
template<typename Equals = std::equal_to<T>>
bool chatterino::LimitedQueue< T >::insertBefore ( const T &  needle,
const T &  item 
)
inline

Inserts the given item before another item.

Parameters
[in]needlethe item to use as positional reference
[in]itemthe item to insert before needle
Template Parameters
Equalityfunction object to use for comparison
Returns
true if an insertion took place
Here is the caller graph for this function:

◆ last()

template<typename T>
boost::optional<T> chatterino::LimitedQueue< T >::last ( ) const
inline

Get the last item from the queue.

Returns
the item at the back of the queue if it's populated, or none the queue is empty

◆ pushBack() [1/2]

template<typename T>
bool chatterino::LimitedQueue< T >::pushBack ( const T &  item,
T &  deleted 
)
inline

Push an item to the end of the queue.

Parameters
itemthe item to push
[out]deletedthe item that was deleted
Returns
true if an element was deleted to make room
Here is the caller graph for this function:

◆ pushBack() [2/2]

template<typename T>
bool chatterino::LimitedQueue< T >::pushBack ( const T &  item)
inline

Push an item to the end of the queue.

Parameters
itemthe item to push
Returns
true if an element was deleted to make room

◆ pushFront()

template<typename T>
std::vector<T> chatterino::LimitedQueue< T >::pushFront ( const std::vector< T > &  items)
inline

Push items into beginning of queue.

Items are inserted in reverse order. Items will only be inserted if they fit, meaning no elements can be deleted from using this function.

Parameters
itemsthe vector of items to push
Returns
vector of elements that were pushed
Here is the caller graph for this function:

◆ replaceItem() [1/2]

template<typename T>
template<typename Equals = std::equal_to<T>>
int chatterino::LimitedQueue< T >::replaceItem ( const T &  needle,
const T &  replacement 
)
inline

Replace the needle with the given item.

Parameters
[in]needlethe item to search for
[in]replacementthe item to replace needle with
Template Parameters
Equalityfunction object to use for comparison
Returns
the index of the replaced item, or -1 if no replacement took place
Here is the caller graph for this function:

◆ replaceItem() [2/2]

template<typename T>
bool chatterino::LimitedQueue< T >::replaceItem ( size_t  index,
const T &  replacement 
)
inline

Replace the item at index with the given item.

Parameters
[in]indexthe index of the item to replace
[in]replacementthe item to put in place of the item at index
Returns
true if a replacement took place

◆ rfind()

template<typename T>
template<typename Predicate >
boost::optional<T> chatterino::LimitedQueue< T >::rfind ( Predicate  pred) const
inline

Returns the first item matching a predicate, checking in reverse.

The contents of the LimitedQueue are iterated over from back to front until the first element that satisfies pred(item). If no item satisfies the predicate, or if the queue is empty, then boost::none is returned.

Parameters
[in]predpredicate that will be applied to items
Returns
the first item found or boost::none
Here is the caller graph for this function:

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