Source code of Windows XP (NT5)
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.

233 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. stack.hxx
  5. Abstract:
  6. This module contains the declaration for the concrete STACK class.
  7. STACK is derived from the ORDERED_CONTAINER class. It implements a
  8. standard FIFO stack data structure with the addition that it has a last
  9. position which can be queried. STACKs are dynamic in that they will
  10. grow rather than overflow.
  11. Author:
  12. David J. Gilman (davegi) 11-Dec-1990
  13. Environment:
  14. ULIB, User Mode
  15. --*/
  16. #if ! defined( _STACK_ )
  17. #define _STACK_
  18. #include "seqcnt.hxx"
  19. //
  20. // Forward references
  21. //
  22. DECLARE_CLASS( ARRAY );
  23. DECLARE_CLASS( ITERATOR );
  24. DECLARE_CLASS( STACK );
  25. //
  26. // Default values for an ARRAY object.
  27. //
  28. CONST ULONG DefaultCapacity = 50;
  29. CONST ULONG DefaultCapacityIncrement = 25;
  30. class STACK : public SEQUENTIAL_CONTAINER {
  31. public:
  32. DECLARE_CONSTRUCTOR( STACK );
  33. DECLARE_CAST_MEMBER_FUNCTION( STACK );
  34. NONVIRTUAL
  35. VOID
  36. Clear (
  37. );
  38. VIRTUAL
  39. PCOBJECT
  40. GetFirst (
  41. ) CONST PURE;
  42. VIRTUAL
  43. PCOBJECT
  44. GetLast (
  45. ) CONST PURE;
  46. NONVIRTUAL
  47. BOOLEAN
  48. Initialize (
  49. IN ULONG Capacity DEFAULT DefaultCapacity,
  50. IN ULONG CapacityIncrement DEFAULT DefaultCapacityIncrement
  51. );
  52. NONVIRTUAL
  53. PCOBJECT
  54. Pop (
  55. );
  56. NONVIRTUAL
  57. BOOLEAN
  58. Push (
  59. IN PCOBJECT Object
  60. );
  61. VIRTUAL
  62. PCOBJECT
  63. Put (
  64. IN PCOBJECT Member
  65. ) PURE;
  66. VIRTUAL
  67. PITERATOR
  68. QueryIterator (
  69. ) CONST PURE;
  70. VIRTUAL
  71. PCOBJECT
  72. Remove (
  73. IN PCOBJECT Member
  74. ) PURE;
  75. NONVIRTUAL
  76. PCOBJECT
  77. Top (
  78. ) CONST;
  79. private:
  80. PARRAY _Stack;
  81. ULONG _Top;
  82. };
  83. INLINE
  84. PCOBJECT
  85. STACK::GetFirst (
  86. ) CONST
  87. {
  88. return( Top( ));
  89. }
  90. INLINE
  91. PCOBJECT
  92. STACK::GetLast (
  93. ) CONST
  94. {
  95. DebugPtrAssert( _Stack );
  96. if( _Stack != NULL ) {
  97. return( _Stack->GetLast( ));
  98. } else {
  99. return( NULL );
  100. }
  101. }
  102. INLINE
  103. VOID
  104. STACK::Clear (
  105. )
  106. {
  107. _Top = 0;
  108. }
  109. INLINE
  110. PCOBJECT
  111. STACK::Pop (
  112. )
  113. {
  114. DebugPtrAssert( _Stack );
  115. if( ( _Stack != NULL ) && ( _Top != 0 )) {
  116. return( _Stack->GetAt( _Top-- ));
  117. } else {
  118. return( NULL );
  119. }
  120. }
  121. INLINE
  122. BOOLEAN
  123. STACK::Push (
  124. IN PCOBJECT Object
  125. )
  126. {
  127. DebugPtrAssert( _Stack );
  128. if( _Stack != NULL ) {
  129. return( _Stack->PutAt( ++_Top ));
  130. } else {
  131. return( NULL );
  132. }
  133. }
  134. INLINE
  135. PCOBJECT
  136. STACK::Put (
  137. IN PCOBJECT Member
  138. )
  139. {
  140. DebugPtrAssert( Member );
  141. return( Push( Member ));
  142. }
  143. INLINE
  144. PITERATOR
  145. STACK::QueryIterator (
  146. ) CONST
  147. {
  148. DebugPtrAssert( _Stack );
  149. if( _Stack != NULL ) {
  150. return( _Stack->QueryIterator( ));
  151. } else {
  152. return( NULL );
  153. }
  154. }
  155. INLINE
  156. PCOBJECT
  157. STACK::Remove (
  158. IN PCOBJECT Member
  159. ) PURE
  160. {
  161. DebugPtrAssert( Member ).IsEqual( Top( ));
  162. if( ( Member != NULL ) && Member.IsEqual( Top( )) ) {
  163. return( Pop( ));
  164. } else {
  165. retrun( NULL );
  166. }
  167. }
  168. INLINE
  169. PCOBJECT
  170. STACK::Top (
  171. ) CONST
  172. {
  173. DebugPtrAssert( _Stack );
  174. if( ( _Stack != NULL ) && ( _Top != 0 )) {
  175. return( _Stack->GetAt( _Top ));
  176. } else {
  177. return( NULL );
  178. }
  179. }
  180. #endif // _STACK_