home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 11.ddi / CLASSSRC.ZIP / COLLECT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  2.8 KB  |  110 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. // Contents ----------------------------------------------------------------
  4. //
  5. //      Collection::findMember
  6. //      Collection::hasMember
  7. //
  8. // Description
  9. //
  10. //      Implementation of class Collection member functions.
  11. //
  12. // End ---------------------------------------------------------------------
  13.  
  14. // Interface Dependencies ---------------------------------------------------
  15.  
  16. #ifndef __CLSTYPES_H
  17. #include <clstypes.h>
  18. #endif
  19.  
  20. #ifndef __COLLECT_H
  21. #include <collect.h>
  22. #endif
  23.  
  24. // End Interface Dependencies ------------------------------------------------
  25.  
  26. // Implementation Dependencies ----------------------------------------------
  27.  
  28. #ifndef __CONTAIN_H
  29. #include <contain.h>
  30. #endif
  31.  
  32. // End Implementation Dependencies -------------------------------------------
  33.  
  34.  
  35. // Member Function //
  36.  
  37. Collection::~Collection()
  38.  
  39. // Summary -----------------------------------------------------------------
  40. //
  41. //      Destructor for a Collection object.
  42. //
  43. //        We don't have to do anything here.  The derived class will
  44. //        destroy all objects in the container.
  45. //
  46. // End ---------------------------------------------------------------------
  47. {
  48. }
  49. // End Destructor //
  50.  
  51.  
  52. // Member Function //
  53.  
  54. Object& Collection::findMember( const Object& testObject ) const
  55.  
  56. // Summary -----------------------------------------------------------------
  57. //
  58. // Functional Description
  59. //
  60. //      We initialize an iterator, then iterate through each object,
  61. //         doing a comparison of objects.  Note that the iteration is
  62. //         a shallow one, that is, if our collection is made up of
  63. //         container objects, we don't check to see whether those containers
  64. //         contain the object we are looking for.
  65. //
  66. // Remarks
  67. //
  68. //  warnings:
  69. //      We must be sure to delete the container iterator, since it was
  70. //      allocated on the heap.
  71. //
  72. // End ---------------------------------------------------------------------
  73. {
  74.     ContainerIterator& containerIterator = initIterator();
  75.  
  76.     while( int(containerIterator) != 0 )
  77.     {
  78.         Object& listObject = containerIterator++;
  79.  
  80.         if ( listObject == testObject )
  81.         {
  82.             delete &containerIterator;
  83.             return listObject;
  84.         }
  85.     } // end while //
  86.     delete &containerIterator;
  87.     return NOOBJECT;
  88. }
  89. // End Member Function Collection::findMember //
  90.  
  91.  
  92. // Member Function //
  93.  
  94. int Collection::hasMember( const Object& testObject ) const
  95.  
  96. // Summary ----------------------------------------------------------------
  97. //
  98. //      Collection
  99. //
  100. // Description
  101. //
  102. //      Defines the abstract class Collection.  Collections group objects
  103. //      together and specify operations.
  104. //
  105. // End ---------------------------------------------------------------------
  106. {
  107.     return findMember( testObject ) != NOOBJECT;
  108. }
  109. // End Member Function Collection::hasMember //
  110.