home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume43 / gen / part02 / Buffer.c next >
Encoding:
C/C++ Source or Header  |  1994-07-24  |  778 b   |  57 lines

  1. /*
  2. File: Buffer.c
  3.  
  4. Author: Bruce Kritt
  5.  
  6. Description:
  7. */
  8.  
  9. #include <stdio.h>
  10.  
  11. #include "string.h"
  12.  
  13. #include "String.h"
  14. #include "Buffer.h"
  15.  
  16. // constructor
  17.  
  18. Buffer::Buffer(int init_size)
  19. {
  20.         if (init_size < 1)
  21.         {
  22.                 puts("Buffer constructor: Bad buffer size.");
  23.                 exit(1);
  24.         }
  25.  
  26.         size = init_size;
  27.         start = new char[Size()+1];
  28.         Flush();
  29.  
  30.         return;
  31.  
  32. }       // end constructor
  33.  
  34. // public services
  35.  
  36. void Buffer::Flush(void)
  37. {
  38.         end = start;
  39.         *end = 0;
  40.  
  41.         return;
  42.  
  43. }       // end function Flush()
  44.  
  45. void Buffer::Push(int ch)
  46. {
  47.         if (!Full())
  48.         {
  49.                 *end = ch;
  50.                 ++end;
  51.                 *end = 0;
  52.         }
  53.  
  54.         return;
  55.  
  56. }       // end function Push()
  57.