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
00034 typedef typename S::reverse_iterator iterator;
00035 typedef typename S::const_reverse_iterator const_iterator;
00036
00037 stack () : seq_ ()
00038 {
00039 }
00040
00041 stack (unsigned int n) : seq_ (n)
00042 {
00043 }
00044
00045 inline
00046 T&
00047 operator [] (unsigned int i)
00048 {
00049 return seq_[i];
00050 }
00051
00052 inline
00053 const T&
00054 operator [] (unsigned int i) const
00055 {
00056 return seq_[i];
00057 }
00058
00059 inline
00060 void
00061 push (const T& t)
00062 {
00063 seq_.push_front (t);
00064 }
00065
00066 inline
00067 void
00068 pop (unsigned int n = 1)
00069 {
00070 for (; n; --n)
00071 seq_.pop_front ();
00072 }
00073
00074 inline
00075 unsigned int
00076 height () const
00077 {
00078 return seq_.size ();
00079 }
00080
00081 inline const_iterator begin () const { return seq_.rbegin (); }
00082 inline const_iterator end () const { return seq_.rend (); }
00083
00084 private:
00085
00086 S seq_;
00087 };
00088
00090 template <class T, class S = stack<T> >
00091 class slice
00092 {
00093 public:
00094
00095 slice (const S& stack,
00096 unsigned int range) : stack_ (stack),
00097 range_ (range)
00098 {
00099 }
00100
00101 inline
00102 const T&
00103 operator [] (unsigned int i) const
00104 {
00105 return stack_[range_ - i];
00106 }
00107
00108 private:
00109
00110 const S& stack_;
00111 unsigned int range_;
00112 };
00113 }
00114
00115 #endif // not BISON_STACK_HH