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
18 * limited_stack - A stack of limited size.
20 * Like a normal stack, but elements falling out
21 * of the bottom are destructed.
26 typedef std::deque<T> container_type;
27 typedef typename container_type::value_type value_type;
28 typedef typename container_type::size_type size_type;
29 typedef typename container_type::const_iterator const_iterator;
31 /// limit is the maximum size of the stack
32 limited_stack(size_type limit = 100) {
36 /// Return the top element.
41 /// Pop and throw away the top element.
46 /// Return true if the stack is empty.
51 /// Clear all elements, deleting them.
56 /// Push an item on to the stack, deleting the
57 /// bottom item on overflow.
58 void push(value_type const & v) {
60 if (c_.size() > limit_) {
65 /// Direct read access to intermediate elements.
66 T const & operator[](size_type pos) const {
70 /// Read access to used size.
71 size_type size() const {
75 const_iterator begin() const {
79 const_iterator end() const {
84 /// Internal contents.
86 /// The maximum number elements stored.
90 // Make pointer type an error.
92 class limited_stack<T*>;
94 #endif // LIMITED_STACK_H