home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BCPPOWL1.ZIP / CLINC.ZIP / CONTAIN.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  5.2 KB  |  210 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. _CLASSDEF(Container)
  39. _CLASSDEF(ContainerIterator)
  40.  
  41. // Class //
  42.  
  43. class _CLASSTYPE Container:  public Object
  44. {
  45. public:
  46.     Container() { itemsInContainer = 0; }
  47.     Container( RCContainer );
  48.     virtual ~Container();
  49.  
  50.     virtual RContainerIterator initIterator() const = 0;
  51.  
  52.     virtual void            forEach( iterFuncType, Pvoid );
  53.     virtual RCObject firstThat( condFuncType, Pvoid ) const;
  54.     virtual RCObject lastThat( condFuncType, Pvoid ) const;
  55.  
  56.     virtual classType       isA() const = 0;
  57.     virtual Pchar nameOf() const = 0;
  58.     virtual hashValueType   hashValue() const = 0;
  59.     virtual int             isEqual( RCObject ) const;
  60.     virtual void            printOn( Rostream ) const;
  61.     virtual void            printHeader( Rostream ) const;
  62.     virtual void            printSeparator( Rostream ) const;
  63.     virtual void            printTrailer( Rostream ) const;
  64.  
  65.             int             isEmpty() const { return (itemsInContainer == 0); }
  66.             countType       getItemsInContainer() const { return itemsInContainer; }
  67.  
  68. protected:
  69.             countType       itemsInContainer;
  70.  
  71. private:
  72.     friend  class ContainerIterator;
  73.  
  74. };
  75.  
  76. // Description -------------------------------------------------------------
  77. //
  78. //      Defines the abstract class Container.  A Container is an object
  79. //      which groups some number of other objects together.  This is
  80. //      an abstract class and provides no method for adding and
  81. //      removing objects from the container.  Those functions are
  82. //      provided by derived classes.
  83. //      
  84. //      Constructor
  85. //
  86. //      Container
  87. //
  88. //      Copy constructor
  89. //
  90. // Public Members
  91. //
  92. //      isEmpty
  93. //
  94. //      Returns a 1 if the container has no members.  Returns a 0
  95. //      otherwise.
  96. //
  97. //      initIterator
  98. //
  99. //      Initializes an iterator for this container.
  100. //
  101. //      firstThat
  102. //
  103. //      Returns the first object that satisfies the given condition.
  104. //
  105. //      lastThat
  106. //
  107. //      Returns the last object that satisfies the given condition.
  108. //
  109. //      isA
  110. //
  111. //      Inherited from Object and redeclared as pure virtual.
  112. //
  113. //      hashValue
  114. //
  115. //      Inherited from Object and redeclared as pure virtual.
  116. //
  117. //      nameOf
  118. //
  119. //      Inherited from Object and redeclared as pure virtual.
  120. //     
  121. //      isEqual
  122. //
  123. //      A deep-comparison equality operator.
  124. //
  125. //      getItemsInContainer
  126. //
  127. //      Returns the current number of objects in any container.
  128. //
  129. //      printOn
  130. //
  131. //      Displays each of the objects which make up a container.
  132. //
  133. //      printHeader
  134. //
  135. //      Displays a standard header.
  136. //
  137. //      printSeparator
  138. //
  139. //      Displays a standard trailer.
  140. //
  141. //      printTrailer
  142. //
  143. //      Displays a standard trailer.
  144. //
  145. // Inherited Members
  146. //
  147. //      operator new
  148. //
  149. //      Inherited from Object.
  150. //
  151. // Protected Members
  152. //
  153. //      itemsInContainer
  154. //
  155. //      A count of the number of items in currently in the container.
  156. //
  157. // Private Members
  158. //
  159. //      The class ContainerIterator is made a friend of class Object so that
  160. //      objects can be iterated without knowing the internals of each class.
  161. //
  162. // End ---------------------------------------------------------------------
  163.  
  164.  
  165. // Class //
  166.  
  167. class _CLASSTYPE ContainerIterator
  168. {
  169. public:
  170.     virtual ~ContainerIterator();
  171.  
  172.     virtual             operator int() = 0;
  173.     virtual             operator RObject() = 0;
  174.     virtual RObject     operator ++() = 0;
  175.     virtual void        restart() = 0;
  176. };
  177.  
  178. // Description -------------------------------------------------------------
  179. //
  180. //      Defines a container iterator object.
  181. //
  182. // Destructor
  183. //
  184. //      ~ContainerIterator
  185. //
  186. // Public Members
  187. //
  188. //      operator int
  189. //
  190. //      We are allowed one cast operator to a predefined type.  This
  191. //      operator defines an explicit or an implicit cast from a
  192. //      ContainerIterator to an integer.
  193. //
  194. //      operator RObject
  195. //
  196. //      Conversion from ContainerIterator to Object.
  197. //
  198. //      operator ++
  199. //
  200. //      The increment operator.
  201. //
  202. //      restart
  203. //
  204. //      Restarts an iterator without destroying it.
  205. //
  206. // End ---------------------------------------------------------------------
  207.  
  208.  
  209. #endif // ifndef __CONTAIN_H //
  210.