home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_40.arc / DAIMS.ARC / CHBUFFER.CPP < prev    next >
Text File  |  1988-02-10  |  896b  |  51 lines

  1. #include "chbuffer.hxx"
  2. #undef TEST
  3. /* 
  4. -*++ char_buffer::put(): stick a character at the end of the buffer
  5. ** 
  6. ** (*++ history: 
  7. **      7 Dec 87    Bruce Eckel    Creation date
  8. ** ++*)
  9. ** 
  10. ** (*++ detailed: 
  11. ** ++*)
  12. */
  13.  
  14. void char_buffer::put(char c) { 
  15.   if (index +1 == length) { error("buffer overflow"); return;}
  16.   head[index++] = c;
  17.   head[index] = 0;        /* null-terminate */
  18. }
  19.  
  20.  
  21. /* 
  22. -*++ char_buffer::get(): get a character from the end of the buffer
  23. ** 
  24. ** (*++ history: 
  25. **      7 Dec 87    Bruce Eckel    Creation date
  26. ** ++*)
  27. ** 
  28. ** (*++ detailed: 
  29. ** ++*)
  30. */
  31.  
  32. char char_buffer::get() {
  33.   if (--index < 0) { index = 0; return 0; }
  34.   char c = head[index];
  35.   head[index] = 0;
  36.   return c;
  37. }
  38.  
  39.   
  40. #ifdef TEST
  41. main()
  42. {
  43.   char c;
  44.   char_buffer buf(80);
  45.   while(cin.get(c), c != '\n')
  46.       buf.put(c);
  47.   cout << "dumping buf\n";
  48.   buf.dump();
  49. }
  50. #endif
  51.