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

stack.hh

Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 1.875d.  */
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     typedef typename S::iterator Iterator;
00034     typedef typename S::const_iterator ConstIterator;
00035 
00036     Stack () : seq_ ()
00037     {
00038     }
00039 
00040     Stack (unsigned int n) : seq_ (n)
00041     {
00042     }
00043 
00044     inline
00045     T&
00046     operator [] (unsigned int i)
00047     {
00048       return seq_[i];
00049     }
00050 
00051     inline
00052     const T&
00053     operator [] (unsigned int 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 int n = 1)
00068     {
00069       for (; n; --n)
00070         seq_.pop_front ();
00071     }
00072 
00073     inline
00074     unsigned int
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 int range) : stack_ (stack),
00095                                  range_ (range)
00096     {
00097     }
00098 
00099     inline
00100     const T&
00101     operator [] (unsigned int i) const
00102     {
00103       return stack_[range_ - i];
00104     }
00105 
00106   private:
00107 
00108     const S& stack_;
00109     unsigned int range_;
00110   };
00111 }
00112 
00113 #endif // not BISON_STACK_HH

Please comment this page and report errors about it on the RefDocComments page.
Generated on Mon Jan 31 12:54:24 2005 for spot by doxygen 1.4.0