00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#ifndef BISON_STACK_HH
00022
# define BISON_STACK_HH
00023
00024
#include <deque>
00025
00026
namespace yy
00027 {
00028
template <
class T,
class S = std::deque< T > >
00029 class Stack
00030 {
00031
public:
00032
00033 typedef typename S::iterator
Iterator;
00034 typedef typename S::const_iterator
ConstIterator;
00035
00036 Stack () :
seq_ ()
00037 {
00038 }
00039
00040 Stack (
unsigned n) :
seq_ (n)
00041 {
00042 }
00043
00044
inline
00045 T&
00046 operator [] (
unsigned i)
00047 {
00048
return seq_[i];
00049 }
00050
00051
inline
00052
const T&
00053 operator [] (
unsigned i)
const
00054
{
00055
return seq_[i];
00056 }
00057
00058
inline
00059
void
00060 push (
const T& t)
00061 {
00062
seq_.push_front (t);
00063 }
00064
00065
inline
00066
void
00067 pop (
unsigned n = 1)
00068 {
00069
for (; n; --n)
00070
seq_.pop_front ();
00071 }
00072
00073
inline
00074
unsigned
00075 height ()
const
00076
{
00077
return seq_.size ();
00078 }
00079
00080 inline ConstIterator begin ()
const {
return seq_.begin (); }
00081 inline ConstIterator end ()
const {
return seq_.end (); }
00082
00083
private:
00084
00085 S
seq_;
00086 };
00087
00088
template <
class T,
class S = Stack< T > >
00089 class Slice
00090 {
00091
public:
00092
00093 Slice (
const S& stack,
00094
unsigned range) :
stack_ (stack),
00095
range_ (range)
00096 {
00097 }
00098
00099
inline
00100
const T&
00101 operator [] (
unsigned i)
const
00102
{
00103
return stack_[
range_ - i];
00104 }
00105
00106
private:
00107
00108 const S&
stack_;
00109 unsigned range_;
00110 };
00111 }
00112
00113
#endif // not BISON_STACK_HH