src/stack.hh

Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 2.3.  */
00002 
00003 /* Stack handling for Bison parsers in C++
00004 
00005    Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.  */
00021 
00022 /* As a special exception, you may create a larger work that contains
00023    part or all of the Bison parser skeleton and distribute that work
00024    under terms of your choice, so long as that work isn't itself a
00025    parser generator using the skeleton or a modified version thereof
00026    as a parser skeleton.  Alternatively, if you modify or redistribute
00027    the parser skeleton itself, you may (at your option) remove this
00028    special exception, which will cause the skeleton and the resulting
00029    Bison output files to be licensed under the GNU General Public
00030    License without this special exception.
00031 
00032    This special exception was added by the Free Software Foundation in
00033    version 2.2 of Bison.  */
00034 
00035 #ifndef BISON_STACK_HH
00036 # define BISON_STACK_HH
00037 
00038 #include <deque>
00039 
00040 namespace example {
00041 
00042 template <class T, class S = std::deque<T> >
00043 class stack
00044 {
00045 public:
00046 
00047     // Hide our reversed order.
00048     typedef typename S::reverse_iterator iterator;
00049     typedef typename S::const_reverse_iterator const_iterator;
00050 
00051     stack () : seq_ ()
00052     {
00053     }
00054 
00055     stack (unsigned int n) : seq_ (n)
00056     {
00057     }
00058 
00059     inline
00060     T&
00061     operator [] (unsigned int i)
00062     {
00063         return seq_[i];
00064     }
00065 
00066     inline
00067     const T&
00068     operator [] (unsigned int i) const
00069     {
00070         return seq_[i];
00071     }
00072 
00073     inline
00074     void
00075     push (const T& t)
00076     {
00077         seq_.push_front (t);
00078     }
00079 
00080     inline
00081     void
00082     pop (unsigned int n = 1)
00083     {
00084         for (; n; --n)
00085             seq_.pop_front ();
00086     }
00087 
00088     inline
00089     unsigned int
00090     height () const
00091     {
00092         return seq_.size ();
00093     }
00094 
00095     inline const_iterator begin () const { return seq_.rbegin (); }
00096     inline const_iterator end () const { return seq_.rend (); }
00097 
00098 private:
00099 
00100     S seq_;
00101 };
00102 
00104 template <class T, class S = stack<T> >
00105 class slice
00106 {
00107 public:
00108 
00109     slice (const S& stack,
00110            unsigned int range) : stack_ (stack),
00111                                  range_ (range)
00112     {
00113     }
00114 
00115     inline
00116     const T&
00117     operator [] (unsigned int i) const
00118     {
00119         return stack_[range_ - i];
00120     }
00121 
00122 private:
00123 
00124     const S& stack_;
00125     unsigned int range_;
00126 };
00127 
00128 }
00129 
00130 #endif // not BISON_STACK_HH

Generated on Mon Aug 20 13:34:21 2007 for Flex Bison C++ Example by  doxygen 1.5.2