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 / CONTAIN.H < prev    next >
C/C++ Source or Header  |  1990-09-26  |  6KB  |  221 lines

  1. #ifndef __CONTAIN_H
  2. #define __CONTAIN_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. //      Container
  18. //      ContainerIterator
  19. //
  20. // Description
  21. //
  22. //      Defines the abstract class Container.  Containers operate
  23. //      on groups of other objects.
  24. //      Defines the ContainerIterator class.  Container iterators are
  25. //      use to step through the objects in a container class without
  26. //      knowing the internals of the container class.
  27. //
  28. // End ---------------------------------------------------------------------
  29.  
  30. // Interface Dependencies ---------------------------------------------------
  31.  
  32. #ifndef __IOSTREAM_H
  33. #include <iostream.h>
  34. #define __IOSTREAM_H
  35. #endif
  36.  
  37. #ifndef __CLSTYPES_H
  38. #include <clstypes.h>
  39. #endif
  40.  
  41. #ifndef __OBJECT_H
  42. #include <object.h>
  43. #endif
  44.  
  45. // End Interface Dependencies ------------------------------------------------
  46.  
  47. // ForwardReference //
  48.  
  49. class ContainerIterator;
  50.  
  51.  
  52. // Class //
  53.  
  54. class Container:  public Object
  55. {
  56. public:
  57.             Container() { itemsInContainer = 0; }
  58.             Container( const Container& );
  59.     virtual ~Container();
  60.  
  61.     virtual ContainerIterator& initIterator() const = 0;
  62.  
  63.     virtual void            forEach( iterFuncType, void * );
  64.     virtual Object&         firstThat( condFuncType, void * ) const;
  65.     virtual Object&         lastThat( condFuncType, void * ) const;
  66.  
  67.     virtual classType       isA() const = 0;
  68.     virtual char           *nameOf() const = 0;
  69.     virtual hashValueType   hashValue() const = 0;
  70.     virtual int             isEqual( const Object& ) const;
  71.     virtual void            printOn( ostream& ) const;
  72.     virtual void            printHeader( ostream& ) const;
  73.     virtual void            printSeparator( ostream& ) const;
  74.     virtual void            printTrailer( ostream& ) const;
  75.  
  76.             int             isEmpty() const { return (itemsInContainer == 0); }
  77.             countType       getItemsInContainer() const { return itemsInContainer; }
  78.  
  79. protected:
  80.             countType       itemsInContainer;
  81.  
  82. private:
  83.     friend  class ContainerIterator;
  84.  
  85. };
  86.  
  87. // Description -------------------------------------------------------------
  88. //
  89. //      Defines the abstract class Container.  A Container is an object
  90. //      which groups some number of other objects together.  This is
  91. //      an abstract class and provides no method for adding and
  92. //      removing objects from the container.  Those functions are
  93. //      provided by derived classes.
  94. //      
  95. //      Constructor
  96. //
  97. //      Container
  98. //
  99. //      Copy constructor
  100. //
  101. // Public Members
  102. //
  103. //      isEmpty
  104. //
  105. //      Returns a 1 if the container has no members.  Returns a 0
  106. //      otherwise.
  107. //
  108. //      initIterator
  109. //
  110. //      Initializes an iterator for this container.
  111. //
  112. //      firstThat
  113. //
  114. //      Returns the first object that satisfies the given condition.
  115. //
  116. //      lastThat
  117. //
  118. //      Returns the last object that satisfies the given condition.
  119. //
  120. //      isA
  121. //
  122. //      Inherited from Object and redeclared as pure virtual.
  123. //
  124. //      hashValue
  125. //
  126. //      Inherited from Object and redeclared as pure virtual.
  127. //
  128. //      nameOf
  129. //
  130. //      Inherited from Object and redeclared as pure virtual.
  131. //     
  132. //      isEqual
  133. //
  134. //      A deep-comparison equality operator.
  135. //
  136. //      getItemsInContainer
  137. //
  138. //      Returns the current number of objects in any container.
  139. //
  140. //      printOn
  141. //
  142. //      Displays each of the objects which make up a container.
  143. //
  144. //      printHeader
  145. //
  146. //      Displays a standard header.
  147. //
  148. //      printSeparator
  149. //
  150. //      Displays a standard trailer.
  151. //
  152. //      printTrailer
  153. //
  154. //      Displays a standard trailer.
  155. //
  156. // Inherited Members
  157. //
  158. //      operator new
  159. //
  160. //      Inherited from Object.
  161. //
  162. // Protected Members
  163. //
  164. //      itemsInContainer
  165. //
  166. //      A count of the number of items in currently in the container.
  167. //
  168. // Private Members
  169. //
  170. //      The class ContainerIterator is made a friend of class Object so that
  171. //      objects can be iterated without knowing the internals of each class.
  172. //
  173. // End ---------------------------------------------------------------------
  174.  
  175.  
  176. // Class //
  177.  
  178. class ContainerIterator
  179. {
  180. public:
  181.     virtual ~ContainerIterator();
  182.  
  183.     virtual             operator int() = 0;
  184.     virtual             operator Object&() = 0;
  185.     virtual Object&     operator ++() = 0;
  186.     virtual void        restart() = 0;
  187. };
  188.  
  189. // Description -------------------------------------------------------------
  190. //
  191. //      Defines a container iterator object.
  192. //
  193. // Destructor
  194. //
  195. //      ~ContainerIterator
  196. //
  197. // Public Members
  198. //
  199. //      operator int
  200. //
  201. //      We are allowed one cast operator to a predefined type.  This
  202. //      operator defines an explicit or an implicit cast from a
  203. //      ContainerIterator to an integer.
  204. //
  205. //      operator Object&
  206. //
  207. //      Conversion from ContainerIterator to Object.
  208. //
  209. //      operator ++
  210. //
  211. //      The increment operator.
  212. //
  213. //      restart
  214. //
  215. //      Restarts an iterator without destroying it.
  216. //
  217. // End ---------------------------------------------------------------------
  218.  
  219.  
  220. #endif // ifndef __CONTAIN_H //
  221.