home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-1.ZIP / CLASSSRC.ZIP / ARRAY.CPP < prev    next >
C/C++ Source or Header  |  1992-02-18  |  1KB  |  47 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  ARRAY.CPP                                                             */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991                                  */
  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 <Array.h>
  16. #endif  // __ARRAY_H
  17.  
  18. void Array::add( Object& toAdd )
  19. {
  20.     lastElementIndex++;
  21.     while( ptrAt( lastElementIndex ) != ZERO &&
  22.            lastElementIndex <= upperbound
  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.         delete ptrAt( atIndex );
  43.         }
  44.  
  45.     setData( atIndex, &toAdd );
  46. }
  47.