stack.hh 3.5 KB

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