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

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