home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 11.ddi / CLASSSRC.ZIP / DEQUE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  4.4 KB  |  183 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. // Contents ----------------------------------------------------------------
  4. //
  5. //      Deque::isA
  6. //      Deque::nameOf
  7. //      Deque::getLeft
  8. //      Deque::getRight
  9. //      Deque::initIterator
  10. //      Deque::initReverseIterator
  11. //      Deque::hashValue
  12. //
  13. // Description
  14. //
  15. //      Implementation of class Deque member functions.
  16. //
  17. // End ---------------------------------------------------------------------
  18.  
  19. // Interface Dependencies ---------------------------------------------------
  20.  
  21. #ifndef __IOSTREAM_H
  22. #include <iostream.h>
  23. #define __IOSTREAM_H
  24. #endif
  25.  
  26. #ifndef __CLSTYPES_H
  27. #include <clstypes.h>
  28. #endif
  29.  
  30. #ifndef __OBJECT_H
  31. #include <object.h>
  32. #endif
  33.  
  34. #ifndef __DEQUE_H
  35. #include <deque.h>
  36. #endif
  37.  
  38. // End Interface Dependencies ------------------------------------------------
  39.  
  40. // Implementation Dependencies ----------------------------------------------
  41.  
  42. #ifndef __DBLLIST_H
  43. #include <dbllist.h>
  44. #endif
  45.  
  46. // End Implementation Dependencies -------------------------------------------
  47.  
  48.  
  49. // Member Function //
  50.  
  51. Deque::~Deque()
  52.  
  53. // Summary -----------------------------------------------------------------
  54. //
  55. //      Destructor for a Deque object.
  56. //
  57. //        We don't do anything here, because the destructor for theDeque
  58. //        will destroy all the objects in the Deque.
  59. //
  60. // End ---------------------------------------------------------------------
  61. {
  62. }
  63. // End Destructor //
  64.  
  65.  
  66. // Member Function //
  67.  
  68. classType Deque::isA() const
  69.  
  70. // Summary -----------------------------------------------------------------
  71. //
  72. //         Returns the class type of a double-ended queue.
  73. //
  74. // End ---------------------------------------------------------------------
  75. {
  76.     return dequeClass; 
  77. }
  78. // End Member Function Deque::isA //
  79.  
  80.  
  81. // Member Function //
  82.  
  83. char *Deque::nameOf() const
  84.  
  85. // Summary -----------------------------------------------------------------
  86. //
  87. //         Returns a pointer to the character string "Deque."
  88. //
  89. // End ---------------------------------------------------------------------
  90. {
  91.     return "Deque";
  92. }
  93. // End Member Function Deque::nameOf //
  94.  
  95.  
  96. // Member Function //
  97.  
  98. Object& Deque::getLeft()
  99.  
  100. // Summary -----------------------------------------------------------------
  101. //
  102. //      Gets an object from the left end of the deque.  The object becomes 
  103. //      the ownership of the receiver.
  104. //
  105. // End ---------------------------------------------------------------------
  106. {
  107.     Object& temp = theDeque.peekAtHead();
  108.     if( temp != NOOBJECT )
  109.         {
  110.         theDeque.detachFromHead( temp );
  111.         itemsInContainer--;
  112.         }
  113.     return temp;
  114. }
  115. // End Member Function Deque::getLeft //
  116.  
  117.  
  118. // Member Function //
  119.  
  120. Object& Deque::getRight()
  121.  
  122. // Summary -----------------------------------------------------------------
  123. //
  124. //      Gets an object from the right end of the deque.  The object becomes 
  125. //      the ownership of the receiver.
  126. //
  127. // End ---------------------------------------------------------------------
  128. {
  129.     Object& temp = theDeque.peekAtTail();
  130.     if( temp != NOOBJECT )
  131.         {
  132.         theDeque.detachFromTail( temp );
  133.         itemsInContainer--;
  134.         }
  135.     return temp;
  136. }
  137. // End Member Function Deque::getLeft //
  138.  
  139.  
  140. // Member Function //
  141.  
  142. ContainerIterator& Deque::initIterator() const
  143.  
  144. // Summary -----------------------------------------------------------------
  145. //
  146. //      Initializes an iterator for a deque.
  147. //
  148. // End ---------------------------------------------------------------------
  149. {
  150.     return *( (ContainerIterator *)new DoubleListIterator( this->theDeque ) );
  151. }
  152. // End Member Function Deque::initIterator //
  153.  
  154.  
  155. // Member Function //
  156.  
  157. ContainerIterator& Deque::initReverseIterator() const
  158.  
  159. // Summary -----------------------------------------------------------------
  160. //
  161. //      Initializes a right to left iterator for a deque.
  162. //
  163. // End ---------------------------------------------------------------------
  164. {
  165.     return *((ContainerIterator *)new DoubleListIterator( this->theDeque, 0 ));
  166. }
  167. // End Member Function Deque::initReverseIterator //
  168.  
  169.  
  170. // Member Function //
  171.  
  172. hashValueType Deque::hashValue() const
  173.  
  174. // Summary -----------------------------------------------------------------
  175. //
  176. //      Returns the hash value of a deque.
  177. //
  178. // End ---------------------------------------------------------------------
  179. {
  180.     return hashValueType(0);
  181. }
  182. // End Member Function Deque::hashValue //
  183.