home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP10-8.ZIP / CLASSSRC.ZIP / STACK.CPP < prev    next >
C/C++ Source or Header  |  1990-09-26  |  5KB  |  211 lines

  1. //
  2. // This file contains proprietary information of Borland International.
  3. // Copying or reproduction without prior written approval is prohibited.
  4. //
  5. // Copyright (c) 1990
  6. // Borland International
  7. // 1800 Scotts Valley Dr.
  8. // Scotts Valley, CA 95066
  9. // (408) 438-8400
  10. //
  11.  
  12. // Contents ----------------------------------------------------------------
  13. //
  14. //      Stack::push
  15. //      Stack::pop
  16. //      Stack::top
  17. //      Stack::initIterator
  18. //         Stack::hashValue
  19. //
  20. // Description
  21. //
  22. //      Implementation of class Stack member functions.
  23. //
  24. // End ---------------------------------------------------------------------
  25.  
  26. // Interface Dependencies ---------------------------------------------------
  27.  
  28. #ifndef __IOSTREAM_H
  29. #include <iostream.h>
  30. #define __IOSTREAM_H
  31. #endif
  32.  
  33. #ifndef __CLSTYPES_H
  34. #include <clstypes.h>
  35. #endif
  36.  
  37. #ifndef __OBJECT_H
  38. #include <object.h>
  39. #endif
  40.  
  41. #ifndef __CONTAIN_H
  42. #include <contain.h>
  43. #endif
  44.  
  45. #ifndef __STACK_H
  46. #include <stack.h>
  47. #endif
  48.  
  49. // End Interface Dependencies ------------------------------------------------
  50.  
  51. // Implementation Dependencies ----------------------------------------------
  52.  
  53. #ifndef __LIST_H
  54. #include <list.h>
  55. #endif
  56.  
  57. // End Implementation Dependencies -------------------------------------------
  58.  
  59.  
  60. // Member Function //
  61.  
  62. Stack::~Stack()
  63.  
  64. // Summary -----------------------------------------------------------------
  65. //
  66. //      Destructor for a Stack object.
  67. //
  68. //      We don't do anything here, because the destructor for theStack
  69. //      will destroy all the contained objects.
  70. //
  71. // End ---------------------------------------------------------------------
  72. {
  73. }
  74. // End Destructor //
  75.  
  76.  
  77. // Member Function //
  78.  
  79. void Stack::push( Object& toPush )
  80.  
  81. // Summary -----------------------------------------------------------------
  82. //
  83. //      Pushes the given object on the stack.
  84. //
  85. // Parameters
  86. //
  87. //      toPush
  88. //
  89. //      The object we are to push on the stack.  Once the object is
  90. //      pushed, it is owned by the stack.
  91. //
  92. // End ---------------------------------------------------------------------
  93. {
  94.     theStack.add( toPush );
  95. }
  96. // End Member Function Stack::push //
  97.  
  98.  
  99. // Member Function //
  100.  
  101. Object& Stack::pop()
  102.  
  103. // Summary -----------------------------------------------------------------
  104. //
  105. //      Pops an object from the stack.
  106. //
  107. // End ---------------------------------------------------------------------
  108. {
  109.     Object& temp = theStack.peekHead();
  110.     theStack.detach( temp );
  111.     return temp;
  112. }
  113. // End Member Function Stack::pop //
  114.  
  115.  
  116. // Member Function //
  117.  
  118. Object& Stack::top() const
  119.  
  120. // Summary -----------------------------------------------------------------
  121. //
  122. //      Peeks at the object on the top of the stack.
  123. //
  124. // End ---------------------------------------------------------------------
  125. {
  126.     return theStack.peekHead();
  127. }
  128. // End Member Function Stack::top //
  129.  
  130.  
  131. // Member Function //
  132.  
  133. int Stack::isEmpty() const
  134.  
  135. // Summary -----------------------------------------------------------------
  136. //
  137. //      Indicates whether the stack is empth
  138. //
  139. // End ---------------------------------------------------------------------
  140. {
  141.     return theStack.isEmpty();
  142. }
  143. // End Member Function Stack::isEmtpy //
  144.  
  145.  
  146. // Member Function //
  147.  
  148. ContainerIterator& Stack::initIterator() const
  149.  
  150. // Summary -----------------------------------------------------------------
  151. //
  152. //      Initializes an iterator for a stack.
  153. //
  154. // End ---------------------------------------------------------------------
  155. {
  156.     return *( (ContainerIterator *)new ListIterator( this->theStack ) );
  157. }
  158. // End Member Function Stack::initIterator //
  159.  
  160. // Member Function //
  161.  
  162. classType Stack::isA() const
  163.  
  164. // Summary -----------------------------------------------------------------
  165. //
  166. //      Returns a predefined value for the class Stack.
  167. //
  168. // Parameters
  169. //
  170. //      none
  171. //
  172. // End ---------------------------------------------------------------------
  173. {
  174.     return stackClass;
  175. }
  176. // End Member Function Stack::isA //
  177.  
  178. // Member Function //
  179.  
  180. char *Stack::nameOf() const
  181.  
  182. // Summary -----------------------------------------------------------------
  183. //
  184. //      Returns the string "Stack".
  185. //
  186. // Parameters
  187. //
  188. //      none
  189. //
  190. // End ---------------------------------------------------------------------
  191. {
  192.     return "Stack";
  193. }
  194. // End Member Function Stack::nameOf //
  195.  
  196.  
  197. // Member Function //
  198.  
  199. hashValueType Stack::hashValue() const
  200.  
  201. // Summary -----------------------------------------------------------------
  202. //
  203. //      Returns the hash value of a stack.
  204. //
  205. // End ---------------------------------------------------------------------
  206. {
  207.     return hashValueType(0);
  208. }
  209. // End Member Function Stack::hashValue //
  210.  
  211.