• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* A Bison parser, made by GNU Bison 2.6.90.8-d4fe.  */
2 
3 /* Stack handling for Bison parsers in C++
4 
5       Copyright (C) 2002-2012 Free Software Foundation, Inc.
6 
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19 
20 /* As a special exception, you may create a larger work that contains
21    part or all of the Bison parser skeleton and distribute that work
22    under terms of your choice, so long as that work isn't itself a
23    parser generator using the skeleton or a modified version thereof
24    as a parser skeleton.  Alternatively, if you modify or redistribute
25    the parser skeleton itself, you may (at your option) remove this
26    special exception, which will cause the skeleton and the resulting
27    Bison output files to be licensed under the GNU General Public
28    License without this special exception.
29 
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32 
33 /**
34  ** \file ../../../../examples/calc++/stack.hh
35  ** Define the yy::stack class.
36  */
37 
38 #ifndef YY_YY_EXAMPLES_CALC_STACK_HH_INCLUDED
39 # define YY_YY_EXAMPLES_CALC_STACK_HH_INCLUDED
40 
41 # include <deque>
42 
43 
44 namespace yy {
45 /* Line 34 of stack.hh  */
46 #line 47 "../../../../examples/calc++/stack.hh"
47   template <class T, class S = std::deque<T> >
48   class stack
49   {
50   public:
51     // Hide our reversed order.
52     typedef typename S::reverse_iterator iterator;
53     typedef typename S::const_reverse_iterator const_iterator;
54 
stack()55     stack () : seq_ ()
56     {
57     }
58 
stack(unsigned int n)59     stack (unsigned int n) : seq_ (n)
60     {
61     }
62 
63     inline
64     T&
operator [](unsigned int i)65     operator [] (unsigned int i)
66     {
67       return seq_[i];
68     }
69 
70     inline
71     const T&
operator [](unsigned int i) const72     operator [] (unsigned int i) const
73     {
74       return seq_[i];
75     }
76 
77     inline
78     void
push(const T & t)79     push (const T& t)
80     {
81       seq_.push_front (t);
82     }
83 
84     inline
85     void
pop(unsigned int n=1)86     pop (unsigned int n = 1)
87     {
88       for (; n; --n)
89         seq_.pop_front ();
90     }
91 
92     inline
93     unsigned int
height() const94     height () const
95     {
96       return seq_.size ();
97     }
98 
begin() const99     inline const_iterator begin () const { return seq_.rbegin (); }
end() const100     inline const_iterator end () const { return seq_.rend (); }
101 
102   private:
103     S seq_;
104   };
105 
106   /// Present a slice of the top of a stack.
107   template <class T, class S = stack<T> >
108   class slice
109   {
110   public:
slice(const S & stack,unsigned int range)111     slice (const S& stack, unsigned int range)
112       : stack_ (stack)
113       , range_ (range)
114     {
115     }
116 
117     inline
118     const T&
operator [](unsigned int i) const119     operator [] (unsigned int i) const
120     {
121       return stack_[range_ - i];
122     }
123 
124   private:
125     const S& stack_;
126     unsigned int range_;
127   };
128 
129 } // yy
130 /* Line 116 of stack.hh  */
131 #line 132 "../../../../examples/calc++/stack.hh"
132 
133 #endif /* !YY_YY_EXAMPLES_CALC_STACK_HH_INCLUDED  */
134