19 #ifndef LIB_QUENTIER_UTILITY_LIMITED_STACK_H 20 #define LIB_QUENTIER_UTILITY_LIMITED_STACK_H 22 #include <quentier/utility/Macros.h> 36 LimitedStack(
void (*deleter)(T&) = Q_NULLPTR) : m_limit(-1), m_deleter(deleter) {}
38 LimitedStack(
LimitedStack<T> && other) : QStack<T>(std::move(other)), m_limit(std::move(other.m_limit)), m_deleter(std::move(other.m_deleter)) {}
43 QStack<T>::operator=(other);
44 m_limit = other.m_limit;
45 m_deleter = other.m_deleter;
54 QStack<T>::operator=(std::move(other));
55 m_limit = std::move(other.m_limit);
56 m_deleter = std::move(other.m_deleter);
66 while (!QStack<T>::isEmpty()) {
67 T t = QStack<T>::pop();
75 int limit = other.m_limit;
76 other.m_limit = m_limit;
79 void (*deleter)(T &) = other.m_deleter;
80 other.m_deleter = m_deleter;
83 QStack<T>::swap(other);
86 int limit()
const {
return m_limit; }
87 void setLimit(
const int limit) { m_limit = limit; }
89 void push(
const T & t)
91 if ((m_limit > 0) && (QVector<T>::size() == m_limit - 1)) {
93 (*m_deleter)(*QVector<T>::begin());
95 Q_UNUSED(QVector<T>::erase(QVector<T>::begin()));
103 void (*m_deleter)(T &);
108 #endif // LIB_QUENTIER_UTILITY_LIMITED_STACK_H The LimitedStack template class implements a stack which may have a limitation for its size; when the...
Definition: LimitedStack.h:33