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) {
39 /// Return the top element.
44 /// Pop and throw away the top element.
49 /// Return true if the stack is empty.
54 /// Clear all elements, deleting them.
59 /// Push an item on to the stack, deleting the
60 /// bottom item on overflow.
61 void push(value_type const & v) {
63 if (c_.size() > limit_) {
68 /// Direct read access to intermediate elements.
69 T const & operator[](size_type pos) const {
73 /// Read access to used size.
74 size_type size() const {
78 const_iterator begin() const {
82 const_iterator end() const {
87 /// Internal contents.
89 /// The maximum number elements stored.
93 // Make pointer type an error.
95 class limited_stack<T*>;
100 #endif // LIMITED_STACK_H