home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stl453up.zip / stl453fx / stlport / stdio_streambuf < prev    next >
Text File  |  2002-04-29  |  4KB  |  116 lines

  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 is an extension.  It defines two streambufs:
  19. // stdio_istreambuf, a read-only streambuf synchronized with a C stdio
  20. // FILE object, and stdio_ostreambuf, a write-only streambuf
  21. // synchronized with a C stdio FILE object.  Note that neither 
  22. // stdio_istreambuf nor stdio_ostreambuf is a template; both classes
  23. // are derived from basic_streambuf<char, char_traits<char> >.
  24.  
  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.  
  36.  
  37. #ifndef _STLP_STDIO_STREAMBUF
  38. #define _STLP_STDIO_STREAMBUF
  39.  
  40. #if !defined(STLP_WINCE)
  41.  
  42. #include <streambuf>            // For basic_streambuf<>
  43. #include <cstdio>              // For FILE.
  44.  
  45. # ifndef _STLP_HAS_NO_NAMESPACES
  46. // This is an extension.  It is in namespace SGI, not namespace std
  47. namespace _SgI {
  48.  
  49. # ifdef _STLP_USE_NAMESPACES
  50. using namespace _STLP_STD;
  51. # endif
  52. # endif
  53.  
  54. // Base class for features common to stdio_istreambuf and stdio_ostreambuf
  55. class stdio_streambuf_base : public _STLP_STD::basic_streambuf<char, char_traits<char> >
  56. {
  57. public:                         // Constructor, destructor.
  58.   // The argument may not be null.  It must be an open file pointer.
  59.   stdio_streambuf_base(FILE*);
  60.  
  61.   // The destructor flushes the stream, but does not close it.
  62.   ~stdio_streambuf_base();
  63.  
  64. protected:                      // Virtual functions from basic_streambuf.
  65.   streambuf* setbuf(char*, streamsize);
  66.  
  67.   pos_type seekoff(off_type, ios_base::seekdir,
  68.                    ios_base::openmode
  69.                           = ios_base::in | ios_base::out);
  70.   pos_type seekpos(pos_type,
  71.                    ios_base::openmode
  72.                           = ios_base::in | ios_base::out);
  73.   int sync();
  74.  
  75. protected:
  76.   FILE* _M_file;
  77. };
  78.  
  79. class stdio_istreambuf : public stdio_streambuf_base
  80. {
  81. public:                         // Constructor, destructor.
  82.   stdio_istreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
  83.  
  84.   ~stdio_istreambuf();
  85.  
  86. protected:                      // Virtual functions from basic_streambuf.
  87.   streamsize showmanyc();
  88.   int_type underflow();
  89.   int_type uflow();
  90.   virtual int_type pbackfail(int_type c = traits_type::eof());
  91. };
  92.  
  93. class stdio_ostreambuf : public stdio_streambuf_base
  94. {
  95. public:                         // Constructor, destructor.
  96.   stdio_ostreambuf(FILE* __f) : stdio_streambuf_base(__f) {}
  97.   ~stdio_ostreambuf();
  98.  
  99. protected:                      // Virtual functions from basic_streambuf.
  100.   streamsize showmanyc();
  101.   int_type overflow(int_type c = traits_type::eof());
  102. };
  103.  
  104. # ifndef _STLP_HAS_NO_NAMESPACES
  105. } // Close namespace _SgI.
  106. # endif
  107.  
  108. #endif /* _STLP_STDIO_STREAMBUF */
  109.  
  110. #endif /* _STLP_WINCE */
  111.  
  112. // Local Variables:
  113. // mode:C++
  114. // End:
  115.  
  116.