home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BCPPOWL1.ZIP / CLINC.ZIP / LIST.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  5.4 KB  |  257 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. // Contents ----------------------------------------------------------------
  4. //
  5. //      List
  6. //
  7. //         ListIterator
  8. //      ListIterator::ListIterator                  constructor
  9. //
  10. // Description
  11. //
  12. //      Defines the class List.  Lists are used to link other objects
  13. //     together.
  14. //     Defines the ListIterator class.  A list iterator visits each
  15. //     of the items in a list.
  16. //
  17. // End ---------------------------------------------------------------------
  18.  
  19. // Interface Dependencies ---------------------------------------------------
  20.  
  21. #ifndef __LIST_H
  22. #define __LIST_H
  23.  
  24. #ifndef __IOSTREAM_H
  25. #include <iostream.h>
  26. #define __IOSTREAM_H
  27. #endif
  28.  
  29. #ifndef __CLSTYPES_H
  30. #include <clstypes.h>
  31. #endif
  32.  
  33. #ifndef __OBJECT_H
  34. #include <object.h>
  35. #endif
  36.  
  37. #ifndef __LSTELEM_H
  38. #include <lstelem.h>
  39. #endif
  40.  
  41. #ifndef __COLLECT_H
  42. #include <collect.h>
  43. #endif
  44.  
  45. #ifndef __CONTAIN_H
  46. #include <contain.h>
  47. #endif
  48.  
  49. // End Interface Dependencies ------------------------------------------------
  50.  
  51. _CLASSDEF(List)
  52. _CLASSDEF(ListIterator)
  53.  
  54. // Class //
  55.  
  56. class _CLASSTYPE List:  public Collection
  57. {
  58. public:
  59.     List() { head = 0; }
  60.     virtual ~List();
  61.  
  62.     RObject  peekHead() const;
  63.  
  64.     void            add( RObject );
  65.     void            detach( RCObject, int = 0 );
  66.     void            destroy( RCObject l ) { detach( l, 1 ); }
  67.  
  68.     virtual classType       isA() const;
  69.     virtual Pchar nameOf() const;
  70.     virtual hashValueType   hashValue() const;
  71.  
  72.     virtual RContainerIterator initIterator() const;
  73.  
  74. private:
  75.     PListElement head;
  76.  
  77.     friend  class ListIterator;
  78. };
  79.  
  80. // Description -------------------------------------------------------------
  81. //
  82. //     Defines the container class List. 
  83. //
  84. //     List objects, i.e. objects instantiated of classes derived from
  85. //     List, are used in sequences where insertions and deletions
  86. //     are defined.  They operate soley on objects derived from
  87. //     class ListElement.
  88. //
  89. // Constructor
  90. //
  91. //     List
  92. //
  93. //     Constructor.
  94. //
  95. // Public Members
  96. //
  97. //      peekHead
  98. //
  99. //      Returns a reference to the object at the head of the list.
  100. //
  101. //      add
  102. //
  103. //      Adds an object to the list.
  104. //
  105. //      destroy
  106. //
  107. //      Detaches an object from the list and calls that object's destructor.
  108. //
  109. //      detach
  110. //
  111. //      Removes a reference to an object from the list.
  112. //
  113. //     hasMember
  114. //
  115. //     Determines whether the list has a given list element.
  116. //
  117. //     isA
  118. //
  119. //     Returns the class type of class list.
  120. //
  121. //     nameOf
  122. //
  123. //     Returns a pointer to the character string "List."
  124. //
  125. //     hashValue
  126. //
  127. //     Returns a pre-defined value for a list object.
  128. //
  129. // Inherited Members
  130. //      
  131. //     printOn
  132. //
  133. //     Inherited from Container.
  134. //
  135. //     isEmpty
  136. //
  137. //     Inherited from Container.
  138. //
  139. //     forEach
  140. //
  141. //     Inherited from Container.
  142. //
  143. //     firstThat
  144. //
  145. //     Inherited from Container.
  146. //
  147. //     lastThat
  148. //
  149. //     Inherited from Container.
  150. //
  151. //     isEqual
  152. //
  153. //     Inherited from Container.
  154. //
  155. //     isSortable
  156. //
  157. //     Inherited from Object.
  158. //
  159. //     isAssociation
  160. //
  161. //     Inherited from Object.
  162. //
  163. // Private Members
  164. //
  165. //     head
  166. //
  167. //     Maintains a pointer to the list element at the head of the list.
  168. //
  169. // End ---------------------------------------------------------------------
  170.  
  171.  
  172. // Class //
  173.  
  174. class _CLASSTYPE ListIterator:  public ContainerIterator
  175. {
  176. public:
  177.     ListIterator( RCList );
  178.     virtual ~ListIterator();
  179.  
  180.     virtual             operator int();
  181.     virtual             operator RObject();
  182.     virtual RObject     operator ++();
  183.     virtual void    restart();
  184.  
  185. private:
  186.     PListElement currentElement;
  187.     PListElement startingElement;
  188. };
  189.  
  190. // Description -------------------------------------------------------------
  191. //
  192. //         Defines the list iterator class.  Upon initialization, we set up
  193. //         an internal pointer to our current position in the list.  As
  194. //         the increment operator is called, we update this current position.
  195. //
  196. // Constructor
  197. //
  198. //      ListIterator( RCList )
  199. //
  200. //         Constructor for an iterator.  Note that this isn't a copy
  201. //         constructor, since it takes an object from a different class.
  202. //
  203. // Destructor
  204. //
  205. //         ~ListIterator
  206. //
  207. // Public Members
  208. //
  209. //         operator int
  210. //
  211. //         We are allowed one cast operator to a predefined type.  This
  212. //         operator defines an explicit or an implicit cast from a
  213. //         ListIterator to an integer.
  214. //
  215. //      operator RObject
  216. //
  217. //      Conversion to Object reference operator.
  218. //
  219. //         operator ++
  220. //
  221. //      The increment operator.
  222. //
  223. //         restart
  224. //
  225. //         List iterator restart mechanism.
  226. //
  227. // Private Members
  228. //
  229. //      currentElement
  230. //
  231. //         The current position in the iteration sequence.
  232. //
  233. //      startingElement
  234. //
  235. //         The starting position in the iteration sequence.
  236. //
  237. // End ---------------------------------------------------------------------
  238.  
  239.  
  240. // Constructor //
  241.  
  242. inline  ListIterator::ListIterator( RCList toIterate )
  243.  
  244. // Summary -----------------------------------------------------------------
  245. //
  246. //      Constructor for a list iterator object.
  247. //
  248. // End ---------------------------------------------------------------------
  249. {
  250.     startingElement = currentElement = toIterate.head;
  251. //    currentElement = toIterate.head;
  252. }
  253. // End Constructor ListIterator::ListIterator //
  254.  
  255.  
  256. #endif // ifndef __LIST_H //
  257.