stdio_streambuf.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. // This header defines two streambufs:
  19. // stdio_istreambuf, a read-only streambuf synchronized with a C stdio
  20. // FILE object
  21. // stdio_ostreambuf, a write-only streambuf synchronized with a C stdio
  22. // FILE object.
  23. // Note that neither stdio_istreambuf nor stdio_ostreambuf is a template;
  24. // both classes are derived from basic_streambuf<char, char_traits<char> >.
  25. // Note: the imbue() member function is a no-op. In particular, these
  26. // classes assume that codecvt<char, char, mbstate_t> is always an identity
  27. // transformation. This is true of the default locale, and of all locales
  28. // defined for the C I/O library. If you need to use a locale where
  29. // the codecvt<char, char, mbstate_t> facet performs a nontrivial
  30. // conversion, then you should use basic_filebuf<> instead of stdio_istreambuf
  31. // or stdio_ostreambuf. (If you don't understand what any of this means,
  32. // then it's not a feature you need to worry about. Locales where
  33. // codecvt<char, char, mbstate_t> does something nontrivial are a rare
  34. // corner case.)
  35. #ifndef _STLP_STDIO_STREAMBUF
  36. #define _STLP_STDIO_STREAMBUF
  37. #include <streambuf>
  38. #include <cstdio> // For FILE.
  39. _STLP_BEGIN_NAMESPACE
  40. _STLP_MOVE_TO_PRIV_NAMESPACE
  41. // Base class for features common to stdio_istreambuf and stdio_ostreambuf
  42. class stdio_streambuf_base :
  43. public basic_streambuf<char, char_traits<char> > /* FILE_basic_streambuf */ {
  44. public: // Constructor, destructor.
  45. // The argument may not be null. It must be an open file pointer.
  46. stdio_streambuf_base(FILE*);
  47. // The destructor flushes the stream, but does not close it.
  48. ~stdio_streambuf_base();
  49. protected: // Virtual functions from basic_streambuf.
  50. streambuf* setbuf(char*, streamsize);
  51. pos_type seekoff(off_type, ios_base::seekdir,
  52. ios_base::openmode
  53. = ios_base::in | ios_base::out);
  54. pos_type seekpos(pos_type,
  55. ios_base::openmode
  56. = ios_base::in | ios_base::out);
  57. int sync();
  58. protected:
  59. FILE* _M_file;
  60. };
  61. class stdio_istreambuf : public stdio_streambuf_base {
  62. public: // Constructor, destructor.
  63. stdio_istreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
  64. ~stdio_istreambuf();
  65. protected: // Virtual functions from basic_streambuf.
  66. streamsize showmanyc();
  67. int_type underflow();
  68. int_type uflow();
  69. virtual int_type pbackfail(int_type c = traits_type::eof());
  70. };
  71. class stdio_ostreambuf : public stdio_streambuf_base {
  72. public: // Constructor, destructor.
  73. stdio_ostreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
  74. ~stdio_ostreambuf();
  75. protected: // Virtual functions from basic_streambuf.
  76. streamsize showmanyc();
  77. int_type overflow(int_type c = traits_type::eof());
  78. };
  79. _STLP_MOVE_TO_STD_NAMESPACE
  80. _STLP_END_NAMESPACE
  81. #endif /* _STLP_STDIO_STREAMBUF */
  82. // Local Variables:
  83. // mode:C++
  84. // End: