Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

stack.hh

Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 2.0.  */
00002 
00003 /* stack handling for Bison C++ parsers,
00004    Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2, or (at your option)
00009    any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.  */
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     // Hide our reversed order.
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

Please comment this page and report errors about it on the RefDocComments page.
Generated on Wed Mar 1 10:32:07 2006 for spot by doxygen 1.4.0