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 / DBLLIST.H < prev    next >
C/C++ Source or Header  |  1990-09-26  |  9KB  |  379 lines

  1. #ifndef __DBLLIST_H
  2. #define __DBLLIST_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. //      DoubleList
  18. //      DoubleList::destroyFromHead
  19. //      DoubleList::destroyFromTail
  20. //
  21. //      DoubleListIterator
  22. //      DoubleListIterator::DoubleListIterator          constructor
  23. //
  24. // Description
  25. //
  26. //      Defines the class DoubleList.
  27. //      Defines the class DoubleListIterator.  A list iterator visits each
  28. //      of the items in a list.
  29. //
  30. // End ---------------------------------------------------------------------
  31.  
  32. // Interface Dependencies ---------------------------------------------------
  33.  
  34. #ifndef __IOSTREAM_H
  35. #include <iostream.h>
  36. #define __IOSTREAM_H
  37. #endif
  38.  
  39. #ifndef __CLSTYPES_H
  40. #include <clstypes.h>
  41. #endif
  42.  
  43. #ifndef __OBJECT_H
  44. #include <object.h>
  45. #endif
  46.  
  47. #ifndef __DLSTELEM_H
  48. #include <dlstelem.h>
  49. #endif
  50.  
  51. #ifndef __COLLECT_H
  52. #include <collect.h>
  53. #endif
  54.  
  55. // End Interface Dependencies ------------------------------------------------
  56.  
  57.  
  58. // Class //
  59.  
  60. class DoubleList:  public Collection
  61. {
  62. public:
  63.             DoubleList() { head = tail = 0; }
  64.     virtual ~DoubleList();
  65.  
  66.             Object&         peekAtHead() const { return *(head->data); }
  67.             Object&         peekAtTail() const { return *(tail->data); }
  68.             
  69.     virtual void            add( Object& );
  70.     virtual void            detach( const Object&, int = 0 );
  71.             void            addAtHead( Object& );
  72.             void            addAtTail( Object& );
  73.             void            destroyFromHead( const Object& );
  74.             void            destroyFromTail( const Object& );
  75.             void            detachFromHead( const Object&, int = 0 );
  76.             void            detachFromTail( const Object&, int = 0 );
  77.  
  78.     virtual ContainerIterator& initIterator() const;
  79.             ContainerIterator& initReverseIterator() const;
  80.  
  81.     virtual classType       isA() const;
  82.     virtual char           *nameOf() const;
  83.     virtual hashValueType   hashValue() const;
  84.  
  85. private:
  86.             DoubleListElement    *head;
  87.             DoubleListElement    *tail;
  88.     friend  class DoubleListIterator;
  89. };
  90.  
  91. // Description -------------------------------------------------------------
  92. //
  93. //      Defines the container class DoubleList. 
  94. //
  95. // Constructor
  96. //
  97. //      DoubleList
  98. //
  99. //      Default constructor
  100. //
  101. // Destructor
  102. //
  103. //      ~DoubleList
  104. //
  105. // Public Members
  106. //
  107. //      peekAtHead
  108. //
  109. //      Returns a reference to the object at the head of the list.
  110. //
  111. //      peekAtTail
  112. //
  113. //      Returns a reference to the object at the tail of the list.
  114. //
  115. //      add
  116. //
  117. //      Adds an element to the list.  By default, the element is
  118. //      added to the head of the list.
  119. //
  120. //      addAtHead
  121. //
  122. //      Adds an element at the head of the list.
  123. //
  124. //      addAtTail
  125. //
  126. //      Adds an element to the tail of the list.
  127. //
  128. //      destroyFromHead
  129. //
  130. //      Destroys the given element, searching forward from the head of the
  131. //      list.
  132. //
  133. //      destroyFromTail
  134. //
  135. //      Destroys the given element, searching forward from the head of the
  136. //      list.
  137. //
  138. //      detach
  139. //
  140. //      Detaches the given element.  By default, the element is searched
  141. //      for from the head of the list.
  142. //
  143. //      detachFromHead
  144. //
  145. //      Detachs the given element, searching forward from the head of the
  146. //      list.
  147. //
  148. //      detachFromTail
  149. //
  150. //      Detachs the given element, searching forward from the head of the
  151. //      list.
  152. //
  153. //      isA
  154. //
  155. //      Returns the class type of class DoubleList.
  156. //
  157. //      nameOf
  158. //
  159. //      Returns a pointer to the character string "DoubleList."
  160. //     
  161. //      hashValue
  162. //
  163. //      Inherited from Object.
  164. //
  165. //      initIterator
  166. //
  167. //      Initializes a double list iterator for a forward traversal of the
  168. //      list.
  169. //
  170. //      initReverseIterator
  171. //
  172. //      Initializes a double list iterator for a reverse traversal of the list.
  173. //
  174. // Inherited Members
  175. //
  176. //      printOn
  177. //
  178. //      Inherited from Container.
  179. //
  180. //      isEqual
  181. //
  182. //      Inherited from Container.
  183. //
  184. //      forEach
  185. //
  186. //      Inherited from Container.
  187. //
  188. //      firstThat
  189. //
  190. //      Inherited from Container.
  191. //
  192. //      lastThat
  193. //
  194. //      Inherited from Container.
  195. //
  196. //      isSortable
  197. //
  198. //      Inherited from Object.
  199. //
  200. //      isAssociation
  201. //
  202. //      Inherited from Object.
  203. //
  204. // End ---------------------------------------------------------------------
  205.  
  206.  
  207. // Member Function //
  208.  
  209. inline void DoubleList::destroyFromHead( const Object& toDestroy )
  210.  
  211. // Summary -----------------------------------------------------------------
  212. //
  213. //      Destroys an object from the head of a double list.  We remove
  214. //      the object from the list and call that object's destructor.
  215. //
  216. // Parameter
  217. //
  218. //      toDestroy
  219. //
  220. //      The object we are to search for and destroy from the DoubleList.
  221. //
  222. // Functional Description                     
  223. //
  224. //      Inline wrap of detach which deleteObjectToo parameter set to 1.
  225. //
  226. // Remarks
  227. //
  228. //  warnings:
  229. //      No error condition is generated if the object which was specified
  230. //      isn't on the double list.
  231. //
  232. // End ---------------------------------------------------------------------
  233. {
  234.     detachFromHead( toDestroy, 1 );
  235. }
  236. // End Member Function DoubleList::destroyFromHead //
  237.  
  238.  
  239. // Member Function //
  240.  
  241. inline void DoubleList::destroyFromTail( const Object& toDestroy )
  242.  
  243. // Summary -----------------------------------------------------------------
  244. //
  245. //      Destroys an object from the tail of a double list.  We remove
  246. //      the object from the list and call that object's destructor.
  247. //
  248. // Parameter
  249. //
  250. //      toDestroy
  251. //
  252. //      The object we are to search for and destroy from the DoubleList.
  253. //
  254. // Functional Description                     
  255. //
  256. //      Inline wrap of detach which deleteObjectToo parameter set to 1.
  257. //
  258. // Remarks
  259. //
  260. //  warnings:
  261. //      No error condition is generated if the object which was specified
  262. //      isn't on the double list.
  263. //
  264. // End ---------------------------------------------------------------------
  265. {
  266.     detachFromTail( toDestroy, 1 );
  267. }
  268. // End Member Function DoubleList::destroyFromTail //
  269.  
  270.  
  271. // Class //
  272.  
  273. class DoubleListIterator:  public ContainerIterator
  274. {
  275. public:
  276.             DoubleListIterator( const DoubleList&, int = 1 );
  277.     virtual ~DoubleListIterator();
  278.  
  279.     virtual                 operator int();
  280.     virtual                 operator Object&();
  281.     virtual Object&         operator ++();
  282.             Object&         operator --();
  283.     virtual void            restart();
  284.  
  285. private:
  286.             DoubleListElement *currentElement;
  287.             DoubleListElement *startingElement;
  288. };
  289.  
  290. // Description -------------------------------------------------------------
  291. //
  292. //      Defines the double list iterator class.  Upon initialization, we 
  293. //      set up an internal pointer to our current position in the list.  When
  294. //      an increment or decrement operator is called, we update this 
  295. //      current position.
  296. //
  297. // Constructor
  298. //
  299. //      DoubleListIterator( const DoubleList&, int = 1 )
  300. //
  301. //      Constructor for an iterator.  Note that this isn't a copy
  302. //      constructor, since it takes an object from a different class.
  303. //
  304. // Destructor
  305. //
  306. //      ~DoubleListIterator
  307. //
  308. // Public Members
  309. //
  310. //      operator int
  311. //
  312. //      We are allowed one cast operator to a predefined type.  This
  313. //      operator defines an explicit or an implicit cast from a
  314. //      DoubleListIterator to an integer.
  315. //
  316. //      operator Object&
  317. //
  318. //      Converts a double list iterator to an Object reference.
  319. //
  320. //      operator ++
  321. //
  322. //      The increment operator.
  323. //
  324. //      operator --
  325. //
  326. //      The decrement operator.  This makes sense for double lists.
  327. //
  328. //      restart
  329. //
  330. //      DoubleList iterator restart mechanism.
  331. //
  332. // Private Members
  333. //
  334. //      currentElement
  335. //
  336. //      The current position in the iteration sequence.
  337. //
  338. //      startingElement
  339. //
  340. //      The starting position in the iteration sequence.
  341. //
  342. // End ---------------------------------------------------------------------
  343.  
  344.  
  345. // Constructor //
  346.  
  347. inline DoubleListIterator::DoubleListIterator( const DoubleList& toIterate, int atHead )
  348.  
  349. // Summary -----------------------------------------------------------------
  350. //
  351. //      Constructor for a list iterator object.
  352. //
  353. // Parameters
  354. //
  355. //      toIterate
  356. //
  357. //      The double list we are to iterate.
  358. //
  359. //      atHead
  360. //
  361. //      Indicates whether we are to start at the head of the list.  If this is
  362. //      not 1, we will start at the tail.
  363. //
  364. // End ---------------------------------------------------------------------
  365. {
  366.     if ( atHead == 1 )
  367.     {
  368.         startingElement = currentElement = toIterate.head;
  369.     }
  370.     else
  371.     {
  372.         startingElement = currentElement = toIterate.tail;
  373.     }
  374. }
  375. // End Constructor DoubleListIterator::DoubleListIterator //
  376.  
  377.  
  378. #endif // ifndef __DBLLIST_H //
  379.