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 
00034 
00035 #ifndef BISON_STACK_HH
00036 # define BISON_STACK_HH
00037 
00038 #include <deque>
00039 
00040 
00041 
00042 #line 1 "[Bison:b4_percent_define_default]"
00043 
00044 namespace example {
00045 
00046 
00047 #line 48 "stack.hh"
00048   template <class T, class S = std::deque<T> >
00049   class stack
00050   {
00051   public:
00052 
00053     
00054     typedef typename S::reverse_iterator iterator;
00055     typedef typename S::const_reverse_iterator const_iterator;
00056 
00057     stack () : seq_ ()
00058     {
00059     }
00060 
00061     stack (unsigned int n) : seq_ (n)
00062     {
00063     }
00064 
00065     inline
00066     T&
00067     operator [] (unsigned int i)
00068     {
00069       return seq_[i];
00070     }
00071 
00072     inline
00073     const T&
00074     operator [] (unsigned int i) const
00075     {
00076       return seq_[i];
00077     }
00078 
00079     inline
00080     void
00081     push (const T& t)
00082     {
00083       seq_.push_front (t);
00084     }
00085 
00086     inline
00087     void
00088     pop (unsigned int n = 1)
00089     {
00090       for (; n; --n)
00091         seq_.pop_front ();
00092     }
00093 
00094     inline
00095     unsigned int
00096     height () const
00097     {
00098       return seq_.size ();
00099     }
00100 
00101     inline const_iterator begin () const { return seq_.rbegin (); }
00102     inline const_iterator end () const { return seq_.rend (); }
00103 
00104   private:
00105 
00106     S seq_;
00107   };
00108 
00110   template <class T, class S = stack<T> >
00111   class slice
00112   {
00113   public:
00114 
00115     slice (const S& stack,
00116            unsigned int range) : stack_ (stack),
00117                                  range_ (range)
00118     {
00119     }
00120 
00121     inline
00122     const T&
00123     operator [] (unsigned int i) const
00124     {
00125       return stack_[range_ - i];
00126     }
00127 
00128   private:
00129 
00130     const S& stack_;
00131     unsigned int range_;
00132   };
00133 
00134 
00135 #line 1 "[Bison:b4_percent_define_default]"
00136 
00137 } 
00138 
00139 
00140 #line 141 "stack.hh"
00141 
00142 #endif // not BISON_STACK_HH[]dnl
00143