3 * \file limited_stack.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef LIMITED_STACK_H
13 #define LIMITED_STACK_H
21 * limited_stack - A stack of limited size.
23 * Like a normal stack, but elements falling out
24 * of the bottom are destructed.
29 typedef std::deque<T> container_type;
30 typedef typename container_type::value_type value_type;
31 typedef typename container_type::size_type size_type;
32 typedef typename container_type::const_iterator const_iterator;
34 /// limit is the maximum size of the stack
35 limited_stack(size_type limit = 100) : limit_(limit) {}
37 /// Return the top element.
42 /// Pop and throw away the top element.
47 /// Return true if the stack is empty.
52 /// Clear all elements, deleting them.
57 /// Push an item on to the stack, deleting the
58 /// bottom item on overflow.
59 void push(value_type const & v) {
61 if (c_.size() > limit_) {
66 /// Direct read access to intermediate elements.
67 T const & operator[](size_type pos) const {
71 /// Read access to used size.
72 size_type size() const {
76 const_iterator begin() const {
80 const_iterator end() const {
85 /// Internal contents.
87 /// The maximum number elements stored.
91 // Make pointer type an error.
93 class limited_stack<T*>;
98 #endif // LIMITED_STACK_H