home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 1.ddi / CLASSINC.ZIP / CONTAIN.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  5.2 KB  |  212 lines

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