home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP10-8.ZIP / CLASSSRC.ZIP / COLLECT.CPP < prev    next >
C/C++ Source or Header  |  1990-09-26  |  3KB  |  119 lines

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