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;
30 /// limit is the maximum size of the stack
31 limited_stack(size_type limit = 100) {
35 /// Return the top element.
40 /// Pop and throw away the top element.
45 /// Return true if the stack is empty.
50 /// Clear all elements, deleting them.
55 /// Push an item on to the stack, deleting the
56 /// bottom item on overflow.
57 void push(value_type const & v) {
59 if (c_.size() > limit_) {
64 /// Direct read access to intermediate elements.
65 T const & operator[](size_type pos) const {
69 /// Read access to used size.
70 size_type size() const {
74 /// Internal contents.
76 /// The maximum number elements stored.
80 // Make pointer type an error.
82 class limited_stack<T*>;
84 #endif // LIMITED_STACK_H