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
16 * limited_stack - a stack of limited size
18 * Like a normal stack, but elements falling out
19 * of the bottom are destructed.
24 typedef std::list<T> container_type;
25 typedef typename container_type::value_type value_type;
26 typedef typename container_type::size_type size_type;
28 /// limit is the maximum size of the stack
29 limited_stack(size_type limit = 10) {
33 /// return the top element
38 /// pop and throw away the top element
43 /// return true if the stack is empty
45 return c_.size() == 0;
48 /// 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_) {
67 /// the maximum number elements stored
71 // make pointer type an error.
73 class limited_stack<T*>;
75 #endif // LIMITED_STACK_H