home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / clobss.pak / ARRAY.CPO < prev    next >
Text File  |  1997-07-23  |  2KB  |  51 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  ARRAY.CPP                                                             */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1993                            */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __CHECKS_H )
  11. #include <checks.h>
  12. #endif  // CHECKS_H
  13.  
  14. #if !defined( __ARRAY_H )
  15. #include "classlib\obsolete\array.h"
  16. #endif  // __ARRAY_H
  17.  
  18. void Array::add( Object& toAdd )
  19. {
  20.     lastElementIndex++;
  21.     while( lastElementIndex <= upperbound &&
  22.            ptrAt( lastElementIndex ) != ZERO
  23.          )
  24.         lastElementIndex++;
  25.  
  26.     if( lastElementIndex > upperbound )
  27.         reallocate( lastElementIndex - lowerbound + 1 );
  28.  
  29.     setData( lastElementIndex, &toAdd );
  30.     itemsInContainer++;
  31.     CHECK( itemsInContainer > 0 );
  32. }
  33.  
  34. void Array::addAt( Object& toAdd, int atIndex )
  35. {
  36.     PRECONDITION( atIndex >= lowerbound );
  37.     if( atIndex > upperbound )
  38.         reallocate( atIndex - lowerbound + 1 );
  39.  
  40.     if( ptrAt( atIndex ) != ZERO )
  41.         {
  42.         if( ownsElements() )
  43.             delete ptrAt( atIndex );
  44.         itemsInContainer--;
  45.         }
  46.  
  47.     setData( atIndex, &toAdd );
  48.     itemsInContainer++;
  49.     CHECK( itemsInContainer > 0 );
  50. }
  51.