Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
3.6 KiB

  1. // stack standard header
  2. #pragma once
  3. #ifndef _STACK_
  4. #define _STACK_
  5. #include <deque>
  6. #pragma pack(push,8)
  7. #pragma warning(push,3)
  8. _STD_BEGIN
  9. // TEMPLATE CLASS stack
  10. template<class _Ty,
  11. class _Container = deque<_Ty> >
  12. class stack
  13. { // LIFO queue implemented with a container
  14. public:
  15. typedef _Container container_type;
  16. typedef typename _Container::value_type value_type;
  17. typedef typename _Container::size_type size_type;
  18. stack()
  19. : c()
  20. { // construct with empty container
  21. }
  22. explicit stack(const _Container& _Cont)
  23. : c(_Cont)
  24. { // construct by copying specified container
  25. }
  26. bool empty() const
  27. { // test if stack is empty
  28. return (c.empty());
  29. }
  30. size_type size() const
  31. { // test length of stack
  32. return (c.size());
  33. }
  34. value_type& top()
  35. { // return last element of mutable stack
  36. return (c.back());
  37. }
  38. const value_type& top() const
  39. { // return last element of nonmutable stack
  40. return (c.back());
  41. }
  42. void push(const value_type& _Val)
  43. { // insert element at end
  44. c.push_back(_Val);
  45. }
  46. void pop()
  47. { // erase last element
  48. c.pop_back();
  49. }
  50. bool _Eq(const stack<_Ty, _Container>& _Right) const
  51. { // test for stack equality
  52. return (c == _Right.c);
  53. }
  54. bool _Lt(const stack<_Ty, _Container>& _Right) const
  55. { // test if this < _Right for stacks
  56. return (c < _Right.c);
  57. }
  58. protected:
  59. _Container c; // the underlying container
  60. };
  61. // stack TEMPLATE FUNCTIONS
  62. template<class _Ty,
  63. class _Container> inline
  64. bool operator==(const stack<_Ty, _Container>& _Left,
  65. const stack<_Ty, _Container>& _Right)
  66. { // test for stack equality
  67. return (_Left._Eq(_Right));
  68. }
  69. template<class _Ty,
  70. class _Container> inline
  71. bool operator!=(const stack<_Ty, _Container>& _Left,
  72. const stack<_Ty, _Container>& _Right)
  73. { // test for stack inequality
  74. return (!(_Left == _Right));
  75. }
  76. template<class _Ty,
  77. class _Container> inline
  78. bool operator<(const stack<_Ty, _Container>& _Left,
  79. const stack<_Ty, _Container>& _Right)
  80. { // test if _Left < _Right for stacks
  81. return (_Left._Lt(_Right));
  82. }
  83. template<class _Ty,
  84. class _Container> inline
  85. bool operator>(const stack<_Ty, _Container>& _Left,
  86. const stack<_Ty, _Container>& _Right)
  87. { // test if _Left > _Right for stacks
  88. return (_Right < _Left);
  89. }
  90. template<class _Ty,
  91. class _Container> inline
  92. bool operator<=(const stack<_Ty, _Container>& _Left,
  93. const stack<_Ty, _Container>& _Right)
  94. { // test if _Left <= _Right for stacks
  95. return (!(_Right < _Left));
  96. }
  97. template<class _Ty,
  98. class _Container> inline
  99. bool operator>=(const stack<_Ty, _Container>& _Left,
  100. const stack<_Ty, _Container>& _Right)
  101. { // test if _Left >= _Right for stacks
  102. return (!(_Left < _Right));
  103. }
  104. _STD_END
  105. #pragma warning(pop)
  106. #pragma pack(pop)
  107. #endif /* _STACK_ */
  108. /*
  109. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  110. * Consult your license regarding permissions and restrictions.
  111. */
  112. /*
  113. * This file is derived from software bearing the following
  114. * restrictions:
  115. *
  116. * Copyright (c) 1994
  117. * Hewlett-Packard Company
  118. *
  119. * Permission to use, copy, modify, distribute and sell this
  120. * software and its documentation for any purpose is hereby
  121. * granted without fee, provided that the above copyright notice
  122. * appear in all copies and that both that copyright notice and
  123. * this permission notice appear in supporting documentation.
  124. * Hewlett-Packard Company makes no representations about the
  125. * suitability of this software for any purpose. It is provided
  126. * "as is" without express or implied warranty.
  127. V3.10:0009 */