home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_DEV08B.LHA / gerlib / libg++ / iostream / QUESTIONS < prev    next >
Encoding:
Text File  |  1993-12-12  |  1.4 KB  |  55 lines

  1. *** Can/should streambuf::sputbackc(char) assume that the putback area
  2. is writable?
  3.  
  4. I.e. is the following a valid implementation:
  5.  
  6. int streambuf::sputbackc(char c)
  7. {
  8.     if (gptr() <= eback()) return pbackfail(c);
  9.     gbump(-1);
  10.     *gptr() = c;
  11.     return zapeof(c);
  12. }
  13.  
  14. Problem: what if the get area is a read-only string?
  15. Or a copy-on-write file buffer?
  16.  
  17. How about:
  18.  
  19. int streambuf::sputbackc(char c)
  20. {
  21.     if (gptr() <= eback()) return pbackfail(c);
  22.     gbump(-1);
  23.     return zapeof(c);
  24. }
  25.  
  26. Problem: What if we want to remember putback'ed characters
  27. in a buffer? Solution: Make sure pbackfail is always called
  28. in those cases.
  29.  
  30. Or the paranoid solution:
  31.  
  32. int streambuf::sputbackc(char c)
  33. {
  34.     if (gptr() <= eback()) return pbackfail(c);
  35.     gbump(-1);
  36.     if (*gptr() != c)
  37.     *gptr() = c;
  38.     return zapeof(c);
  39. }
  40.  
  41. The assumptions should be specified by the standard.
  42.  
  43. *** The 2.1 Library manual page 3-19 section "Files" says:
  44. "A subtle point is that closing a file stream (either explicitly or
  45. implicitly in the destructor) will close the underlying file
  46. descriptor if it was opened with a filename, but not
  47. if it was supplied with attach."
  48.  
  49. I assume the [io]fstream::attach(fd) rule also applies to
  50. the [io]fstream::[io]fstream(int fd) constructors?
  51.  
  52. How about filebufs? Will "delete (new filebuf(0))"
  53. close the underlying file descriptor? What about
  54. "(new filebuf(0))->close()"?
  55.