Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef BISON_STACK_HH
00034 # define BISON_STACK_HH
00035
00036 #include <deque>
00037
00038
00039 namespace eltlyy {
00040
00041
00042 #line 43 "stack.hh"
00043 template <class T, class S = std::deque<T> >
00044 class stack
00045 {
00046 public:
00047
00048
00049 typedef typename S::reverse_iterator iterator;
00050 typedef typename S::const_reverse_iterator const_iterator;
00051
00052 stack () : seq_ ()
00053 {
00054 }
00055
00056 stack (unsigned int n) : seq_ (n)
00057 {
00058 }
00059
00060 inline
00061 T&
00062 operator [] (unsigned int i)
00063 {
00064 return seq_[i];
00065 }
00066
00067 inline
00068 const T&
00069 operator [] (unsigned int i) const
00070 {
00071 return seq_[i];
00072 }
00073
00074 inline
00075 void
00076 push (const T& t)
00077 {
00078 seq_.push_front (t);
00079 }
00080
00081 inline
00082 void
00083 pop (unsigned int n = 1)
00084 {
00085 for (; n; --n)
00086 seq_.pop_front ();
00087 }
00088
00089 inline
00090 unsigned int
00091 height () const
00092 {
00093 return seq_.size ();
00094 }
00095
00096 inline const_iterator begin () const { return seq_.rbegin (); }
00097 inline const_iterator end () const { return seq_.rend (); }
00098
00099 private:
00100
00101 S seq_;
00102 };
00103
00105 template <class T, class S = stack<T> >
00106 class slice
00107 {
00108 public:
00109
00110 slice (const S& stack,
00111 unsigned int range) : stack_ (stack),
00112 range_ (range)
00113 {
00114 }
00115
00116 inline
00117 const T&
00118 operator [] (unsigned int i) const
00119 {
00120 return stack_[range_ - i];
00121 }
00122
00123 private:
00124
00125 const S& stack_;
00126 unsigned int range_;
00127 };
00128
00129 }
00130
00131
00132 #line 133 "stack.hh"
00133
00134 #endif // not BISON_STACK_HH[]dnl
00135