stack.hh 3.5 KB

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