3 * \file limited_stack.h
4 * Copyright 2002 the LyX Team
5 * Read the file COPYING
7 * \author John Levon <moz@compsoc.man.ac.uk>
10 #ifndef LIMITED_STACK_H
11 #define LIMITED_STACK_H
15 #include <boost/shared_ptr.hpp>
18 * limited_stack - a stack of limited size
20 * Like a normal stack, but only accepts pointer types,
21 * and bottom elements are deleted on overflow
26 typedef std::list<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 = 10) {
35 /// return the top element
40 /// pop and throw away the top element
45 /// return true if the stack is empty
47 return c_.size() == 0;
50 /// 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_) {
69 /// the maximum number elements stored
73 // make pointer type an error.
75 class limited_stack<T*>;
77 #endif // LIMITED_STACK_H