home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 8.ddi / IOSTRSR1.ZIP / SRBOFLOW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.4 KB  |  72 lines

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     srboflow.cpp                                             |*/
  4. /*|                                                              |*/
  5. /*|     Class strstreambuf                                       |*/
  6. /*|          int strstreambuf::overflow( int )                   |*/
  7. /*|                                                              |*/
  8. /*[]------------------------------------------------------------[]*/
  9.  
  10. /*
  11.  *      C/C++ Run Time Library - Version 5.0
  12.  *
  13.  *      Copyright (c) 1990, 1992 by Borland International
  14.  *      All Rights Reserved.
  15.  *
  16.  */
  17.  
  18. #include <ioconfig.h>
  19. #include <strstrea.h>
  20.  
  21. #define expandable ((ssbflags&(dynamic|frozen))==dynamic)
  22.  
  23. int strstreambuf::overflow(int c)
  24. {
  25.     if( expandable )
  26.         {
  27.         // allocate put area as needed
  28.         if( ! base() )
  29.             doallocate();
  30.         if( ! pbase() )
  31.             setp(base(), ebuf());
  32.         }
  33.  
  34.     if( pbase() )
  35.         {
  36.         if( (pptr() >= epptr()) && expandable )
  37.             {
  38.             // expand the reserve area
  39.             char *oldp = base();    // old buf
  40.             int len = blen();       // length of old buf
  41.             char *p = new char[len + MinStrstreamIncr]; // new buf
  42.             if( ! p )
  43.                 return EOF;     // out of memory
  44.  
  45.             memcpy(p, oldp, len);   // copy data to new buf
  46.             // get relative pointer data
  47.             int ebloc, gloc, egloc; // get area pointer data
  48.             int ploc = (int)(pptr() - oldp);    // put area pointer data
  49.             int get_area = (gptr() != 0);
  50.             if( get_area )
  51.                 {
  52.                 ebloc = (int)(eback() - oldp);  // eback location
  53.                 gloc = (int)(gptr() - oldp);    // gptr location
  54.                 egloc = (int)(egptr() - oldp);  // egptr location
  55.                 }
  56.             // set up new pointers
  57.             setb(p, p + len + MinStrstreamIncr, 0);
  58.             setp(p, ebuf());    // the put area goes to end of buf
  59.             pbump(ploc);
  60.             if( get_area )
  61.                 setg(p + ebloc, p + gloc, p + egloc);
  62.             delete oldp;        // free old space
  63.             }
  64.         if( pptr() < epptr() )
  65.             return sputc(c);        // now there is room in the put area
  66.         }
  67.  
  68.     return EOF;     // could not make more space
  69. }
  70.  
  71.  
  72.