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 / ARRAY.CPP < prev    next >
C/C++ Source or Header  |  1990-09-26  |  4KB  |  178 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. //      Array::isA
  15. //      Array::nameOf
  16. //      Array::add
  17. //      Array::addAt
  18. //
  19. // Description
  20. //
  21. //      Implementation of class Array member functions.
  22. //
  23. // End ---------------------------------------------------------------------
  24.  
  25. // Interface Dependencies ---------------------------------------------------
  26.  
  27. #ifndef __CLSTYPES_H
  28. #include <clstypes.h>
  29. #endif
  30.  
  31. #ifndef __OBJECT_H
  32. #include <object.h>
  33. #endif
  34.  
  35. #ifndef __CONTAIN_H
  36. #include <contain.h>
  37. #endif
  38.  
  39. #ifndef __ARRAY_H
  40. #include <array.h>
  41. #endif
  42.  
  43. // End Interface Dependencies ------------------------------------------------
  44.  
  45. // Implementation Dependencies ----------------------------------------------
  46. // End Implementation Dependencies -------------------------------------------
  47.  
  48.  
  49. // Member Function //
  50.  
  51. Array::~Array()
  52.  
  53. // Summary -----------------------------------------------------------------
  54. //
  55. //      Destructor for an Array object.
  56. //
  57. //        We don't do anything here, because the destructor for AbstractArray
  58. //        will take care of destroying the contained objects.
  59. //
  60. // End ---------------------------------------------------------------------
  61. {
  62. }
  63. // End Destructor //
  64.  
  65.  
  66. // Member Function //
  67.  
  68. classType Array::isA() const
  69.  
  70. // Summary -----------------------------------------------------------------
  71. //
  72. //         Returns the class type of an array.
  73. //
  74. // End ---------------------------------------------------------------------
  75. {
  76.     return arrayClass; 
  77. }
  78. // End Member Function Array::isA //
  79.  
  80.  
  81. // Member Function //
  82.  
  83. char *Array::nameOf() const
  84.  
  85. // Summary -----------------------------------------------------------------
  86. //
  87. //         Returns a pointer to the character string "Array."
  88. //
  89. // End ---------------------------------------------------------------------
  90. {
  91.     return "Array";
  92. }
  93. // End Member Function Array::nameOf //
  94.  
  95.  
  96. // Member Function //
  97.  
  98. void Array::add( Object& toAdd )
  99.  
  100. // Summary -----------------------------------------------------------------
  101. //
  102. //      Adds the given object to the array.
  103. //
  104. // Parameters
  105. //
  106. //      toAdd
  107. //
  108. //      The object we are to add to the array.  Once the object is
  109. //      added, it is owned by the array.
  110. //
  111. // End ---------------------------------------------------------------------
  112. {
  113.  
  114. // Body Comment
  115. //
  116. //      We search for the first available space for an array element.
  117. //      Since the user may have inserted an element with addAt or
  118. //      with the subscript operator, we check first before overwriting
  119. //      anything.
  120. //
  121. // End
  122.  
  123.     while( theArray[ whereToAdd ] != ZERO && whereToAdd <= upperbound )
  124.     {
  125.         whereToAdd++;
  126.     } // end while an array index already has an element.
  127.  
  128.     if( whereToAdd > upperbound )
  129.     {
  130.         reallocate( whereToAdd - lowerbound + 1 );
  131.     }
  132.     theArray[ whereToAdd++ ] = &toAdd;
  133.     itemsInContainer++;
  134.  
  135. }
  136. // End Member Function Array::add //
  137.  
  138.  
  139. // Member Function //
  140.  
  141. void Array::addAt( Object& toAdd, int atIndex )
  142.  
  143. // Summary -----------------------------------------------------------------
  144. //
  145. //      Adds the given object to the array at the given index.  If there
  146. //      is an object already at that index, destroys the object.
  147. //
  148. // Parameters
  149. //
  150. //      toAdd
  151. //
  152. //      The object we are to add to the array.  Once the object is
  153. //      added, it is owned by the array.
  154. //
  155. //      atIndex
  156. //
  157. //      The index at which to add the object.
  158. //
  159. // End ---------------------------------------------------------------------
  160. {
  161.  
  162.     if( atIndex > upperbound )
  163.     {
  164.         reallocate( atIndex - lowerbound + 1 );
  165.     }
  166.  
  167.     if ( theArray[ atIndex ] != ZERO )
  168.     {
  169.         delete theArray[ atIndex ];
  170.         itemsInContainer--;
  171.     }
  172.     theArray[ atIndex ] = &toAdd;
  173.     itemsInContainer++;
  174. }
  175. // End Member Function Array::addAt //
  176.  
  177.  
  178.