home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / streamb1.cpp < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  162 lines

  1. /***
  2. *streamb1.cpp - non-core functions for streambuf class.
  3. *
  4. *       Copyright (c) 1990-1997, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *       None-core functions for streambuf class.
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <internal.h>
  13. #include <iostream.h>
  14. #pragma hdrstop
  15.  
  16.  
  17. /***
  18. *int streambuf::snextc() -
  19. *
  20. *Purpose:
  21. *       Increments get_pointer and returns the character following the new
  22. *       get_pointer.
  23. *
  24. *Entry:
  25. *       None.
  26. *
  27. *Exit:
  28. *       Returns the next character or EOF.
  29. *
  30. *Exceptions:
  31. *       Returns EOF if error.
  32. *
  33. *******************************************************************************/
  34. int streambuf::snextc()
  35. {
  36.     if (_fUnbuf)
  37.         {
  38.         if (x_lastc==EOF)
  39.             underflow();                // skip 1st character
  40.         return x_lastc = underflow();   // return next character, or EOF
  41.         }
  42.     else
  43.         {
  44.         if ((!egptr()) || (gptr()>=egptr()))
  45.             underflow();                // make sure buffer
  46.  
  47.         if ((++_gptr) < egptr())
  48.             return (int)(unsigned char) *gptr();
  49.         return underflow();             // returns next character, or EOF
  50.         }
  51. }
  52.  
  53.  
  54. /***
  55. *int streambuf::sbumpc() -
  56. *
  57. *Purpose:
  58. *       Increments get_pointer and returns the character that the previous
  59. *       get_pointer pointed to.
  60. *
  61. *Entry:
  62. *       None.
  63. *
  64. *Exit:
  65. *       Returns current character before bumping get pointer.
  66. *
  67. *Exceptions:
  68. *       Returns EOF if error.
  69. *
  70. *******************************************************************************/
  71. int streambuf::sbumpc()
  72. {
  73.     int c;
  74.     if (_fUnbuf) // no buffer
  75.         {
  76.         if (x_lastc==EOF)
  77.             {
  78.             c = underflow();
  79.             }
  80.         else
  81.             {
  82.             c = x_lastc;
  83.             x_lastc = EOF;
  84.             }
  85.         }
  86.     else
  87.         {
  88.         if( gptr() < egptr() )
  89.             {
  90.             c = (int)(unsigned char)*(gptr());
  91.             }
  92.         else
  93.             {
  94.             c = underflow();
  95.             }
  96.         _gptr++;
  97.         }
  98.     return c;
  99. }
  100.  
  101. /***
  102. *void streambuf::stossc() - advance get pointer
  103. *
  104. *Purpose:
  105. *       Advances the get pointer.  Does not check for EOF.
  106. *
  107. *Entry:
  108. *       None.
  109. *
  110. *Exit:
  111. *       None.
  112. *
  113. *Exceptions:
  114. *
  115. *******************************************************************************/
  116. void streambuf::stossc()
  117. {
  118.     if (_fUnbuf)
  119.         {
  120.         if (x_lastc==EOF)
  121.             underflow();        // throw away current character
  122.         else
  123.             x_lastc=EOF;        // discard current cached character
  124.         }
  125.     else
  126.         {
  127.         if (gptr() >= egptr())
  128.             underflow();
  129.         if (gptr() < egptr())
  130.             _gptr++;
  131.         }
  132. }
  133.  
  134. /***
  135. *int streambuf::sgetc() -
  136. *
  137. *Purpose:
  138. *       Returns the character that the previous get_pointer points to.
  139. *       DOES NOT advance the get pointer.
  140. *
  141. *Entry:
  142. *       None.
  143. *
  144. *Exit:
  145. *       Returns current character or EOF if error.
  146. *
  147. *Exceptions:
  148. *       Returns EOF if error.
  149. *
  150. *******************************************************************************/
  151. int streambuf::sgetc()
  152. {
  153.     if (_fUnbuf)  // no buffer
  154.         {
  155.         if (x_lastc==EOF)
  156.             x_lastc = underflow();
  157.         return x_lastc;
  158.         }
  159.      else
  160.         return underflow();
  161. }
  162.